@streamflow/stream 6.5.0 → 7.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.
Files changed (137) hide show
  1. package/README.md +17 -22
  2. package/dist/cjs/__tests__/aptos/streamClient.spec.js +111 -0
  3. package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +45 -0
  4. package/dist/cjs/aptos/StreamClient.js +226 -0
  5. package/dist/cjs/aptos/constants.js +27 -0
  6. package/dist/{aptos → cjs/aptos}/index.js +6 -6
  7. package/dist/cjs/aptos/types.js +69 -0
  8. package/dist/{aptos → cjs/aptos}/utils.js +4 -4
  9. package/dist/cjs/aptos/wallet.js +34 -0
  10. package/dist/cjs/common/BaseStreamClient.js +23 -0
  11. package/dist/cjs/common/GenericStreamClient.js +102 -0
  12. package/dist/{common → cjs/common}/constants.js +2 -2
  13. package/dist/{common → cjs/common}/contractUtils.js +19 -20
  14. package/dist/cjs/common/utils.js +66 -0
  15. package/dist/cjs/evm/StreamClient.js +238 -0
  16. package/dist/cjs/evm/constants.js +38 -0
  17. package/dist/{evm → cjs/evm}/index.js +8 -8
  18. package/dist/{evm → cjs/evm}/types.js +26 -35
  19. package/dist/{evm → cjs/evm}/utils.js +2 -2
  20. package/dist/{index.js → cjs/index.js} +10 -10
  21. package/dist/cjs/solana/StreamClient.js +737 -0
  22. package/dist/{solana → cjs/solana}/constants.js +33 -33
  23. package/dist/cjs/solana/index.js +39 -0
  24. package/dist/{solana → cjs/solana}/instructions.js +83 -83
  25. package/dist/{solana → cjs/solana}/layout.js +8 -9
  26. package/dist/{solana → cjs/solana}/types.js +16 -26
  27. package/dist/cjs/solana/utils.js +134 -0
  28. package/dist/cjs/sui/StreamClient.js +402 -0
  29. package/dist/cjs/sui/constants.js +42 -0
  30. package/dist/{sui → cjs/sui}/index.js +5 -5
  31. package/dist/cjs/sui/types.js +68 -0
  32. package/dist/{sui → cjs/sui}/utils.js +7 -7
  33. package/dist/cjs/sui/wallet.js +40 -0
  34. package/dist/esm/__tests__/aptos/streamClient.spec.js +106 -0
  35. package/dist/esm/__tests__/common/GenericStreamClient.spec.js +40 -0
  36. package/dist/{aptos → esm/aptos}/StreamClient.d.ts +3 -3
  37. package/dist/esm/aptos/StreamClient.js +226 -0
  38. package/dist/{aptos → esm/aptos}/constants.d.ts +1 -1
  39. package/dist/esm/aptos/constants.js +24 -0
  40. package/dist/esm/aptos/index.d.ts +4 -0
  41. package/dist/esm/aptos/index.js +4 -0
  42. package/dist/{aptos → esm/aptos}/types.d.ts +13 -13
  43. package/dist/esm/aptos/types.js +105 -0
  44. package/dist/esm/aptos/utils.js +30 -0
  45. package/dist/esm/aptos/wallet.js +33 -0
  46. package/dist/{common → esm/common}/BaseStreamClient.d.ts +1 -1
  47. package/dist/esm/common/BaseStreamClient.js +19 -0
  48. package/dist/{common → esm/common}/GenericStreamClient.d.ts +6 -6
  49. package/dist/esm/common/GenericStreamClient.js +101 -0
  50. package/dist/esm/common/constants.d.ts +3 -0
  51. package/dist/esm/common/constants.js +3 -0
  52. package/dist/{common → esm/common}/contractUtils.d.ts +15 -15
  53. package/dist/esm/common/contractUtils.js +42 -0
  54. package/dist/{common → esm/common}/types.d.ts +19 -19
  55. package/dist/esm/common/types.js +106 -0
  56. package/dist/{common → esm/common}/utils.d.ts +11 -12
  57. package/dist/esm/common/utils.js +56 -0
  58. package/dist/{evm → esm/evm}/StreamClient.d.ts +4 -4
  59. package/dist/esm/evm/StreamClient.js +237 -0
  60. package/dist/esm/evm/abi.js +1255 -0
  61. package/dist/{evm → esm/evm}/constants.d.ts +1 -1
  62. package/dist/esm/evm/constants.js +35 -0
  63. package/dist/esm/evm/ercAbi.js +222 -0
  64. package/dist/esm/evm/index.d.ts +5 -0
  65. package/dist/esm/evm/index.js +5 -0
  66. package/dist/{evm → esm/evm}/types.d.ts +38 -38
  67. package/dist/esm/evm/types.js +102 -0
  68. package/dist/esm/evm/utils.js +8 -0
  69. package/dist/esm/index.d.ts +9 -0
  70. package/dist/esm/index.js +9 -0
  71. package/dist/{solana → esm/solana}/StreamClient.d.ts +4 -4
  72. package/dist/esm/solana/StreamClient.js +711 -0
  73. package/dist/{solana → esm/solana}/constants.d.ts +3 -1
  74. package/dist/esm/solana/constants.js +62 -0
  75. package/dist/esm/solana/index.d.ts +6 -0
  76. package/dist/esm/solana/index.js +6 -0
  77. package/dist/esm/solana/instructionTypes.js +1 -0
  78. package/dist/{solana → esm/solana}/instructions.d.ts +18 -18
  79. package/dist/esm/solana/instructions.js +257 -0
  80. package/dist/{solana → esm/solana}/layout.d.ts +2 -1
  81. package/dist/esm/solana/layout.js +155 -0
  82. package/dist/esm/solana/timelockIDL.js +420 -0
  83. package/dist/{solana → esm/solana}/types.d.ts +38 -37
  84. package/dist/esm/solana/types.js +101 -0
  85. package/dist/{solana → esm/solana}/utils.d.ts +4 -1
  86. package/dist/esm/solana/utils.js +123 -0
  87. package/dist/{sui → esm/sui}/StreamClient.d.ts +3 -3
  88. package/dist/esm/sui/StreamClient.js +403 -0
  89. package/dist/{sui → esm/sui}/constants.d.ts +1 -1
  90. package/dist/esm/sui/constants.js +39 -0
  91. package/dist/esm/sui/index.d.ts +4 -0
  92. package/dist/esm/sui/index.js +4 -0
  93. package/dist/{sui → esm/sui}/types.d.ts +13 -13
  94. package/dist/esm/sui/types.js +104 -0
  95. package/dist/{sui → esm/sui}/utils.d.ts +1 -1
  96. package/dist/esm/sui/utils.js +23 -0
  97. package/dist/{sui → esm/sui}/wallet.d.ts +1 -1
  98. package/dist/esm/sui/wallet.js +38 -0
  99. package/package.json +37 -35
  100. package/dist/__tests__/aptos/streamClient.spec.js +0 -161
  101. package/dist/__tests__/common/GenericStreamClient.spec.js +0 -44
  102. package/dist/aptos/StreamClient.js +0 -431
  103. package/dist/aptos/constants.js +0 -28
  104. package/dist/aptos/index.d.ts +0 -4
  105. package/dist/aptos/types.js +0 -77
  106. package/dist/aptos/wallet.js +0 -89
  107. package/dist/common/BaseStreamClient.js +0 -71
  108. package/dist/common/GenericStreamClient.js +0 -128
  109. package/dist/common/constants.d.ts +0 -3
  110. package/dist/common/utils.js +0 -118
  111. package/dist/evm/StreamClient.js +0 -496
  112. package/dist/evm/constants.js +0 -39
  113. package/dist/evm/index.d.ts +0 -5
  114. package/dist/index.d.ts +0 -9
  115. package/dist/solana/StreamClient.js +0 -1253
  116. package/dist/solana/index.d.ts +0 -7
  117. package/dist/solana/index.js +0 -43
  118. package/dist/solana/utils.js +0 -211
  119. package/dist/sui/StreamClient.js +0 -648
  120. package/dist/sui/constants.js +0 -43
  121. package/dist/sui/index.d.ts +0 -4
  122. package/dist/sui/types.js +0 -102
  123. package/dist/sui/wallet.js +0 -90
  124. /package/dist/{common → cjs/common}/types.js +0 -0
  125. /package/dist/{evm → cjs/evm}/abi.js +0 -0
  126. /package/dist/{evm → cjs/evm}/ercAbi.js +0 -0
  127. /package/dist/{solana → cjs/solana}/instructionTypes.js +0 -0
  128. /package/dist/{solana → cjs/solana}/timelockIDL.js +0 -0
  129. /package/dist/{__tests__ → esm/__tests__}/aptos/streamClient.spec.d.ts +0 -0
  130. /package/dist/{__tests__ → esm/__tests__}/common/GenericStreamClient.spec.d.ts +0 -0
  131. /package/dist/{aptos → esm/aptos}/utils.d.ts +0 -0
  132. /package/dist/{aptos → esm/aptos}/wallet.d.ts +0 -0
  133. /package/dist/{evm → esm/evm}/abi.d.ts +0 -0
  134. /package/dist/{evm → esm/evm}/ercAbi.d.ts +0 -0
  135. /package/dist/{evm → esm/evm}/utils.d.ts +0 -0
  136. /package/dist/{solana → esm/solana}/instructionTypes.d.ts +0 -0
  137. /package/dist/{solana → esm/solana}/timelockIDL.d.ts +0 -0
@@ -1,1253 +0,0 @@
1
- "use strict";
2
- // Latest version of the SDK that does not use Anchor. It supports raw instructions.
3
- var __extends = (this && this.__extends) || (function () {
4
- var extendStatics = function (d, b) {
5
- extendStatics = Object.setPrototypeOf ||
6
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
- return extendStatics(d, b);
9
- };
10
- return function (d, b) {
11
- if (typeof b !== "function" && b !== null)
12
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
- extendStatics(d, b);
14
- function __() { this.constructor = d; }
15
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
- };
17
- })();
18
- var __assign = (this && this.__assign) || function () {
19
- __assign = Object.assign || function(t) {
20
- for (var s, i = 1, n = arguments.length; i < n; i++) {
21
- s = arguments[i];
22
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
23
- t[p] = s[p];
24
- }
25
- return t;
26
- };
27
- return __assign.apply(this, arguments);
28
- };
29
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
30
- if (k2 === undefined) k2 = k;
31
- var desc = Object.getOwnPropertyDescriptor(m, k);
32
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
33
- desc = { enumerable: true, get: function() { return m[k]; } };
34
- }
35
- Object.defineProperty(o, k2, desc);
36
- }) : (function(o, m, k, k2) {
37
- if (k2 === undefined) k2 = k;
38
- o[k2] = m[k];
39
- }));
40
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
41
- Object.defineProperty(o, "default", { enumerable: true, value: v });
42
- }) : function(o, v) {
43
- o["default"] = v;
44
- });
45
- var __importStar = (this && this.__importStar) || function (mod) {
46
- if (mod && mod.__esModule) return mod;
47
- var result = {};
48
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
49
- __setModuleDefault(result, mod);
50
- return result;
51
- };
52
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
53
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
54
- return new (P || (P = Promise))(function (resolve, reject) {
55
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
56
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
57
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
58
- step((generator = generator.apply(thisArg, _arguments || [])).next());
59
- });
60
- };
61
- var __generator = (this && this.__generator) || function (thisArg, body) {
62
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
63
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
64
- function verb(n) { return function (v) { return step([n, v]); }; }
65
- function step(op) {
66
- if (f) throw new TypeError("Generator is already executing.");
67
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
68
- 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;
69
- if (y = 0, t) op = [op[0] & 2, t.value];
70
- switch (op[0]) {
71
- case 0: case 1: t = op; break;
72
- case 4: _.label++; return { value: op[1], done: false };
73
- case 5: _.label++; y = op[1]; op = [0]; continue;
74
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
75
- default:
76
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
77
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
78
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
79
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
80
- if (t[2]) _.ops.pop();
81
- _.trys.pop(); continue;
82
- }
83
- op = body.call(thisArg, _);
84
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
85
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
86
- }
87
- };
88
- var __read = (this && this.__read) || function (o, n) {
89
- var m = typeof Symbol === "function" && o[Symbol.iterator];
90
- if (!m) return o;
91
- var i = m.call(o), r, ar = [], e;
92
- try {
93
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
94
- }
95
- catch (error) { e = { error: error }; }
96
- finally {
97
- try {
98
- if (r && !r.done && (m = i["return"])) m.call(i);
99
- }
100
- finally { if (e) throw e.error; }
101
- }
102
- return ar;
103
- };
104
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
105
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
106
- if (ar || !(i in from)) {
107
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
108
- ar[i] = from[i];
109
- }
110
- }
111
- return to.concat(ar || Array.prototype.slice.call(from));
112
- };
113
- var __values = (this && this.__values) || function(o) {
114
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
115
- if (m) return m.call(o);
116
- if (o && typeof o.length === "number") return {
117
- next: function () {
118
- if (o && i >= o.length) o = void 0;
119
- return { value: o && o[i++], done: !o };
120
- }
121
- };
122
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
123
- };
124
- var __importDefault = (this && this.__importDefault) || function (mod) {
125
- return (mod && mod.__esModule) ? mod : { "default": mod };
126
- };
127
- Object.defineProperty(exports, "__esModule", { value: true });
128
- var bn_js_1 = __importDefault(require("bn.js"));
129
- var buffer_1 = require("buffer");
130
- var spl_token_1 = require("@solana/spl-token");
131
- var web3_js_1 = require("@solana/web3.js");
132
- var solana_1 = require("@streamflow/common/solana");
133
- var borsh = __importStar(require("borsh"));
134
- var types_1 = require("./types");
135
- var utils_1 = require("./utils");
136
- var constants_1 = require("./constants");
137
- var instructions_1 = require("./instructions");
138
- var types_2 = require("../common/types");
139
- var BaseStreamClient_1 = require("../common/BaseStreamClient");
140
- var utils_2 = require("../common/utils");
141
- var constants_2 = require("../common/constants");
142
- var METADATA_ACC_SIZE = 1104;
143
- var SolanaStreamClient = /** @class */ (function (_super) {
144
- __extends(SolanaStreamClient, _super);
145
- /**
146
- * Create Stream instance
147
- */
148
- function SolanaStreamClient(clusterUrl, cluster, commitment, programId, sendRate, sendThrottler) {
149
- if (cluster === void 0) { cluster = types_2.ICluster.Mainnet; }
150
- if (commitment === void 0) { commitment = "confirmed"; }
151
- if (programId === void 0) { programId = ""; }
152
- if (sendRate === void 0) { sendRate = 1; }
153
- var _this = _super.call(this) || this;
154
- _this.commitment = commitment;
155
- _this.connection = new web3_js_1.Connection(clusterUrl, _this.commitment);
156
- _this.programId = programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_1.PROGRAM_ID[cluster]);
157
- _this.sendThrottler = sendThrottler !== null && sendThrottler !== void 0 ? sendThrottler : (0, solana_1.buildSendThrottler)(sendRate);
158
- return _this;
159
- }
160
- SolanaStreamClient.prototype.getConnection = function () {
161
- return this.connection;
162
- };
163
- SolanaStreamClient.prototype.getCommitment = function () {
164
- return typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
165
- };
166
- SolanaStreamClient.prototype.getProgramId = function () {
167
- return this.programId.toBase58();
168
- };
169
- /**
170
- * Creates a new stream/vesting contract.
171
- * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
172
- */
173
- SolanaStreamClient.prototype.create = function (data, extParams) {
174
- return __awaiter(this, void 0, void 0, function () {
175
- var _a, ixs, metadata, metadataPubKey, _b, tx, hash, context, signature;
176
- return __generator(this, function (_c) {
177
- switch (_c.label) {
178
- case 0: return [4 /*yield*/, this.prepareCreateInstructions(data, extParams)];
179
- case 1:
180
- _a = _c.sent(), ixs = _a.ixs, metadata = _a.metadata, metadataPubKey = _a.metadataPubKey;
181
- return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.sender.publicKey, undefined, metadata)];
182
- case 2:
183
- _b = _c.sent(), tx = _b.tx, hash = _b.hash, context = _b.context;
184
- return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.sender, tx, {
185
- hash: hash,
186
- context: context,
187
- commitment: this.getCommitment(),
188
- }, { sendThrottler: this.sendThrottler })];
189
- case 3:
190
- signature = _c.sent();
191
- return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
192
- }
193
- });
194
- });
195
- };
196
- /**
197
- * Creates a new stream/vesting contract.
198
- * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
199
- */
200
- SolanaStreamClient.prototype.prepareCreateInstructions = function (_a, _b) {
201
- var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canPause = _a.canPause, canUpdateRate = _a.canUpdateRate, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d, partner = _a.partner;
202
- var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
203
- return __awaiter(this, void 0, void 0, function () {
204
- var ixs, mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, _g, escrowTokens, tokenProgramId, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, totalFee, totalAmount, _h, _j, _k, _l;
205
- return __generator(this, function (_m) {
206
- switch (_m.label) {
207
- case 0:
208
- if (!sender.publicKey) {
209
- throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
210
- }
211
- ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
212
- computePrice: computePrice,
213
- computeLimit: computeLimit,
214
- });
215
- mintPublicKey = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(mint);
216
- recipientPublicKey = new web3_js_1.PublicKey(recipient);
217
- _f = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _f.metadata, metadataPubKey = _f.metadataPubKey;
218
- _g = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _g[0];
219
- return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey)];
220
- case 1:
221
- tokenProgramId = (_m.sent()).tokenProgramId;
222
- return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, sender.publicKey, tokenProgramId)];
223
- case 2:
224
- senderTokens = _m.sent();
225
- return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, recipientPublicKey, tokenProgramId)];
226
- case 3:
227
- recipientTokens = _m.sent();
228
- return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId)];
229
- case 4:
230
- streamflowTreasuryTokens = _m.sent();
231
- partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.WITHDRAWOR_PUBLIC_KEY;
232
- return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, partnerPublicKey, tokenProgramId)];
233
- case 5:
234
- partnerTokens = _m.sent();
235
- if (!isNative) return [3 /*break*/, 8];
236
- return [4 /*yield*/, this.getTotalFee({
237
- address: partner !== null && partner !== void 0 ? partner : sender.publicKey.toBase58(),
238
- })];
239
- case 6:
240
- totalFee = _m.sent();
241
- totalAmount = (0, utils_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
242
- _j = (_h = ixs.push).apply;
243
- _k = [ixs];
244
- _l = [[]];
245
- return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)];
246
- case 7:
247
- _j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_m.sent())]), false]))]));
248
- _m.label = 8;
249
- case 8:
250
- ixs.push((0, instructions_1.createStreamInstruction)({
251
- start: new bn_js_1.default(start),
252
- depositedAmount: depositedAmount,
253
- period: new bn_js_1.default(period),
254
- amountPerPeriod: amountPerPeriod,
255
- cliff: new bn_js_1.default(cliff),
256
- cliffAmount: cliffAmount,
257
- cancelableBySender: cancelableBySender,
258
- cancelableByRecipient: cancelableByRecipient,
259
- automaticWithdrawal: automaticWithdrawal,
260
- transferableBySender: transferableBySender,
261
- transferableByRecipient: transferableByRecipient,
262
- canTopup: canTopup,
263
- canUpdateRate: !!canUpdateRate,
264
- canPause: !!canPause,
265
- name: name,
266
- withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
267
- }, this.programId, {
268
- sender: sender.publicKey,
269
- senderTokens: senderTokens,
270
- recipient: new web3_js_1.PublicKey(recipient),
271
- metadata: metadataPubKey,
272
- escrowTokens: escrowTokens,
273
- recipientTokens: recipientTokens,
274
- streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
275
- streamflowTreasuryTokens: streamflowTreasuryTokens,
276
- partner: partnerPublicKey,
277
- partnerTokens: partnerTokens,
278
- mint: new web3_js_1.PublicKey(mint),
279
- feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
280
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
281
- timelockProgram: this.programId,
282
- tokenProgram: tokenProgramId,
283
- associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
284
- withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
285
- systemProgram: web3_js_1.SystemProgram.programId,
286
- }));
287
- return [2 /*return*/, { ixs: ixs, metadata: metadata, metadataPubKey: metadataPubKey }];
288
- }
289
- });
290
- });
291
- };
292
- /**
293
- * Creates a new stream/vesting contract using unchecked instruction.
294
- *
295
- * Unchecked instruction differs from the regular in:
296
- * - does not check for initialized associated token account (wallets with no control over their ATA should not be used
297
- * as sender/recipient/partner or there are risks of funds being locked in the contract)
298
- * - initialized contract PDA off chain
299
- *
300
- * If you are not sure if you should use create or create_unchecked, go for create to be safer.
301
- */
302
- SolanaStreamClient.prototype.createUnchecked = function (data, extParams) {
303
- return __awaiter(this, void 0, void 0, function () {
304
- var _a, ixs, metadata, metadataPubKey, _b, tx, hash, context, signature;
305
- return __generator(this, function (_c) {
306
- switch (_c.label) {
307
- case 0: return [4 /*yield*/, this.prepareCreateUncheckedInstructions(data, extParams)];
308
- case 1:
309
- _a = _c.sent(), ixs = _a.ixs, metadata = _a.metadata, metadataPubKey = _a.metadataPubKey;
310
- return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.sender.publicKey, undefined, metadata)];
311
- case 2:
312
- _b = _c.sent(), tx = _b.tx, hash = _b.hash, context = _b.context;
313
- return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.sender, tx, {
314
- hash: hash,
315
- context: context,
316
- commitment: this.getCommitment(),
317
- }, { sendThrottler: this.sendThrottler })];
318
- case 3:
319
- signature = _c.sent();
320
- return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
321
- }
322
- });
323
- });
324
- };
325
- /**
326
- * Create Transaction instructions for `createUnchecked`
327
- */
328
- SolanaStreamClient.prototype.prepareCreateUncheckedInstructions = function (_a, _b) {
329
- var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, canUpdateRate = _a.canUpdateRate, canPause = _a.canPause, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d, partner = _a.partner;
330
- var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
331
- return __awaiter(this, void 0, void 0, function () {
332
- var mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, rentToExempt, createMetadataInstruction, _g, escrowTokens, tokenProgramId, senderTokens, partnerPublicKey, ixs, totalFee, totalAmount, _h, _j, _k, _l, createInstruction;
333
- return __generator(this, function (_m) {
334
- switch (_m.label) {
335
- case 0:
336
- if (!sender.publicKey) {
337
- throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
338
- }
339
- mintPublicKey = new web3_js_1.PublicKey(mint);
340
- recipientPublicKey = new web3_js_1.PublicKey(recipient);
341
- _f = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _f.metadata, metadataPubKey = _f.metadataPubKey;
342
- return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
343
- case 1:
344
- rentToExempt = _m.sent();
345
- createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
346
- programId: this.programId,
347
- space: METADATA_ACC_SIZE,
348
- lamports: rentToExempt,
349
- fromPubkey: sender === null || sender === void 0 ? void 0 : sender.publicKey,
350
- newAccountPubkey: metadataPubKey,
351
- });
352
- _g = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _g[0];
353
- return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey)];
354
- case 2:
355
- tokenProgramId = (_m.sent()).tokenProgramId;
356
- return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, sender.publicKey, tokenProgramId)];
357
- case 3:
358
- senderTokens = _m.sent();
359
- partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.WITHDRAWOR_PUBLIC_KEY;
360
- ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
361
- computePrice: computePrice,
362
- computeLimit: computeLimit,
363
- });
364
- if (!isNative) return [3 /*break*/, 6];
365
- return [4 /*yield*/, this.getTotalFee({ address: partner !== null && partner !== void 0 ? partner : sender.publicKey.toBase58() })];
366
- case 4:
367
- totalFee = _m.sent();
368
- totalAmount = (0, utils_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
369
- _j = (_h = ixs.push).apply;
370
- _k = [ixs];
371
- _l = [[]];
372
- return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)];
373
- case 5:
374
- _j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_m.sent())]), false]))]));
375
- _m.label = 6;
376
- case 6:
377
- createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
378
- start: new bn_js_1.default(start),
379
- depositedAmount: depositedAmount,
380
- period: new bn_js_1.default(period),
381
- amountPerPeriod: amountPerPeriod,
382
- cliff: new bn_js_1.default(cliff),
383
- cliffAmount: cliffAmount,
384
- cancelableBySender: cancelableBySender,
385
- cancelableByRecipient: cancelableByRecipient,
386
- automaticWithdrawal: automaticWithdrawal,
387
- transferableBySender: transferableBySender,
388
- transferableByRecipient: transferableByRecipient,
389
- canTopup: canTopup,
390
- canUpdateRate: !!canUpdateRate,
391
- canPause: !!canPause,
392
- name: name,
393
- withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
394
- recipient: recipientPublicKey,
395
- partner: partnerPublicKey,
396
- }, this.programId, {
397
- sender: sender.publicKey,
398
- senderTokens: senderTokens,
399
- metadata: metadataPubKey,
400
- escrowTokens: escrowTokens,
401
- mint: new web3_js_1.PublicKey(mint),
402
- feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
403
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
404
- timelockProgram: this.programId,
405
- tokenProgram: tokenProgramId,
406
- withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
407
- systemProgram: web3_js_1.SystemProgram.programId,
408
- });
409
- ixs.push(createMetadataInstruction, createInstruction);
410
- return [2 /*return*/, { ixs: ixs, metadata: metadata, metadataPubKey: metadataPubKey }];
411
- }
412
- });
413
- });
414
- };
415
- /**
416
- * Creates multiple stream/vesting contracts.
417
- * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
418
- */
419
- SolanaStreamClient.prototype.createMultiple = function (data, _a) {
420
- var sender = _a.sender, metadataPubKeys = _a.metadataPubKeys, _b = _a.isNative, isNative = _b === void 0 ? false : _b, computePrice = _a.computePrice, computeLimit = _a.computeLimit;
421
- return __awaiter(this, void 0, void 0, function () {
422
- var recipients, metadatas, metadataToRecipient, errors, signatures, batch, instructionsBatch, i, recipientData, _c, ixs, metadata, metadataPubKey, _d, hash, context, instructionsBatch_1, instructionsBatch_1_1, _e, ixs, metadata, recipient, messageV0, tx, totalDepositedAmount, nativeInstructions, messageV0, tx, signedBatch, prepareTx, responses, signedBatch_1, signedBatch_1_1, batchTx, _f, _g, _h, _j, e_1_1, _k, _l, _m, _o;
423
- var e_2, _p, e_1, _q;
424
- var _this = this;
425
- return __generator(this, function (_r) {
426
- switch (_r.label) {
427
- case 0:
428
- recipients = data.recipients;
429
- if (!sender.publicKey) {
430
- throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
431
- }
432
- metadatas = [];
433
- metadataToRecipient = {};
434
- errors = [];
435
- signatures = [];
436
- batch = [];
437
- instructionsBatch = [];
438
- metadataPubKeys = metadataPubKeys || [];
439
- i = 0;
440
- _r.label = 1;
441
- case 1:
442
- if (!(i < recipients.length)) return [3 /*break*/, 4];
443
- recipientData = recipients[i];
444
- return [4 /*yield*/, this.prepareStreamInstructions(recipientData, data, {
445
- sender: sender,
446
- metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
447
- computePrice: computePrice,
448
- computeLimit: computeLimit,
449
- })];
450
- case 2:
451
- _c = _r.sent(), ixs = _c.ixs, metadata = _c.metadata, metadataPubKey = _c.metadataPubKey;
452
- metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
453
- metadatas.push(metadataPubKey.toBase58());
454
- instructionsBatch.push({
455
- ixs: ixs,
456
- metadata: metadata,
457
- recipient: recipientData.recipient,
458
- });
459
- _r.label = 3;
460
- case 3:
461
- i++;
462
- return [3 /*break*/, 1];
463
- case 4: return [4 /*yield*/, this.connection.getLatestBlockhashAndContext()];
464
- case 5:
465
- _d = _r.sent(), hash = _d.value, context = _d.context;
466
- try {
467
- for (instructionsBatch_1 = __values(instructionsBatch), instructionsBatch_1_1 = instructionsBatch_1.next(); !instructionsBatch_1_1.done; instructionsBatch_1_1 = instructionsBatch_1.next()) {
468
- _e = instructionsBatch_1_1.value, ixs = _e.ixs, metadata = _e.metadata, recipient = _e.recipient;
469
- messageV0 = new web3_js_1.TransactionMessage({
470
- payerKey: sender.publicKey,
471
- recentBlockhash: hash.blockhash,
472
- instructions: ixs,
473
- }).compileToV0Message();
474
- tx = new web3_js_1.VersionedTransaction(messageV0);
475
- if (metadata) {
476
- tx.sign([metadata]);
477
- }
478
- batch.push({ tx: tx, recipient: recipient });
479
- }
480
- }
481
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
482
- finally {
483
- try {
484
- if (instructionsBatch_1_1 && !instructionsBatch_1_1.done && (_p = instructionsBatch_1.return)) _p.call(instructionsBatch_1);
485
- }
486
- finally { if (e_2) throw e_2.error; }
487
- }
488
- if (!isNative) return [3 /*break*/, 7];
489
- totalDepositedAmount = recipients.reduce(function (acc, recipient) { return recipient.amount.add(acc); }, new bn_js_1.default(0));
490
- return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
491
- case 6:
492
- nativeInstructions = _r.sent();
493
- messageV0 = new web3_js_1.TransactionMessage({
494
- payerKey: sender.publicKey,
495
- recentBlockhash: hash.blockhash,
496
- instructions: nativeInstructions,
497
- }).compileToV0Message();
498
- tx = new web3_js_1.VersionedTransaction(messageV0);
499
- batch.push({
500
- tx: tx,
501
- recipient: sender.publicKey.toBase58(),
502
- });
503
- _r.label = 7;
504
- case 7: return [4 /*yield*/, (0, utils_1.signAllTransactionWithRecipients)(sender, batch)];
505
- case 8:
506
- signedBatch = _r.sent();
507
- if (!isNative) return [3 /*break*/, 10];
508
- prepareTx = signedBatch.pop();
509
- return [4 /*yield*/, (0, utils_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx, { hash: hash, context: context }, { sendThrottler: this.sendThrottler })];
510
- case 9:
511
- _r.sent();
512
- _r.label = 10;
513
- case 10:
514
- responses = [];
515
- if (!(metadataPubKeys.length > 0)) return [3 /*break*/, 19];
516
- _r.label = 11;
517
- case 11:
518
- _r.trys.push([11, 16, 17, 18]);
519
- signedBatch_1 = __values(signedBatch), signedBatch_1_1 = signedBatch_1.next();
520
- _r.label = 12;
521
- case 12:
522
- if (!!signedBatch_1_1.done) return [3 /*break*/, 15];
523
- batchTx = signedBatch_1_1.value;
524
- _g = (_f = responses.push).apply;
525
- _h = [responses];
526
- _j = [[]];
527
- return [4 /*yield*/, Promise.allSettled([
528
- (0, solana_1.executeTransaction)(this.connection, batchTx.tx, { hash: hash, context: context }, { sendThrottler: this.sendThrottler }),
529
- ])];
530
- case 13:
531
- _g.apply(_f, _h.concat([__spreadArray.apply(void 0, _j.concat([__read.apply(void 0, [(_r.sent())]), false]))]));
532
- _r.label = 14;
533
- case 14:
534
- signedBatch_1_1 = signedBatch_1.next();
535
- return [3 /*break*/, 12];
536
- case 15: return [3 /*break*/, 18];
537
- case 16:
538
- e_1_1 = _r.sent();
539
- e_1 = { error: e_1_1 };
540
- return [3 /*break*/, 18];
541
- case 17:
542
- try {
543
- if (signedBatch_1_1 && !signedBatch_1_1.done && (_q = signedBatch_1.return)) _q.call(signedBatch_1);
544
- }
545
- finally { if (e_1) throw e_1.error; }
546
- return [7 /*endfinally*/];
547
- case 18: return [3 /*break*/, 21];
548
- case 19:
549
- _l =
550
- //send all transactions in parallel and wait for them to settle.
551
- //it allows to speed up the process of sending transactions
552
- //we then filter all promise responses and handle failed transactions
553
- (_k = responses.push).apply;
554
- _m = [
555
- //send all transactions in parallel and wait for them to settle.
556
- //it allows to speed up the process of sending transactions
557
- //we then filter all promise responses and handle failed transactions
558
- responses];
559
- _o = [[]];
560
- return [4 /*yield*/, (0, solana_1.executeMultipleTransactions)(this.connection, signedBatch.map(function (item) { return item.tx; }), { hash: hash, context: context }, { sendThrottler: this.sendThrottler })];
561
- case 20:
562
- //send all transactions in parallel and wait for them to settle.
563
- //it allows to speed up the process of sending transactions
564
- //we then filter all promise responses and handle failed transactions
565
- _l.apply(_k, _m.concat([__spreadArray.apply(void 0, _o.concat([__read.apply(void 0, [(_r.sent())]), false]))]));
566
- _r.label = 21;
567
- case 21:
568
- responses.forEach(function (item, index) {
569
- if (item.status === "fulfilled") {
570
- signatures.push(item.value);
571
- }
572
- else {
573
- errors.push({
574
- recipient: signedBatch[index].recipient,
575
- error: item.reason,
576
- contractErrorCode: _this.extractErrorCode(item.reason) || undefined,
577
- });
578
- }
579
- });
580
- return [2 /*return*/, { txs: signatures, metadatas: metadatas, metadataToRecipient: metadataToRecipient, errors: errors }];
581
- }
582
- });
583
- });
584
- };
585
- /**
586
- * Attempts withdrawing from the specified stream.
587
- */
588
- SolanaStreamClient.prototype.withdraw = function (_a, extParams) {
589
- var id = _a.id, _b = _a.amount, amount = _b === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _b;
590
- return __awaiter(this, void 0, void 0, function () {
591
- var ixs, _c, tx, hash, context, signature;
592
- return __generator(this, function (_d) {
593
- switch (_d.label) {
594
- case 0: return [4 /*yield*/, this.prepareWithdrawInstructions({ id: id, amount: amount }, extParams)];
595
- case 1:
596
- ixs = _d.sent();
597
- return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey)];
598
- case 2:
599
- _c = _d.sent(), tx = _c.tx, hash = _c.hash, context = _c.context;
600
- return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
601
- hash: hash,
602
- context: context,
603
- commitment: this.getCommitment(),
604
- }, { sendThrottler: this.sendThrottler })];
605
- case 3:
606
- signature = _d.sent();
607
- return [2 /*return*/, { ixs: ixs, txId: signature }];
608
- }
609
- });
610
- });
611
- };
612
- /**
613
- * Creates Transaction Instructions for withdrawal
614
- */
615
- SolanaStreamClient.prototype.prepareWithdrawInstructions = function (_a, _b) {
616
- var id = _a.id, _c = _a.amount, amount = _c === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _c;
617
- var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
618
- return __awaiter(this, void 0, void 0, function () {
619
- var ixs, streamPublicKey, escrow, data, tokenProgramId, streamflowTreasuryTokens, partnerTokens;
620
- return __generator(this, function (_d) {
621
- switch (_d.label) {
622
- case 0:
623
- if (!invoker.publicKey) {
624
- throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
625
- }
626
- ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
627
- computePrice: computePrice,
628
- computeLimit: computeLimit,
629
- });
630
- streamPublicKey = new web3_js_1.PublicKey(id);
631
- return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
632
- case 1:
633
- escrow = _d.sent();
634
- if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
635
- throw new Error("Couldn't get account info");
636
- }
637
- data = (0, utils_1.decodeStream)(escrow.data);
638
- return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, data.mint)];
639
- case 2:
640
- tokenProgramId = (_d.sent()).tokenProgramId;
641
- return [4 /*yield*/, (0, solana_1.ata)(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId)];
642
- case 3:
643
- streamflowTreasuryTokens = _d.sent();
644
- return [4 /*yield*/, (0, solana_1.ata)(data.mint, data.partner, tokenProgramId)];
645
- case 4:
646
- partnerTokens = _d.sent();
647
- return [4 /*yield*/, this.checkAssociatedTokenAccounts(data, { invoker: invoker, checkTokenAccounts: checkTokenAccounts }, ixs, tokenProgramId)];
648
- case 5:
649
- _d.sent();
650
- ixs.push((0, instructions_1.withdrawStreamInstruction)(amount, this.programId, {
651
- authority: invoker.publicKey,
652
- recipient: invoker.publicKey,
653
- recipientTokens: data.recipientTokens,
654
- metadata: streamPublicKey,
655
- escrowTokens: data.escrowTokens,
656
- streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
657
- streamflowTreasuryTokens: streamflowTreasuryTokens,
658
- partner: data.partner,
659
- partnerTokens: partnerTokens,
660
- mint: data.mint,
661
- tokenProgram: tokenProgramId,
662
- }));
663
- return [2 /*return*/, ixs];
664
- }
665
- });
666
- });
667
- };
668
- /**
669
- * Attempts canceling the specified stream.
670
- */
671
- SolanaStreamClient.prototype.cancel = function (_a, extParams) {
672
- var id = _a.id;
673
- return __awaiter(this, void 0, void 0, function () {
674
- var ixs, _b, tx, hash, context, signature;
675
- return __generator(this, function (_c) {
676
- switch (_c.label) {
677
- case 0: return [4 /*yield*/, this.prepareCancelInstructions({ id: id }, extParams)];
678
- case 1:
679
- ixs = _c.sent();
680
- return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey)];
681
- case 2:
682
- _b = _c.sent(), tx = _b.tx, hash = _b.hash, context = _b.context;
683
- return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
684
- hash: hash,
685
- context: context,
686
- commitment: this.getCommitment(),
687
- }, { sendThrottler: this.sendThrottler })];
688
- case 3:
689
- signature = _c.sent();
690
- return [2 /*return*/, { ixs: ixs, txId: signature }];
691
- }
692
- });
693
- });
694
- };
695
- /**
696
- * Creates Transaction Instructions for cancel
697
- */
698
- SolanaStreamClient.prototype.prepareCancelInstructions = function (_a, _b) {
699
- var id = _a.id;
700
- var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
701
- return __awaiter(this, void 0, void 0, function () {
702
- var streamPublicKey, escrowAcc, data, tokenProgramId, streamflowTreasuryTokens, partnerTokens, ixs;
703
- return __generator(this, function (_c) {
704
- switch (_c.label) {
705
- case 0:
706
- if (!invoker.publicKey) {
707
- throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
708
- }
709
- streamPublicKey = new web3_js_1.PublicKey(id);
710
- return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
711
- case 1:
712
- escrowAcc = _c.sent();
713
- if (!(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data)) {
714
- throw new Error("Couldn't get account info");
715
- }
716
- data = (0, utils_1.decodeStream)(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data);
717
- return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, data.mint)];
718
- case 2:
719
- tokenProgramId = (_c.sent()).tokenProgramId;
720
- return [4 /*yield*/, (0, solana_1.ata)(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId)];
721
- case 3:
722
- streamflowTreasuryTokens = _c.sent();
723
- return [4 /*yield*/, (0, solana_1.ata)(data.mint, data.partner, tokenProgramId)];
724
- case 4:
725
- partnerTokens = _c.sent();
726
- ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
727
- computePrice: computePrice,
728
- computeLimit: computeLimit,
729
- });
730
- return [4 /*yield*/, this.checkAssociatedTokenAccounts(data, { invoker: invoker, checkTokenAccounts: checkTokenAccounts }, ixs, tokenProgramId)];
731
- case 5:
732
- _c.sent();
733
- ixs.push((0, instructions_1.cancelStreamInstruction)(this.programId, {
734
- authority: invoker.publicKey,
735
- sender: data.sender,
736
- senderTokens: data.senderTokens,
737
- recipient: data.recipient,
738
- recipientTokens: data.recipientTokens,
739
- metadata: streamPublicKey,
740
- escrowTokens: data.escrowTokens,
741
- streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
742
- streamflowTreasuryTokens: streamflowTreasuryTokens,
743
- partner: data.partner,
744
- partnerTokens: partnerTokens,
745
- mint: data.mint,
746
- tokenProgram: tokenProgramId,
747
- }));
748
- return [2 /*return*/, ixs];
749
- }
750
- });
751
- });
752
- };
753
- /**
754
- * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
755
- * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
756
- */
757
- SolanaStreamClient.prototype.transfer = function (_a, extParams) {
758
- var id = _a.id, newRecipient = _a.newRecipient;
759
- return __awaiter(this, void 0, void 0, function () {
760
- var ixs, _b, tx, hash, context, signature;
761
- return __generator(this, function (_c) {
762
- switch (_c.label) {
763
- case 0: return [4 /*yield*/, this.prepareTransferInstructions({ id: id, newRecipient: newRecipient }, extParams)];
764
- case 1:
765
- ixs = _c.sent();
766
- return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey)];
767
- case 2:
768
- _b = _c.sent(), tx = _b.tx, hash = _b.hash, context = _b.context;
769
- return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
770
- hash: hash,
771
- context: context,
772
- commitment: this.getCommitment(),
773
- }, { sendThrottler: this.sendThrottler })];
774
- case 3:
775
- signature = _c.sent();
776
- return [2 /*return*/, { ixs: ixs, txId: signature }];
777
- }
778
- });
779
- });
780
- };
781
- /**
782
- * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
783
- * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
784
- */
785
- SolanaStreamClient.prototype.prepareTransferInstructions = function (_a, _b) {
786
- var id = _a.id, newRecipient = _a.newRecipient;
787
- var invoker = _b.invoker, computePrice = _b.computePrice, _c = _b.computeLimit, computeLimit = _c === void 0 ? 100001 : _c;
788
- return __awaiter(this, void 0, void 0, function () {
789
- var ixs, stream, newRecipientPublicKey, escrow, mint, tokenProgramId, newRecipientTokens;
790
- return __generator(this, function (_d) {
791
- switch (_d.label) {
792
- case 0:
793
- if (!invoker.publicKey) {
794
- throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
795
- }
796
- ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
797
- computePrice: computePrice,
798
- computeLimit: computeLimit,
799
- });
800
- stream = new web3_js_1.PublicKey(id);
801
- newRecipientPublicKey = new web3_js_1.PublicKey(newRecipient);
802
- return [4 /*yield*/, this.connection.getAccountInfo(stream)];
803
- case 1:
804
- escrow = _d.sent();
805
- if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
806
- throw new Error("Couldn't get account info");
807
- }
808
- mint = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data).mint;
809
- return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, mint)];
810
- case 2:
811
- tokenProgramId = (_d.sent()).tokenProgramId;
812
- return [4 /*yield*/, (0, solana_1.ata)(mint, newRecipientPublicKey, tokenProgramId)];
813
- case 3:
814
- newRecipientTokens = _d.sent();
815
- ixs.push((0, instructions_1.transferStreamInstruction)(this.programId, {
816
- authority: invoker.publicKey,
817
- newRecipient: newRecipientPublicKey,
818
- newRecipientTokens: newRecipientTokens,
819
- metadata: stream,
820
- mint: mint,
821
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
822
- tokenProgram: tokenProgramId,
823
- associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
824
- systemProgram: web3_js_1.SystemProgram.programId,
825
- }));
826
- return [2 /*return*/, ixs];
827
- }
828
- });
829
- });
830
- };
831
- /**
832
- * Tops up stream account with specified amount.
833
- */
834
- SolanaStreamClient.prototype.topup = function (_a, extParams) {
835
- var id = _a.id, amount = _a.amount;
836
- return __awaiter(this, void 0, void 0, function () {
837
- var ixs, _b, tx, hash, context, signature;
838
- return __generator(this, function (_c) {
839
- switch (_c.label) {
840
- case 0: return [4 /*yield*/, this.prepareTopupInstructions({ id: id, amount: amount }, extParams)];
841
- case 1:
842
- ixs = _c.sent();
843
- return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey)];
844
- case 2:
845
- _b = _c.sent(), tx = _b.tx, hash = _b.hash, context = _b.context;
846
- return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
847
- hash: hash,
848
- context: context,
849
- commitment: this.getCommitment(),
850
- }, { sendThrottler: this.sendThrottler })];
851
- case 3:
852
- signature = _c.sent();
853
- return [2 /*return*/, { ixs: ixs, txId: signature }];
854
- }
855
- });
856
- });
857
- };
858
- /**
859
- * Create Transaction instructions for topup
860
- */
861
- SolanaStreamClient.prototype.prepareTopupInstructions = function (_a, _b) {
862
- var id = _a.id, amount = _a.amount;
863
- var invoker = _b.invoker, isNative = _b.isNative, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
864
- return __awaiter(this, void 0, void 0, function () {
865
- var ixs, streamPublicKey, escrow, _c, mint, partner, senderTokens, escrowTokens, tokenProgramId, streamflowTreasuryTokens, partnerTokens, _d, _e, _f, _g;
866
- return __generator(this, function (_h) {
867
- switch (_h.label) {
868
- case 0:
869
- if (!invoker.publicKey) {
870
- throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
871
- }
872
- ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
873
- computePrice: computePrice,
874
- computeLimit: computeLimit,
875
- });
876
- streamPublicKey = new web3_js_1.PublicKey(id);
877
- return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
878
- case 1:
879
- escrow = _h.sent();
880
- if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
881
- throw new Error("Couldn't get account info");
882
- }
883
- _c = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data), mint = _c.mint, partner = _c.partner, senderTokens = _c.senderTokens, escrowTokens = _c.escrowTokens;
884
- return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, mint)];
885
- case 2:
886
- tokenProgramId = (_h.sent()).tokenProgramId;
887
- return [4 /*yield*/, (0, solana_1.ata)(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId)];
888
- case 3:
889
- streamflowTreasuryTokens = _h.sent();
890
- return [4 /*yield*/, (0, solana_1.ata)(mint, partner, tokenProgramId)];
891
- case 4:
892
- partnerTokens = _h.sent();
893
- if (!isNative) return [3 /*break*/, 6];
894
- _e = (_d = ixs.push).apply;
895
- _f = [ixs];
896
- _g = [[]];
897
- return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, invoker.publicKey, amount)];
898
- case 5:
899
- _e.apply(_d, _f.concat([__spreadArray.apply(void 0, _g.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
900
- _h.label = 6;
901
- case 6:
902
- ixs.push((0, instructions_1.topupStreamInstruction)(amount, this.programId, {
903
- sender: invoker.publicKey,
904
- senderTokens: senderTokens,
905
- metadata: streamPublicKey,
906
- escrowTokens: escrowTokens,
907
- streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
908
- streamflowTreasuryTokens: streamflowTreasuryTokens,
909
- partner: partner,
910
- partnerTokens: partnerTokens,
911
- mint: mint,
912
- tokenProgram: tokenProgramId,
913
- withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
914
- systemProgram: web3_js_1.SystemProgram.programId,
915
- }));
916
- return [2 /*return*/, ixs];
917
- }
918
- });
919
- });
920
- };
921
- /**
922
- * Fetch stream data by its id (address).
923
- */
924
- SolanaStreamClient.prototype.getOne = function (_a) {
925
- var id = _a.id;
926
- return __awaiter(this, void 0, void 0, function () {
927
- var escrow;
928
- return __generator(this, function (_b) {
929
- switch (_b.label) {
930
- case 0: return [4 /*yield*/, this.connection.getAccountInfo(new web3_js_1.PublicKey(id), constants_1.TX_FINALITY_CONFIRMED)];
931
- case 1:
932
- escrow = _b.sent();
933
- if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
934
- throw new Error("Couldn't get account info.");
935
- }
936
- return [2 /*return*/, new types_1.Contract((0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data))];
937
- }
938
- });
939
- });
940
- };
941
- /**
942
- * Fetch streams/contracts by providing direction.
943
- * Streams are sorted by start time in ascending order.
944
- */
945
- SolanaStreamClient.prototype.get = function (_a) {
946
- var address = _a.address, _b = _a.type, type = _b === void 0 ? types_2.StreamType.All : _b, _c = _a.direction, direction = _c === void 0 ? types_2.StreamDirection.All : _c;
947
- return __awaiter(this, void 0, void 0, function () {
948
- var publicKey, accounts, outgoingAccounts, incomingAccounts, offset, streams, sortedStreams;
949
- return __generator(this, function (_d) {
950
- switch (_d.label) {
951
- case 0:
952
- publicKey = new web3_js_1.PublicKey(address);
953
- accounts = [];
954
- if (!(direction === "all")) return [3 /*break*/, 3];
955
- return [4 /*yield*/, (0, solana_1.getProgramAccounts)(this.connection, publicKey, constants_1.STREAM_STRUCT_OFFSET_SENDER, this.programId)];
956
- case 1:
957
- outgoingAccounts = _d.sent();
958
- return [4 /*yield*/, (0, solana_1.getProgramAccounts)(this.connection, publicKey, constants_1.STREAM_STRUCT_OFFSET_RECIPIENT, this.programId)];
959
- case 2:
960
- incomingAccounts = _d.sent();
961
- accounts = __spreadArray(__spreadArray([], __read(outgoingAccounts), false), __read(incomingAccounts), false);
962
- return [3 /*break*/, 5];
963
- case 3:
964
- offset = direction === "outgoing" ? constants_1.STREAM_STRUCT_OFFSET_SENDER : constants_1.STREAM_STRUCT_OFFSET_RECIPIENT;
965
- return [4 /*yield*/, (0, solana_1.getProgramAccounts)(this.connection, publicKey, offset, this.programId)];
966
- case 4:
967
- accounts = _d.sent();
968
- _d.label = 5;
969
- case 5:
970
- streams = {};
971
- accounts.forEach(function (account) {
972
- var _a;
973
- var decoded = new types_1.Contract((0, utils_1.decodeStream)(account.account.data));
974
- streams = __assign(__assign({}, streams), (_a = {}, _a[account.pubkey.toBase58()] = decoded, _a));
975
- });
976
- sortedStreams = Object.entries(streams).sort(function (_a, _b) {
977
- var _c = __read(_a, 2), stream1 = _c[1];
978
- var _d = __read(_b, 2), stream2 = _d[1];
979
- return stream2.start - stream1.start;
980
- });
981
- if (type === "all")
982
- return [2 /*return*/, sortedStreams];
983
- return [2 /*return*/, sortedStreams.filter(function (stream) { return stream[1].type === type; })];
984
- }
985
- });
986
- });
987
- };
988
- SolanaStreamClient.prototype.searchStreams = function (data) {
989
- return __awaiter(this, void 0, void 0, function () {
990
- var filters, accounts;
991
- return __generator(this, function (_a) {
992
- switch (_a.label) {
993
- case 0:
994
- filters = Object.entries(data)
995
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
996
- .filter(function (_a) {
997
- var _b = __read(_a, 2), _ = _b[0], value = _b[1];
998
- return value;
999
- }) // Only keep entries where the value is truthy
1000
- .map(function (_a) {
1001
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
1002
- return ({
1003
- memcmp: {
1004
- offset: constants_1.STREAM_STRUCT_OFFSETS[key],
1005
- bytes: value,
1006
- },
1007
- });
1008
- });
1009
- return [4 /*yield*/, this.connection.getProgramAccounts(this.programId, { filters: filters })];
1010
- case 1:
1011
- accounts = _a.sent();
1012
- return [2 /*return*/, accounts.map(function (_a) {
1013
- var pubkey = _a.pubkey, account = _a.account;
1014
- return ({
1015
- publicKey: pubkey,
1016
- account: new types_1.Contract((0, utils_1.decodeStream)(account.data)),
1017
- });
1018
- })];
1019
- }
1020
- });
1021
- });
1022
- };
1023
- /**
1024
- * Attempts updating the stream auto withdrawal params and amount per period
1025
- */
1026
- SolanaStreamClient.prototype.update = function (data, extParams) {
1027
- return __awaiter(this, void 0, void 0, function () {
1028
- var ixs, _a, tx, hash, context, signature;
1029
- return __generator(this, function (_b) {
1030
- switch (_b.label) {
1031
- case 0: return [4 /*yield*/, this.prepareUpdateInstructions(data, extParams)];
1032
- case 1:
1033
- ixs = _b.sent();
1034
- return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey)];
1035
- case 2:
1036
- _a = _b.sent(), tx = _a.tx, hash = _a.hash, context = _a.context;
1037
- return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
1038
- hash: hash,
1039
- context: context,
1040
- commitment: this.getCommitment(),
1041
- }, { sendThrottler: this.sendThrottler })];
1042
- case 3:
1043
- signature = _b.sent();
1044
- return [2 /*return*/, {
1045
- ixs: ixs,
1046
- txId: signature,
1047
- }];
1048
- }
1049
- });
1050
- });
1051
- };
1052
- /**
1053
- * Create Transaction instructions for update
1054
- */
1055
- SolanaStreamClient.prototype.prepareUpdateInstructions = function (data, _a) {
1056
- var invoker = _a.invoker, computePrice = _a.computePrice, computeLimit = _a.computeLimit;
1057
- return __awaiter(this, void 0, void 0, function () {
1058
- var streamPublicKey, escrow, ixs;
1059
- return __generator(this, function (_b) {
1060
- switch (_b.label) {
1061
- case 0:
1062
- if (!invoker.publicKey) {
1063
- throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
1064
- }
1065
- streamPublicKey = new web3_js_1.PublicKey(data.id);
1066
- return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
1067
- case 1:
1068
- escrow = _b.sent();
1069
- if (!escrow) {
1070
- throw new Error("Couldn't get account info");
1071
- }
1072
- ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
1073
- computePrice: computePrice,
1074
- computeLimit: computeLimit,
1075
- });
1076
- ixs.push((0, instructions_1.updateStreamInstruction)(data, this.programId, {
1077
- authority: invoker.publicKey,
1078
- metadata: streamPublicKey,
1079
- withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
1080
- systemProgram: web3_js_1.SystemProgram.programId,
1081
- }));
1082
- return [2 /*return*/, ixs];
1083
- }
1084
- });
1085
- });
1086
- };
1087
- SolanaStreamClient.prototype.getFees = function (_a) {
1088
- var address = _a.address;
1089
- return __awaiter(this, void 0, void 0, function () {
1090
- var _b, metadataPubKey, data, partners, filteredPartners;
1091
- return __generator(this, function (_c) {
1092
- switch (_c.label) {
1093
- case 0:
1094
- _b = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from(constants_1.FEES_METADATA_SEED)], new web3_js_1.PublicKey(constants_1.PARTNER_ORACLE_PROGRAM_ID)), 1), metadataPubKey = _b[0];
1095
- return [4 /*yield*/, this.connection.getAccountInfo(metadataPubKey)];
1096
- case 1:
1097
- data = _c.sent();
1098
- if (!data) {
1099
- return [2 /*return*/, null];
1100
- }
1101
- partners = borsh.deserialize(constants_1.PARTNERS_SCHEMA, data.data);
1102
- filteredPartners = partners.filter(function (item) { return new web3_js_1.PublicKey(item.pubkey).toString() === address; });
1103
- if (filteredPartners.length === 0) {
1104
- return [2 /*return*/, null];
1105
- }
1106
- return [2 /*return*/, {
1107
- streamflowFee: Number(filteredPartners[0].strm_fee.toFixed(4)),
1108
- partnerFee: Number(filteredPartners[0].partner_fee.toFixed(4)),
1109
- }];
1110
- }
1111
- });
1112
- });
1113
- };
1114
- SolanaStreamClient.prototype.getDefaultStreamflowFee = function () {
1115
- return __awaiter(this, void 0, void 0, function () {
1116
- return __generator(this, function (_a) {
1117
- return [2 /*return*/, constants_1.DEFAULT_STREAMFLOW_FEE];
1118
- });
1119
- });
1120
- };
1121
- SolanaStreamClient.prototype.extractErrorCode = function (err) {
1122
- var _a;
1123
- var logs = "logs" in err && Array.isArray(err.logs) ? err.logs : undefined;
1124
- return (0, utils_1.extractSolanaErrorCode)((_a = err.toString()) !== null && _a !== void 0 ? _a : "Unknown error!", logs);
1125
- };
1126
- /**
1127
- * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
1128
- */
1129
- SolanaStreamClient.prototype.prepareStreamInstructions = function (recipient, streamParams, extParams) {
1130
- return __awaiter(this, void 0, void 0, function () {
1131
- var mint, start, period, cliff, canTopup, canUpdateRate, canPause, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, partner, sender, metadataPubKeys, computeLimit, computePrice, ixs, recipientPublicKey, mintPublicKey, _c, metadata, metadataPubKey, _d, escrowTokens, tokenProgramId, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens;
1132
- return __generator(this, function (_e) {
1133
- switch (_e.label) {
1134
- case 0:
1135
- mint = streamParams.tokenId, start = streamParams.start, period = streamParams.period, cliff = streamParams.cliff, canTopup = streamParams.canTopup, canUpdateRate = streamParams.canUpdateRate, canPause = streamParams.canPause, cancelableBySender = streamParams.cancelableBySender, cancelableByRecipient = streamParams.cancelableByRecipient, transferableBySender = streamParams.transferableBySender, transferableByRecipient = streamParams.transferableByRecipient, _a = streamParams.automaticWithdrawal, automaticWithdrawal = _a === void 0 ? false : _a, _b = streamParams.withdrawalFrequency, withdrawalFrequency = _b === void 0 ? 0 : _b, partner = streamParams.partner;
1136
- sender = extParams.sender, metadataPubKeys = extParams.metadataPubKeys, computeLimit = extParams.computeLimit, computePrice = extParams.computePrice;
1137
- if (!sender.publicKey) {
1138
- throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
1139
- }
1140
- ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
1141
- computePrice: computePrice,
1142
- computeLimit: computeLimit,
1143
- });
1144
- recipientPublicKey = new web3_js_1.PublicKey(recipient.recipient);
1145
- mintPublicKey = new web3_js_1.PublicKey(mint);
1146
- _c = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _c.metadata, metadataPubKey = _c.metadataPubKey;
1147
- _d = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _d[0];
1148
- return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey)];
1149
- case 1:
1150
- tokenProgramId = (_e.sent()).tokenProgramId;
1151
- return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, sender.publicKey, tokenProgramId)];
1152
- case 2:
1153
- senderTokens = _e.sent();
1154
- return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, recipientPublicKey, tokenProgramId)];
1155
- case 3:
1156
- recipientTokens = _e.sent();
1157
- return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId)];
1158
- case 4:
1159
- streamflowTreasuryTokens = _e.sent();
1160
- partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.WITHDRAWOR_PUBLIC_KEY;
1161
- return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, partnerPublicKey, tokenProgramId)];
1162
- case 5:
1163
- partnerTokens = _e.sent();
1164
- ixs.push((0, instructions_1.createStreamInstruction)({
1165
- start: new bn_js_1.default(start),
1166
- depositedAmount: recipient.amount,
1167
- period: new bn_js_1.default(period),
1168
- amountPerPeriod: recipient.amountPerPeriod,
1169
- cliff: new bn_js_1.default(cliff),
1170
- cliffAmount: recipient.cliffAmount,
1171
- cancelableBySender: cancelableBySender,
1172
- cancelableByRecipient: cancelableByRecipient,
1173
- automaticWithdrawal: automaticWithdrawal,
1174
- transferableBySender: transferableBySender,
1175
- transferableByRecipient: transferableByRecipient,
1176
- canTopup: canTopup,
1177
- canUpdateRate: !!canUpdateRate,
1178
- canPause: !!canPause,
1179
- name: recipient.name,
1180
- withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
1181
- }, this.programId, {
1182
- sender: sender.publicKey,
1183
- senderTokens: senderTokens,
1184
- recipient: new web3_js_1.PublicKey(recipient.recipient),
1185
- metadata: metadataPubKey,
1186
- escrowTokens: escrowTokens,
1187
- recipientTokens: recipientTokens,
1188
- streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
1189
- streamflowTreasuryTokens: streamflowTreasuryTokens,
1190
- partner: partnerPublicKey,
1191
- partnerTokens: partnerTokens,
1192
- mint: new web3_js_1.PublicKey(mint),
1193
- feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
1194
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
1195
- timelockProgram: this.programId,
1196
- tokenProgram: tokenProgramId,
1197
- associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
1198
- withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
1199
- systemProgram: web3_js_1.SystemProgram.programId,
1200
- }));
1201
- return [2 /*return*/, { ixs: ixs, metadata: metadata, metadataPubKey: metadataPubKey }];
1202
- }
1203
- });
1204
- });
1205
- };
1206
- /**
1207
- * Utility function to generate metadata for a Contract or return existing Pubkey
1208
- */
1209
- SolanaStreamClient.prototype.getOrCreateStreamMetadata = function (metadataPubKeys) {
1210
- var metadata;
1211
- var metadataPubKey;
1212
- if (!metadataPubKeys) {
1213
- metadata = web3_js_1.Keypair.generate();
1214
- metadataPubKey = metadata.publicKey;
1215
- }
1216
- else {
1217
- metadataPubKey = metadataPubKeys[0];
1218
- }
1219
- return { metadata: metadata, metadataPubKey: metadataPubKey };
1220
- };
1221
- /**
1222
- * Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
1223
- */
1224
- SolanaStreamClient.prototype.checkAssociatedTokenAccounts = function (data, _a, ixs, programId) {
1225
- var invoker = _a.invoker, checkTokenAccounts = _a.checkTokenAccounts;
1226
- return __awaiter(this, void 0, void 0, function () {
1227
- var owners, _b, _c, _d, _e;
1228
- return __generator(this, function (_f) {
1229
- switch (_f.label) {
1230
- case 0:
1231
- if (!checkTokenAccounts) {
1232
- return [2 /*return*/];
1233
- }
1234
- owners = Array.from(new Set([
1235
- data.sender.toBase58(),
1236
- data.recipient.toBase58(),
1237
- data.partner.toBase58(),
1238
- data.streamflowTreasury.toBase58(),
1239
- ]), function (address) { return new web3_js_1.PublicKey(address); });
1240
- _c = (_b = ixs.push).apply;
1241
- _d = [ixs];
1242
- _e = [[]];
1243
- return [4 /*yield*/, (0, solana_1.checkOrCreateAtaBatch)(this.connection, owners, data.mint, invoker, programId)];
1244
- case 1:
1245
- _c.apply(_b, _d.concat([__spreadArray.apply(void 0, _e.concat([__read.apply(void 0, [(_f.sent())]), false]))]));
1246
- return [2 /*return*/];
1247
- }
1248
- });
1249
- });
1250
- };
1251
- return SolanaStreamClient;
1252
- }(BaseStreamClient_1.BaseStreamClient));
1253
- exports.default = SolanaStreamClient;