@streamflow/stream 7.1.0-alpha.1 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -195,7 +195,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
195
195
|
const streamflowTreasuryTokens = await (0, solana_1.ata)(mintPublicKey, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
196
196
|
const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
|
|
197
197
|
const partnerTokens = await (0, solana_1.ata)(mintPublicKey, partnerPublicKey, tokenProgramId);
|
|
198
|
-
ixs.push((0, instructions_js_1.createStreamInstruction)({
|
|
198
|
+
ixs.push(await (0, instructions_js_1.createStreamInstruction)({
|
|
199
199
|
start: new bn_js_1.default(start),
|
|
200
200
|
depositedAmount,
|
|
201
201
|
period: new bn_js_1.default(period),
|
|
@@ -285,7 +285,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
285
285
|
const totalAmount = (0, utils_js_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
|
|
286
286
|
ixs.push(...(await (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)));
|
|
287
287
|
}
|
|
288
|
-
const createInstruction = (0, instructions_js_1.createUncheckedStreamInstruction)({
|
|
288
|
+
const createInstruction = await (0, instructions_js_1.createUncheckedStreamInstruction)({
|
|
289
289
|
start: new bn_js_1.default(start),
|
|
290
290
|
depositedAmount,
|
|
291
291
|
period: new bn_js_1.default(period),
|
|
@@ -558,7 +558,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
558
558
|
const streamflowTreasuryTokens = await (0, solana_1.ata)(mint, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
559
559
|
const partnerTokens = await (0, solana_1.ata)(mint, partner, tokenProgramId);
|
|
560
560
|
const ataIx = await this.getCreateATAInstructions([sender, recipient, streamflowTreasury, partner], mint, invoker, checkTokenAccounts, tokenProgramId);
|
|
561
|
-
ixs.push(...ataIx, (0, instructions_js_1.withdrawStreamInstruction)(amount, this.programId, {
|
|
561
|
+
ixs.push(...ataIx, await (0, instructions_js_1.withdrawStreamInstruction)(amount, this.programId, {
|
|
562
562
|
partner,
|
|
563
563
|
partnerTokens,
|
|
564
564
|
mint,
|
|
@@ -655,7 +655,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
655
655
|
computeLimit,
|
|
656
656
|
});
|
|
657
657
|
const ixsAta = await this.getCreateATAInstructions([sender, recipient, partner, streamflowTreasury], mint, invoker, checkTokenAccounts, tokenProgramId);
|
|
658
|
-
ixs.push(...ixsAta, (0, instructions_js_1.cancelStreamInstruction)(this.programId, {
|
|
658
|
+
ixs.push(...ixsAta, await (0, instructions_js_1.cancelStreamInstruction)(this.programId, {
|
|
659
659
|
sender,
|
|
660
660
|
senderTokens,
|
|
661
661
|
recipient,
|
|
@@ -707,7 +707,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
707
707
|
const { mint } = (0, utils_js_1.decodeStream)(escrow?.data);
|
|
708
708
|
const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, mint);
|
|
709
709
|
const newRecipientTokens = await (0, solana_1.ata)(mint, newRecipientPublicKey, tokenProgramId);
|
|
710
|
-
ixs.push((0, instructions_js_1.transferStreamInstruction)(this.programId, {
|
|
710
|
+
ixs.push(await (0, instructions_js_1.transferStreamInstruction)(this.programId, {
|
|
711
711
|
authority: invoker.publicKey,
|
|
712
712
|
newRecipient: newRecipientPublicKey,
|
|
713
713
|
newRecipientTokens,
|
|
@@ -756,7 +756,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
756
756
|
if (isNative) {
|
|
757
757
|
ixs.push(...(await (0, solana_1.prepareWrappedAccount)(this.connection, invoker.publicKey, amount)));
|
|
758
758
|
}
|
|
759
|
-
ixs.push((0, instructions_js_1.topupStreamInstruction)(amount, this.programId, {
|
|
759
|
+
ixs.push(await (0, instructions_js_1.topupStreamInstruction)(amount, this.programId, {
|
|
760
760
|
sender: invoker.publicKey,
|
|
761
761
|
senderTokens,
|
|
762
762
|
metadata: streamPublicKey,
|
|
@@ -917,7 +917,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
917
917
|
computePrice,
|
|
918
918
|
computeLimit,
|
|
919
919
|
});
|
|
920
|
-
ixs.push((0, instructions_js_1.updateStreamInstruction)(data, this.programId, {
|
|
920
|
+
ixs.push(await (0, instructions_js_1.updateStreamInstruction)(data, this.programId, {
|
|
921
921
|
authority: invoker.publicKey,
|
|
922
922
|
metadata: streamPublicKey,
|
|
923
923
|
withdrawor: constants_js_1.WITHDRAWOR_PUBLIC_KEY,
|
|
@@ -26,13 +26,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.updateStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
|
|
27
27
|
const buffer_1 = require("buffer");
|
|
28
28
|
const web3_js_1 = require("@solana/web3.js");
|
|
29
|
-
const node_crypto_1 = require("node:crypto");
|
|
30
29
|
const Layout = __importStar(require("./layout.js"));
|
|
31
|
-
const hasher = () => (0, node_crypto_1.createHash)("sha256");
|
|
32
30
|
const sha256 = {
|
|
33
|
-
digest: (data) =>
|
|
31
|
+
digest: async (data) => {
|
|
32
|
+
const dataBuffer = new TextEncoder().encode(data);
|
|
33
|
+
const hashBuffer = await globalThis.crypto.subtle.digest("SHA-256", dataBuffer);
|
|
34
|
+
return new Uint8Array(hashBuffer);
|
|
35
|
+
},
|
|
34
36
|
};
|
|
35
|
-
const createStreamInstruction = (data, programId, accounts) => {
|
|
37
|
+
const createStreamInstruction = async (data, programId, accounts) => {
|
|
36
38
|
const keys = [
|
|
37
39
|
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
38
40
|
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
@@ -90,7 +92,11 @@ const createStreamInstruction = (data, programId, accounts) => {
|
|
|
90
92
|
};
|
|
91
93
|
const encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
|
|
92
94
|
bufferData = bufferData.slice(0, encodeLength);
|
|
93
|
-
bufferData = buffer_1.Buffer.concat([
|
|
95
|
+
bufferData = buffer_1.Buffer.concat([
|
|
96
|
+
buffer_1.Buffer.from(await sha256.digest("global:create")).slice(0, 8),
|
|
97
|
+
bufferData,
|
|
98
|
+
buffer_1.Buffer.alloc(10),
|
|
99
|
+
]);
|
|
94
100
|
return new web3_js_1.TransactionInstruction({
|
|
95
101
|
keys,
|
|
96
102
|
programId,
|
|
@@ -98,7 +104,7 @@ const createStreamInstruction = (data, programId, accounts) => {
|
|
|
98
104
|
});
|
|
99
105
|
};
|
|
100
106
|
exports.createStreamInstruction = createStreamInstruction;
|
|
101
|
-
const createUncheckedStreamInstruction = (data, programId, accounts) => {
|
|
107
|
+
const createUncheckedStreamInstruction = async (data, programId, accounts) => {
|
|
102
108
|
const keys = [
|
|
103
109
|
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
104
110
|
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
@@ -145,8 +151,8 @@ const createUncheckedStreamInstruction = (data, programId, accounts) => {
|
|
|
145
151
|
const encodeLength = Layout.createUncheckedStreamLayout.encode(decodedData, bufferData);
|
|
146
152
|
bufferData = bufferData.slice(0, encodeLength);
|
|
147
153
|
const digest = accounts.payer
|
|
148
|
-
? sha256.digest("global:create_unchecked_with_payer")
|
|
149
|
-
: sha256.digest("global:create_unchecked");
|
|
154
|
+
? await sha256.digest("global:create_unchecked_with_payer")
|
|
155
|
+
: await sha256.digest("global:create_unchecked");
|
|
150
156
|
bufferData = buffer_1.Buffer.concat([buffer_1.Buffer.from(digest).slice(0, 8), bufferData, buffer_1.Buffer.alloc(10)]);
|
|
151
157
|
return new web3_js_1.TransactionInstruction({
|
|
152
158
|
keys,
|
|
@@ -155,7 +161,7 @@ const createUncheckedStreamInstruction = (data, programId, accounts) => {
|
|
|
155
161
|
});
|
|
156
162
|
};
|
|
157
163
|
exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
|
|
158
|
-
const withdrawStreamInstruction = (amount, programId, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }) => {
|
|
164
|
+
const withdrawStreamInstruction = async (amount, programId, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }) => {
|
|
159
165
|
const keys = [
|
|
160
166
|
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
161
167
|
{ pubkey: recipient, isSigner: false, isWritable: true },
|
|
@@ -177,7 +183,7 @@ const withdrawStreamInstruction = (amount, programId, { authority, recipient, re
|
|
|
177
183
|
const decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
|
|
178
184
|
const encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
|
|
179
185
|
data = data.slice(0, encodeLength);
|
|
180
|
-
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:withdraw")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
|
|
186
|
+
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(await sha256.digest("global:withdraw")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
|
|
181
187
|
return new web3_js_1.TransactionInstruction({
|
|
182
188
|
keys,
|
|
183
189
|
programId,
|
|
@@ -185,7 +191,7 @@ const withdrawStreamInstruction = (amount, programId, { authority, recipient, re
|
|
|
185
191
|
});
|
|
186
192
|
};
|
|
187
193
|
exports.withdrawStreamInstruction = withdrawStreamInstruction;
|
|
188
|
-
const updateStreamInstruction = (params, programId, { authority, metadata, withdrawor, systemProgram }) => {
|
|
194
|
+
const updateStreamInstruction = async (params, programId, { authority, metadata, withdrawor, systemProgram }) => {
|
|
189
195
|
const keys = [
|
|
190
196
|
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
191
197
|
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
@@ -200,7 +206,7 @@ const updateStreamInstruction = (params, programId, { authority, metadata, withd
|
|
|
200
206
|
};
|
|
201
207
|
const encodeLength = Layout.encodeUpdateStream(decodedData, data);
|
|
202
208
|
data = data.slice(0, encodeLength);
|
|
203
|
-
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:update")).slice(0, 8), data, buffer_1.Buffer.alloc(20)]);
|
|
209
|
+
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(await sha256.digest("global:update")).slice(0, 8), data, buffer_1.Buffer.alloc(20)]);
|
|
204
210
|
return new web3_js_1.TransactionInstruction({
|
|
205
211
|
keys: keys,
|
|
206
212
|
programId: programId,
|
|
@@ -208,7 +214,7 @@ const updateStreamInstruction = (params, programId, { authority, metadata, withd
|
|
|
208
214
|
});
|
|
209
215
|
};
|
|
210
216
|
exports.updateStreamInstruction = updateStreamInstruction;
|
|
211
|
-
const cancelStreamInstruction = (programId, { authority, sender, senderTokens, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }) => {
|
|
217
|
+
const cancelStreamInstruction = async (programId, { authority, sender, senderTokens, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }) => {
|
|
212
218
|
const keys = [
|
|
213
219
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
214
220
|
{ pubkey: sender, isSigner: false, isWritable: true },
|
|
@@ -228,7 +234,7 @@ const cancelStreamInstruction = (programId, { authority, sender, senderTokens, r
|
|
|
228
234
|
{ pubkey: mint, isSigner: false, isWritable: true },
|
|
229
235
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
230
236
|
];
|
|
231
|
-
const data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:cancel")).slice(0, 8), buffer_1.Buffer.alloc(10)]);
|
|
237
|
+
const data = buffer_1.Buffer.concat([buffer_1.Buffer.from(await sha256.digest("global:cancel")).slice(0, 8), buffer_1.Buffer.alloc(10)]);
|
|
232
238
|
return new web3_js_1.TransactionInstruction({
|
|
233
239
|
keys,
|
|
234
240
|
programId,
|
|
@@ -236,7 +242,7 @@ const cancelStreamInstruction = (programId, { authority, sender, senderTokens, r
|
|
|
236
242
|
});
|
|
237
243
|
};
|
|
238
244
|
exports.cancelStreamInstruction = cancelStreamInstruction;
|
|
239
|
-
const transferStreamInstruction = (programId, { authority, newRecipient, newRecipientTokens, metadata, mint, rent, tokenProgram, associatedTokenProgram, systemProgram, }) => {
|
|
245
|
+
const transferStreamInstruction = async (programId, { authority, newRecipient, newRecipientTokens, metadata, mint, rent, tokenProgram, associatedTokenProgram, systemProgram, }) => {
|
|
240
246
|
const keys = [
|
|
241
247
|
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
242
248
|
{ pubkey: newRecipient, isSigner: false, isWritable: true },
|
|
@@ -248,7 +254,10 @@ const transferStreamInstruction = (programId, { authority, newRecipient, newReci
|
|
|
248
254
|
{ pubkey: associatedTokenProgram, isSigner: false, isWritable: false },
|
|
249
255
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
250
256
|
];
|
|
251
|
-
const data = buffer_1.Buffer.concat([
|
|
257
|
+
const data = buffer_1.Buffer.concat([
|
|
258
|
+
buffer_1.Buffer.from(await sha256.digest("global:transfer_recipient")).slice(0, 8),
|
|
259
|
+
buffer_1.Buffer.alloc(10),
|
|
260
|
+
]);
|
|
252
261
|
return new web3_js_1.TransactionInstruction({
|
|
253
262
|
keys,
|
|
254
263
|
programId,
|
|
@@ -256,7 +265,7 @@ const transferStreamInstruction = (programId, { authority, newRecipient, newReci
|
|
|
256
265
|
});
|
|
257
266
|
};
|
|
258
267
|
exports.transferStreamInstruction = transferStreamInstruction;
|
|
259
|
-
const topupStreamInstruction = (amount, programId, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }) => {
|
|
268
|
+
const topupStreamInstruction = async (amount, programId, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }) => {
|
|
260
269
|
const keys = [
|
|
261
270
|
{ pubkey: sender, isSigner: true, isWritable: true },
|
|
262
271
|
{ pubkey: senderTokens, isSigner: false, isWritable: true },
|
|
@@ -279,7 +288,7 @@ const topupStreamInstruction = (amount, programId, { sender, senderTokens, metad
|
|
|
279
288
|
const decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
|
|
280
289
|
const encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
|
|
281
290
|
data = data.slice(0, encodeLength);
|
|
282
|
-
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:topup")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
|
|
291
|
+
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(await sha256.digest("global:topup")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
|
|
283
292
|
return new web3_js_1.TransactionInstruction({
|
|
284
293
|
keys,
|
|
285
294
|
programId,
|
|
@@ -171,7 +171,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
171
171
|
const streamflowTreasuryTokens = await ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
172
172
|
const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
|
|
173
173
|
const partnerTokens = await ata(mintPublicKey, partnerPublicKey, tokenProgramId);
|
|
174
|
-
ixs.push(createStreamInstruction({
|
|
174
|
+
ixs.push(await createStreamInstruction({
|
|
175
175
|
start: new BN(start),
|
|
176
176
|
depositedAmount,
|
|
177
177
|
period: new BN(period),
|
|
@@ -261,7 +261,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
261
261
|
const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
|
|
262
262
|
ixs.push(...(await prepareWrappedAccount(this.connection, sender.publicKey, totalAmount)));
|
|
263
263
|
}
|
|
264
|
-
const createInstruction = createUncheckedStreamInstruction({
|
|
264
|
+
const createInstruction = await createUncheckedStreamInstruction({
|
|
265
265
|
start: new BN(start),
|
|
266
266
|
depositedAmount,
|
|
267
267
|
period: new BN(period),
|
|
@@ -534,7 +534,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
534
534
|
const streamflowTreasuryTokens = await ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
535
535
|
const partnerTokens = await ata(mint, partner, tokenProgramId);
|
|
536
536
|
const ataIx = await this.getCreateATAInstructions([sender, recipient, streamflowTreasury, partner], mint, invoker, checkTokenAccounts, tokenProgramId);
|
|
537
|
-
ixs.push(...ataIx, withdrawStreamInstruction(amount, this.programId, {
|
|
537
|
+
ixs.push(...ataIx, await withdrawStreamInstruction(amount, this.programId, {
|
|
538
538
|
partner,
|
|
539
539
|
partnerTokens,
|
|
540
540
|
mint,
|
|
@@ -631,7 +631,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
631
631
|
computeLimit,
|
|
632
632
|
});
|
|
633
633
|
const ixsAta = await this.getCreateATAInstructions([sender, recipient, partner, streamflowTreasury], mint, invoker, checkTokenAccounts, tokenProgramId);
|
|
634
|
-
ixs.push(...ixsAta, cancelStreamInstruction(this.programId, {
|
|
634
|
+
ixs.push(...ixsAta, await cancelStreamInstruction(this.programId, {
|
|
635
635
|
sender,
|
|
636
636
|
senderTokens,
|
|
637
637
|
recipient,
|
|
@@ -683,7 +683,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
683
683
|
const { mint } = decodeStream(escrow?.data);
|
|
684
684
|
const { tokenProgramId } = await getMintAndProgram(this.connection, mint);
|
|
685
685
|
const newRecipientTokens = await ata(mint, newRecipientPublicKey, tokenProgramId);
|
|
686
|
-
ixs.push(transferStreamInstruction(this.programId, {
|
|
686
|
+
ixs.push(await transferStreamInstruction(this.programId, {
|
|
687
687
|
authority: invoker.publicKey,
|
|
688
688
|
newRecipient: newRecipientPublicKey,
|
|
689
689
|
newRecipientTokens,
|
|
@@ -732,7 +732,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
732
732
|
if (isNative) {
|
|
733
733
|
ixs.push(...(await prepareWrappedAccount(this.connection, invoker.publicKey, amount)));
|
|
734
734
|
}
|
|
735
|
-
ixs.push(topupStreamInstruction(amount, this.programId, {
|
|
735
|
+
ixs.push(await topupStreamInstruction(amount, this.programId, {
|
|
736
736
|
sender: invoker.publicKey,
|
|
737
737
|
senderTokens,
|
|
738
738
|
metadata: streamPublicKey,
|
|
@@ -893,7 +893,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
893
893
|
computePrice,
|
|
894
894
|
computeLimit,
|
|
895
895
|
});
|
|
896
|
-
ixs.push(updateStreamInstruction(data, this.programId, {
|
|
896
|
+
ixs.push(await updateStreamInstruction(data, this.programId, {
|
|
897
897
|
authority: invoker.publicKey,
|
|
898
898
|
metadata: streamPublicKey,
|
|
899
899
|
withdrawor: WITHDRAWOR_PUBLIC_KEY,
|
|
@@ -39,7 +39,7 @@ interface CreateStreamAccounts {
|
|
|
39
39
|
withdrawor: PublicKey;
|
|
40
40
|
systemProgram: PublicKey;
|
|
41
41
|
}
|
|
42
|
-
export declare const createStreamInstruction: (data: CreateStreamData, programId: PublicKey, accounts: CreateStreamAccounts) => TransactionInstruction
|
|
42
|
+
export declare const createStreamInstruction: (data: CreateStreamData, programId: PublicKey, accounts: CreateStreamAccounts) => Promise<TransactionInstruction>;
|
|
43
43
|
interface CreateUncheckedStreamData {
|
|
44
44
|
start: BN;
|
|
45
45
|
depositedAmount: BN;
|
|
@@ -74,7 +74,7 @@ interface CreateUncheckedStreamAccounts {
|
|
|
74
74
|
withdrawor: PublicKey;
|
|
75
75
|
systemProgram: PublicKey;
|
|
76
76
|
}
|
|
77
|
-
export declare const createUncheckedStreamInstruction: (data: CreateUncheckedStreamData, programId: PublicKey, accounts: CreateUncheckedStreamAccounts) => TransactionInstruction
|
|
77
|
+
export declare const createUncheckedStreamInstruction: (data: CreateUncheckedStreamData, programId: PublicKey, accounts: CreateUncheckedStreamAccounts) => Promise<TransactionInstruction>;
|
|
78
78
|
interface WithdrawAccounts {
|
|
79
79
|
authority: PublicKey;
|
|
80
80
|
recipient: PublicKey;
|
|
@@ -88,14 +88,14 @@ interface WithdrawAccounts {
|
|
|
88
88
|
mint: PublicKey;
|
|
89
89
|
tokenProgram: PublicKey;
|
|
90
90
|
}
|
|
91
|
-
export declare const withdrawStreamInstruction: (amount: BN, programId: PublicKey, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }: WithdrawAccounts) => TransactionInstruction
|
|
91
|
+
export declare const withdrawStreamInstruction: (amount: BN, programId: PublicKey, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }: WithdrawAccounts) => Promise<TransactionInstruction>;
|
|
92
92
|
interface UpdateAccounts {
|
|
93
93
|
authority: PublicKey;
|
|
94
94
|
metadata: PublicKey;
|
|
95
95
|
withdrawor: PublicKey;
|
|
96
96
|
systemProgram: PublicKey;
|
|
97
97
|
}
|
|
98
|
-
export declare const updateStreamInstruction: (params: IUpdateData, programId: PublicKey, { authority, metadata, withdrawor, systemProgram }: UpdateAccounts) => TransactionInstruction
|
|
98
|
+
export declare const updateStreamInstruction: (params: IUpdateData, programId: PublicKey, { authority, metadata, withdrawor, systemProgram }: UpdateAccounts) => Promise<TransactionInstruction>;
|
|
99
99
|
interface CancelAccounts {
|
|
100
100
|
authority: PublicKey;
|
|
101
101
|
sender: PublicKey;
|
|
@@ -111,7 +111,7 @@ interface CancelAccounts {
|
|
|
111
111
|
mint: PublicKey;
|
|
112
112
|
tokenProgram: PublicKey;
|
|
113
113
|
}
|
|
114
|
-
export declare const cancelStreamInstruction: (programId: PublicKey, { authority, sender, senderTokens, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }: CancelAccounts) => TransactionInstruction
|
|
114
|
+
export declare const cancelStreamInstruction: (programId: PublicKey, { authority, sender, senderTokens, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }: CancelAccounts) => Promise<TransactionInstruction>;
|
|
115
115
|
interface TransferAccounts {
|
|
116
116
|
authority: PublicKey;
|
|
117
117
|
newRecipient: PublicKey;
|
|
@@ -123,7 +123,7 @@ interface TransferAccounts {
|
|
|
123
123
|
associatedTokenProgram: PublicKey;
|
|
124
124
|
systemProgram: PublicKey;
|
|
125
125
|
}
|
|
126
|
-
export declare const transferStreamInstruction: (programId: PublicKey, { authority, newRecipient, newRecipientTokens, metadata, mint, rent, tokenProgram, associatedTokenProgram, systemProgram, }: TransferAccounts) => TransactionInstruction
|
|
126
|
+
export declare const transferStreamInstruction: (programId: PublicKey, { authority, newRecipient, newRecipientTokens, metadata, mint, rent, tokenProgram, associatedTokenProgram, systemProgram, }: TransferAccounts) => Promise<TransactionInstruction>;
|
|
127
127
|
interface TopupAccounts {
|
|
128
128
|
sender: PublicKey;
|
|
129
129
|
senderTokens: PublicKey;
|
|
@@ -138,5 +138,5 @@ interface TopupAccounts {
|
|
|
138
138
|
withdrawor: PublicKey;
|
|
139
139
|
systemProgram: PublicKey;
|
|
140
140
|
}
|
|
141
|
-
export declare const topupStreamInstruction: (amount: BN, programId: PublicKey, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }: TopupAccounts) => TransactionInstruction
|
|
141
|
+
export declare const topupStreamInstruction: (amount: BN, programId: PublicKey, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }: TopupAccounts) => Promise<TransactionInstruction>;
|
|
142
142
|
export {};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
2
|
import { TransactionInstruction } from "@solana/web3.js";
|
|
3
|
-
import { createHash } from "node:crypto";
|
|
4
3
|
import * as Layout from "./layout.js";
|
|
5
|
-
const hasher = () => createHash("sha256");
|
|
6
4
|
const sha256 = {
|
|
7
|
-
digest: (data) =>
|
|
5
|
+
digest: async (data) => {
|
|
6
|
+
const dataBuffer = new TextEncoder().encode(data);
|
|
7
|
+
const hashBuffer = await globalThis.crypto.subtle.digest("SHA-256", dataBuffer);
|
|
8
|
+
return new Uint8Array(hashBuffer);
|
|
9
|
+
},
|
|
8
10
|
};
|
|
9
|
-
export const createStreamInstruction = (data, programId, accounts) => {
|
|
11
|
+
export const createStreamInstruction = async (data, programId, accounts) => {
|
|
10
12
|
const keys = [
|
|
11
13
|
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
12
14
|
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
@@ -64,14 +66,18 @@ export const createStreamInstruction = (data, programId, accounts) => {
|
|
|
64
66
|
};
|
|
65
67
|
const encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
|
|
66
68
|
bufferData = bufferData.slice(0, encodeLength);
|
|
67
|
-
bufferData = Buffer.concat([
|
|
69
|
+
bufferData = Buffer.concat([
|
|
70
|
+
Buffer.from(await sha256.digest("global:create")).slice(0, 8),
|
|
71
|
+
bufferData,
|
|
72
|
+
Buffer.alloc(10),
|
|
73
|
+
]);
|
|
68
74
|
return new TransactionInstruction({
|
|
69
75
|
keys,
|
|
70
76
|
programId,
|
|
71
77
|
data: bufferData,
|
|
72
78
|
});
|
|
73
79
|
};
|
|
74
|
-
export const createUncheckedStreamInstruction = (data, programId, accounts) => {
|
|
80
|
+
export const createUncheckedStreamInstruction = async (data, programId, accounts) => {
|
|
75
81
|
const keys = [
|
|
76
82
|
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
77
83
|
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
@@ -118,8 +124,8 @@ export const createUncheckedStreamInstruction = (data, programId, accounts) => {
|
|
|
118
124
|
const encodeLength = Layout.createUncheckedStreamLayout.encode(decodedData, bufferData);
|
|
119
125
|
bufferData = bufferData.slice(0, encodeLength);
|
|
120
126
|
const digest = accounts.payer
|
|
121
|
-
? sha256.digest("global:create_unchecked_with_payer")
|
|
122
|
-
: sha256.digest("global:create_unchecked");
|
|
127
|
+
? await sha256.digest("global:create_unchecked_with_payer")
|
|
128
|
+
: await sha256.digest("global:create_unchecked");
|
|
123
129
|
bufferData = Buffer.concat([Buffer.from(digest).slice(0, 8), bufferData, Buffer.alloc(10)]);
|
|
124
130
|
return new TransactionInstruction({
|
|
125
131
|
keys,
|
|
@@ -127,7 +133,7 @@ export const createUncheckedStreamInstruction = (data, programId, accounts) => {
|
|
|
127
133
|
data: bufferData,
|
|
128
134
|
});
|
|
129
135
|
};
|
|
130
|
-
export const withdrawStreamInstruction = (amount, programId, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }) => {
|
|
136
|
+
export const withdrawStreamInstruction = async (amount, programId, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }) => {
|
|
131
137
|
const keys = [
|
|
132
138
|
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
133
139
|
{ pubkey: recipient, isSigner: false, isWritable: true },
|
|
@@ -149,14 +155,14 @@ export const withdrawStreamInstruction = (amount, programId, { authority, recipi
|
|
|
149
155
|
const decodedData = { amount: amount.toArrayLike(Buffer, "le", 8) };
|
|
150
156
|
const encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
|
|
151
157
|
data = data.slice(0, encodeLength);
|
|
152
|
-
data = Buffer.concat([Buffer.from(sha256.digest("global:withdraw")).slice(0, 8), data, Buffer.alloc(10)]);
|
|
158
|
+
data = Buffer.concat([Buffer.from(await sha256.digest("global:withdraw")).slice(0, 8), data, Buffer.alloc(10)]);
|
|
153
159
|
return new TransactionInstruction({
|
|
154
160
|
keys,
|
|
155
161
|
programId,
|
|
156
162
|
data,
|
|
157
163
|
});
|
|
158
164
|
};
|
|
159
|
-
export const updateStreamInstruction = (params, programId, { authority, metadata, withdrawor, systemProgram }) => {
|
|
165
|
+
export const updateStreamInstruction = async (params, programId, { authority, metadata, withdrawor, systemProgram }) => {
|
|
160
166
|
const keys = [
|
|
161
167
|
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
162
168
|
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
@@ -171,14 +177,14 @@ export const updateStreamInstruction = (params, programId, { authority, metadata
|
|
|
171
177
|
};
|
|
172
178
|
const encodeLength = Layout.encodeUpdateStream(decodedData, data);
|
|
173
179
|
data = data.slice(0, encodeLength);
|
|
174
|
-
data = Buffer.concat([Buffer.from(sha256.digest("global:update")).slice(0, 8), data, Buffer.alloc(20)]);
|
|
180
|
+
data = Buffer.concat([Buffer.from(await sha256.digest("global:update")).slice(0, 8), data, Buffer.alloc(20)]);
|
|
175
181
|
return new TransactionInstruction({
|
|
176
182
|
keys: keys,
|
|
177
183
|
programId: programId,
|
|
178
184
|
data: data,
|
|
179
185
|
});
|
|
180
186
|
};
|
|
181
|
-
export const cancelStreamInstruction = (programId, { authority, sender, senderTokens, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }) => {
|
|
187
|
+
export const cancelStreamInstruction = async (programId, { authority, sender, senderTokens, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }) => {
|
|
182
188
|
const keys = [
|
|
183
189
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
184
190
|
{ pubkey: sender, isSigner: false, isWritable: true },
|
|
@@ -198,14 +204,14 @@ export const cancelStreamInstruction = (programId, { authority, sender, senderTo
|
|
|
198
204
|
{ pubkey: mint, isSigner: false, isWritable: true },
|
|
199
205
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
200
206
|
];
|
|
201
|
-
const data = Buffer.concat([Buffer.from(sha256.digest("global:cancel")).slice(0, 8), Buffer.alloc(10)]);
|
|
207
|
+
const data = Buffer.concat([Buffer.from(await sha256.digest("global:cancel")).slice(0, 8), Buffer.alloc(10)]);
|
|
202
208
|
return new TransactionInstruction({
|
|
203
209
|
keys,
|
|
204
210
|
programId,
|
|
205
211
|
data,
|
|
206
212
|
});
|
|
207
213
|
};
|
|
208
|
-
export const transferStreamInstruction = (programId, { authority, newRecipient, newRecipientTokens, metadata, mint, rent, tokenProgram, associatedTokenProgram, systemProgram, }) => {
|
|
214
|
+
export const transferStreamInstruction = async (programId, { authority, newRecipient, newRecipientTokens, metadata, mint, rent, tokenProgram, associatedTokenProgram, systemProgram, }) => {
|
|
209
215
|
const keys = [
|
|
210
216
|
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
211
217
|
{ pubkey: newRecipient, isSigner: false, isWritable: true },
|
|
@@ -217,14 +223,17 @@ export const transferStreamInstruction = (programId, { authority, newRecipient,
|
|
|
217
223
|
{ pubkey: associatedTokenProgram, isSigner: false, isWritable: false },
|
|
218
224
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
219
225
|
];
|
|
220
|
-
const data = Buffer.concat([
|
|
226
|
+
const data = Buffer.concat([
|
|
227
|
+
Buffer.from(await sha256.digest("global:transfer_recipient")).slice(0, 8),
|
|
228
|
+
Buffer.alloc(10),
|
|
229
|
+
]);
|
|
221
230
|
return new TransactionInstruction({
|
|
222
231
|
keys,
|
|
223
232
|
programId,
|
|
224
233
|
data,
|
|
225
234
|
});
|
|
226
235
|
};
|
|
227
|
-
export const topupStreamInstruction = (amount, programId, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }) => {
|
|
236
|
+
export const topupStreamInstruction = async (amount, programId, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }) => {
|
|
228
237
|
const keys = [
|
|
229
238
|
{ pubkey: sender, isSigner: true, isWritable: true },
|
|
230
239
|
{ pubkey: senderTokens, isSigner: false, isWritable: true },
|
|
@@ -247,7 +256,7 @@ export const topupStreamInstruction = (amount, programId, { sender, senderTokens
|
|
|
247
256
|
const decodedData = { amount: amount.toArrayLike(Buffer, "le", 8) };
|
|
248
257
|
const encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
|
|
249
258
|
data = data.slice(0, encodeLength);
|
|
250
|
-
data = Buffer.concat([Buffer.from(sha256.digest("global:topup")).slice(0, 8), data, Buffer.alloc(10)]);
|
|
259
|
+
data = Buffer.concat([Buffer.from(await sha256.digest("global:topup")).slice(0, 8), data, Buffer.alloc(10)]);
|
|
251
260
|
return new TransactionInstruction({
|
|
252
261
|
keys,
|
|
253
262
|
programId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/stream",
|
|
3
|
-
"version": "7.1.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "JavaScript SDK to interact with Streamflow protocol.",
|
|
5
5
|
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
6
6
|
"main": "./dist/esm/index.js",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"lint": "eslint --fix .",
|
|
43
43
|
"prepublishOnly": "pnpm run lint && pnpm run test run && pnpm run build"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "43138796876f19398e3fbae5173c901cd7b5a580",
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@streamflow/eslint-config": "7.1.0
|
|
47
|
+
"@streamflow/eslint-config": "7.1.0",
|
|
48
48
|
"@types/bn.js": "5.1.1",
|
|
49
49
|
"@types/ethereum-checksum-address": "^0.0.0",
|
|
50
50
|
"date-fns": "2.28.0",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@solana/spl-token": "0.4.9",
|
|
60
60
|
"@solana/wallet-adapter-base": "0.9.19",
|
|
61
61
|
"@solana/web3.js": "1.95.4",
|
|
62
|
-
"@streamflow/common": "7.1.0
|
|
62
|
+
"@streamflow/common": "7.1.0",
|
|
63
63
|
"@suiet/wallet-kit": "0.2.22",
|
|
64
64
|
"aptos": "1.21.0",
|
|
65
65
|
"bn.js": "5.2.1",
|