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