@streamflow/stream 4.0.1 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aptos/StreamClient.d.ts +5 -1
- package/dist/aptos/StreamClient.js +29 -0
- package/dist/common/BaseStreamClient.d.ts +2 -1
- package/dist/common/GenericStreamClient.d.ts +5 -1
- package/dist/common/GenericStreamClient.js +13 -0
- package/dist/common/types.d.ts +6 -0
- package/dist/solana/StreamClient.d.ts +5 -1
- package/dist/solana/StreamClient.js +53 -4
- package/dist/solana/instructionTypes.d.ts +5 -0
- package/dist/solana/instructions.d.ts +8 -0
- package/dist/solana/instructions.js +33 -1
- package/dist/solana/layout.d.ts +6 -1
- package/dist/solana/layout.js +38 -1
- package/dist/solana/utils.js +12 -8
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseStreamClient } from "../common/BaseStreamClient";
|
|
2
|
-
import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IWithdrawData } from "../common/types";
|
|
2
|
+
import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData } from "../common/types";
|
|
3
3
|
import { Contract, ICreateStreamAptosExt, IMultiTransactionResult, ITransactionAptosExt, ITransactionResult } from "./types";
|
|
4
4
|
export default class AptosStreamClient extends BaseStreamClient {
|
|
5
5
|
private programId;
|
|
@@ -34,6 +34,10 @@ export default class AptosStreamClient extends BaseStreamClient {
|
|
|
34
34
|
* Fetch stream data by its id (address).
|
|
35
35
|
*/
|
|
36
36
|
getOne({ id }: IGetOneData): Promise<Contract>;
|
|
37
|
+
/**
|
|
38
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
39
|
+
*/
|
|
40
|
+
update(updateData: IUpdateData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
|
|
37
41
|
/**
|
|
38
42
|
* Returns StreamClient protocol program ID.
|
|
39
43
|
*/
|
|
@@ -287,6 +287,35 @@ var AptosStreamClient = /** @class */ (function (_super) {
|
|
|
287
287
|
});
|
|
288
288
|
});
|
|
289
289
|
};
|
|
290
|
+
/**
|
|
291
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
292
|
+
*/
|
|
293
|
+
AptosStreamClient.prototype.update = function (updateData, _a) {
|
|
294
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
295
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
296
|
+
var payload, hash;
|
|
297
|
+
return __generator(this, function (_b) {
|
|
298
|
+
switch (_b.label) {
|
|
299
|
+
case 0:
|
|
300
|
+
payload = {
|
|
301
|
+
type: "update",
|
|
302
|
+
function: "".concat(this.programId, "::protocol::update"),
|
|
303
|
+
type_arguments: [tokenId],
|
|
304
|
+
arguments: [
|
|
305
|
+
updateData.id,
|
|
306
|
+
updateData.enableAutomaticWithdrawal ? [true] : [],
|
|
307
|
+
updateData.withdrawFrequency ? [updateData.withdrawFrequency.toString()] : [],
|
|
308
|
+
updateData.amountPerPeriod ? [updateData.amountPerPeriod.toString()] : [],
|
|
309
|
+
],
|
|
310
|
+
};
|
|
311
|
+
return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
|
|
312
|
+
case 1:
|
|
313
|
+
hash = (_b.sent()).hash;
|
|
314
|
+
return [2 /*return*/, { txId: hash }];
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
};
|
|
290
319
|
/**
|
|
291
320
|
* Returns StreamClient protocol program ID.
|
|
292
321
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData } from "./types";
|
|
1
|
+
import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData, IUpdateData } from "./types";
|
|
2
2
|
export declare abstract class BaseStreamClient {
|
|
3
3
|
protected abstract create(streamData: ICreateStreamData, chainSpecificParams: any): Promise<any>;
|
|
4
4
|
protected abstract createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: any): Promise<any>;
|
|
@@ -7,4 +7,5 @@ export declare abstract class BaseStreamClient {
|
|
|
7
7
|
protected abstract transfer(transferData: ITransferData, chainSpecificParams: any): Promise<any>;
|
|
8
8
|
protected abstract topup(topupData: ITopUpData, chainSpecificParams: any): Promise<any>;
|
|
9
9
|
protected abstract getOne(getOneData: IGetOneData, chainSpecificParams: any): Promise<any>;
|
|
10
|
+
protected abstract update(updateData: IUpdateData, chainSpecificParams: any): Promise<any>;
|
|
10
11
|
}
|
|
@@ -2,7 +2,7 @@ import { Commitment, ConnectionConfig } from "@solana/web3.js";
|
|
|
2
2
|
import SolanaStreamClient from "../solana/StreamClient";
|
|
3
3
|
import AptosStreamClient from "../aptos/StreamClient";
|
|
4
4
|
import { BaseStreamClient } from "./BaseStreamClient";
|
|
5
|
-
import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IWithdrawData } from "./types";
|
|
5
|
+
import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData } from "./types";
|
|
6
6
|
import { CreateMultiResponse, CreateResponse, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt, Stream, TxResponse } from "../solana";
|
|
7
7
|
import { ICreateStreamAptosExt, IMultiTransactionResult, ITransactionAptosExt, ITransactionResult } from "../aptos";
|
|
8
8
|
export interface SolanaStreamClientOptions {
|
|
@@ -52,5 +52,9 @@ export default class GenericStreamClient extends BaseStreamClient {
|
|
|
52
52
|
* Fetch stream data by its id (address).
|
|
53
53
|
*/
|
|
54
54
|
getOne(getOneData: IGetOneData): Promise<Stream>;
|
|
55
|
+
/**
|
|
56
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
57
|
+
*/
|
|
58
|
+
update(updateData: IUpdateData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<TxResponse | ITransactionResult>;
|
|
55
59
|
}
|
|
56
60
|
export {};
|
|
@@ -119,6 +119,19 @@ var GenericStreamClient = /** @class */ (function (_super) {
|
|
|
119
119
|
GenericStreamClient.prototype.getOne = function (getOneData) {
|
|
120
120
|
return this.nativeStreamClient.getOne(getOneData);
|
|
121
121
|
};
|
|
122
|
+
/**
|
|
123
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
124
|
+
*/
|
|
125
|
+
GenericStreamClient.prototype.update = function (updateData, chainSpecificParams) {
|
|
126
|
+
if (this.nativeStreamClient instanceof StreamClient_1.default) {
|
|
127
|
+
var params = chainSpecificParams;
|
|
128
|
+
return this.nativeStreamClient.update(updateData, params);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
var params = chainSpecificParams;
|
|
132
|
+
return this.nativeStreamClient.update(updateData, params);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
122
135
|
return GenericStreamClient;
|
|
123
136
|
}(BaseStreamClient_1.BaseStreamClient));
|
|
124
137
|
exports.default = GenericStreamClient;
|
package/dist/common/types.d.ts
CHANGED
|
@@ -29,6 +29,12 @@ export interface IWithdrawData {
|
|
|
29
29
|
id: string;
|
|
30
30
|
amount: BN;
|
|
31
31
|
}
|
|
32
|
+
export interface IUpdateData {
|
|
33
|
+
id: string;
|
|
34
|
+
enableAutomaticWithdrawal?: boolean;
|
|
35
|
+
withdrawFrequency?: BN;
|
|
36
|
+
amountPerPeriod?: BN;
|
|
37
|
+
}
|
|
32
38
|
export interface ICancelData {
|
|
33
39
|
id: string;
|
|
34
40
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connection, Commitment, ConnectionConfig } from "@solana/web3.js";
|
|
2
2
|
import { Stream as StreamData, GetAllParams, CreateResponse, CreateMultiResponse, TxResponse, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "./types";
|
|
3
|
-
import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IWithdrawData } from "../common/types";
|
|
3
|
+
import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData } from "../common/types";
|
|
4
4
|
import { BaseStreamClient } from "../common/BaseStreamClient";
|
|
5
5
|
export default class SolanaStreamClient extends BaseStreamClient {
|
|
6
6
|
private connection;
|
|
@@ -60,6 +60,10 @@ export default class SolanaStreamClient extends BaseStreamClient {
|
|
|
60
60
|
*/
|
|
61
61
|
get({ wallet, type, direction, }: GetAllParams): Promise<[string, StreamData][]>;
|
|
62
62
|
private sign;
|
|
63
|
+
/**
|
|
64
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
65
|
+
*/
|
|
66
|
+
update(data: IUpdateData, { invoker }: IInteractStreamSolanaExt): Promise<TxResponse>;
|
|
63
67
|
/**
|
|
64
68
|
* Forms instructions from params, creates a raw transaction and fetch recent blockhash.
|
|
65
69
|
*/
|
|
@@ -343,7 +343,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
343
343
|
SolanaStreamClient.prototype.createMultiple = function (data, _a) {
|
|
344
344
|
var sender = _a.sender, _b = _a.partner, partner = _b === void 0 ? null : _b, _c = _a.isNative, isNative = _c === void 0 ? false : _c;
|
|
345
345
|
return __awaiter(this, void 0, void 0, function () {
|
|
346
|
-
var recipients, metadatas, metadataToRecipient, errors, signatures, batch, recipients_1, recipients_1_1, recipientData, _d, tx, metadata, metadataPubKey, e_1_1, totalDepositedAmount, nativeInstructions, commitment, hash, prepareTransaction,
|
|
346
|
+
var recipients, metadatas, metadataToRecipient, errors, signatures, batch, recipients_1, recipients_1_1, recipientData, _d, tx, metadata, metadataPubKey, e_1_1, totalDepositedAmount, nativeInstructions, commitment, hash, prepareTransaction, signedBatch, prepareTx, batchTransactionsCalls, responses, successes, failures;
|
|
347
347
|
var e_1, _e, _f;
|
|
348
348
|
var _this = this;
|
|
349
349
|
return __generator(this, function (_g) {
|
|
@@ -410,15 +410,18 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
410
410
|
_g.label = 11;
|
|
411
411
|
case 11: return [4 /*yield*/, (0, utils_1.signAllTransactionWithRecipients)(sender, batch)];
|
|
412
412
|
case 12:
|
|
413
|
-
|
|
413
|
+
signedBatch = _g.sent();
|
|
414
|
+
signedBatch.forEach(function (item, index) {
|
|
415
|
+
item.tx.lastValidBlockHeight = batch[index].tx.lastValidBlockHeight;
|
|
416
|
+
});
|
|
414
417
|
if (!isNative) return [3 /*break*/, 14];
|
|
415
|
-
prepareTx =
|
|
418
|
+
prepareTx = signedBatch.pop();
|
|
416
419
|
return [4 /*yield*/, (0, utils_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx)];
|
|
417
420
|
case 13:
|
|
418
421
|
_g.sent();
|
|
419
422
|
_g.label = 14;
|
|
420
423
|
case 14:
|
|
421
|
-
batchTransactionsCalls =
|
|
424
|
+
batchTransactionsCalls = signedBatch.map(function (el) {
|
|
422
425
|
return (0, utils_1.sendAndConfirmStreamRawTransaction)(_this.connection, el);
|
|
423
426
|
});
|
|
424
427
|
return [4 /*yield*/, Promise.allSettled(batchTransactionsCalls)];
|
|
@@ -787,6 +790,52 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
787
790
|
});
|
|
788
791
|
});
|
|
789
792
|
};
|
|
793
|
+
/**
|
|
794
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
795
|
+
*/
|
|
796
|
+
SolanaStreamClient.prototype.update = function (data, _a) {
|
|
797
|
+
var invoker = _a.invoker;
|
|
798
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
799
|
+
var streamPublicKey, escrow, updateIx, commitment, hash, tx, signature;
|
|
800
|
+
return __generator(this, function (_b) {
|
|
801
|
+
switch (_b.label) {
|
|
802
|
+
case 0:
|
|
803
|
+
if (!invoker.publicKey) {
|
|
804
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
805
|
+
}
|
|
806
|
+
streamPublicKey = new web3_js_1.PublicKey(data.id);
|
|
807
|
+
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
808
|
+
case 1:
|
|
809
|
+
escrow = _b.sent();
|
|
810
|
+
if (!escrow) {
|
|
811
|
+
throw new Error("Couldn't get account info");
|
|
812
|
+
}
|
|
813
|
+
updateIx = (0, instructions_1.updateStreamInstruction)(data, this.programId, {
|
|
814
|
+
authority: invoker.publicKey,
|
|
815
|
+
metadata: streamPublicKey,
|
|
816
|
+
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
817
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
818
|
+
});
|
|
819
|
+
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
820
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
821
|
+
case 2:
|
|
822
|
+
hash = _b.sent();
|
|
823
|
+
tx = new web3_js_1.Transaction({
|
|
824
|
+
feePayer: invoker.publicKey,
|
|
825
|
+
blockhash: hash.blockhash,
|
|
826
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
827
|
+
}).add(updateIx);
|
|
828
|
+
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
829
|
+
case 3:
|
|
830
|
+
signature = _b.sent();
|
|
831
|
+
return [2 /*return*/, {
|
|
832
|
+
ixs: [updateIx],
|
|
833
|
+
tx: signature,
|
|
834
|
+
}];
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
});
|
|
838
|
+
};
|
|
790
839
|
/**
|
|
791
840
|
* Forms instructions from params, creates a raw transaction and fetch recent blockhash.
|
|
792
841
|
*/
|
|
@@ -76,6 +76,11 @@ export interface ICreateUncheckedStreamLayout {
|
|
|
76
76
|
export interface IWithdrawStreamLayout {
|
|
77
77
|
amount: Uint8Array;
|
|
78
78
|
}
|
|
79
|
+
export interface IUpdateStreamLayout {
|
|
80
|
+
enable_automatic_withdrawal?: number;
|
|
81
|
+
withdraw_frequency?: Uint8Array;
|
|
82
|
+
amount_per_period?: Uint8Array;
|
|
83
|
+
}
|
|
79
84
|
export interface ITopupStreamLayout {
|
|
80
85
|
amount: Uint8Array;
|
|
81
86
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
2
|
import BN from "bn.js";
|
|
3
|
+
import { IUpdateData } from "../common/types";
|
|
3
4
|
interface CreateStreamData {
|
|
4
5
|
start: BN;
|
|
5
6
|
depositedAmount: BN;
|
|
@@ -84,6 +85,13 @@ interface WithdrawAccounts {
|
|
|
84
85
|
tokenProgram: PublicKey;
|
|
85
86
|
}
|
|
86
87
|
export declare const withdrawStreamInstruction: (amount: BN, programId: PublicKey, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }: WithdrawAccounts) => TransactionInstruction;
|
|
88
|
+
interface UpdateAccounts {
|
|
89
|
+
authority: PublicKey;
|
|
90
|
+
metadata: PublicKey;
|
|
91
|
+
withdrawor: PublicKey;
|
|
92
|
+
systemProgram: PublicKey;
|
|
93
|
+
}
|
|
94
|
+
export declare const updateStreamInstruction: (params: IUpdateData, programId: PublicKey, { authority, metadata, withdrawor, systemProgram }: UpdateAccounts) => TransactionInstruction;
|
|
87
95
|
interface CancelAccounts {
|
|
88
96
|
authority: PublicKey;
|
|
89
97
|
sender: PublicKey;
|
|
@@ -87,7 +87,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
87
87
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
88
88
|
};
|
|
89
89
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
90
|
-
exports.prepareWrappedAccount = exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
|
|
90
|
+
exports.prepareWrappedAccount = exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.updateStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
|
|
91
91
|
var buffer_1 = require("buffer");
|
|
92
92
|
var web3_js_1 = require("@solana/web3.js");
|
|
93
93
|
var bn_js_1 = __importDefault(require("bn.js"));
|
|
@@ -253,6 +253,38 @@ var withdrawStreamInstruction = function (amount, programId, _a) {
|
|
|
253
253
|
});
|
|
254
254
|
};
|
|
255
255
|
exports.withdrawStreamInstruction = withdrawStreamInstruction;
|
|
256
|
+
var updateStreamInstruction = function (params, programId, _a) {
|
|
257
|
+
var authority = _a.authority, metadata = _a.metadata, withdrawor = _a.withdrawor, systemProgram = _a.systemProgram;
|
|
258
|
+
var keys = [
|
|
259
|
+
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
260
|
+
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
261
|
+
{ pubkey: withdrawor, isSigner: false, isWritable: true },
|
|
262
|
+
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
263
|
+
];
|
|
264
|
+
var data = buffer_1.Buffer.alloc(100);
|
|
265
|
+
var decodedData = {
|
|
266
|
+
enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
|
|
267
|
+
withdraw_frequency: params.withdrawFrequency
|
|
268
|
+
? params.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8)
|
|
269
|
+
: undefined,
|
|
270
|
+
amount_per_period: params.amountPerPeriod
|
|
271
|
+
? params.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8)
|
|
272
|
+
: undefined,
|
|
273
|
+
};
|
|
274
|
+
var encodeLength = Layout.encodeUpdateStream(decodedData, data);
|
|
275
|
+
data = data.slice(0, encodeLength);
|
|
276
|
+
data = buffer_1.Buffer.concat([
|
|
277
|
+
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:update")).slice(0, 8),
|
|
278
|
+
data,
|
|
279
|
+
buffer_1.Buffer.alloc(20),
|
|
280
|
+
]);
|
|
281
|
+
return new web3_js_1.TransactionInstruction({
|
|
282
|
+
keys: keys,
|
|
283
|
+
programId: programId,
|
|
284
|
+
data: data,
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
exports.updateStreamInstruction = updateStreamInstruction;
|
|
256
288
|
var cancelStreamInstruction = function (programId, _a) {
|
|
257
289
|
var authority = _a.authority, sender = _a.sender, senderTokens = _a.senderTokens, recipient = _a.recipient, recipientTokens = _a.recipientTokens, metadata = _a.metadata, escrowTokens = _a.escrowTokens, streamflowTreasury = _a.streamflowTreasury, streamflowTreasuryTokens = _a.streamflowTreasuryTokens, partner = _a.partner, partnerTokens = _a.partnerTokens, mint = _a.mint, tokenProgram = _a.tokenProgram;
|
|
258
290
|
var keys = [
|
package/dist/solana/layout.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import * as BufferLayout from "@solana/buffer-layout";
|
|
2
|
-
import { ICreateStreamLayout, ICreateUncheckedStreamLayout, IStreamLayout, ITopupStreamLayout, IWithdrawStreamLayout } from "./instructionTypes";
|
|
3
|
+
import { ICreateStreamLayout, ICreateUncheckedStreamLayout, IStreamLayout, ITopupStreamLayout, IUpdateStreamLayout, IWithdrawStreamLayout } from "./instructionTypes";
|
|
3
4
|
/**
|
|
4
5
|
* Stream layout
|
|
5
6
|
*/
|
|
@@ -16,6 +17,10 @@ export declare const createUncheckedStreamLayout: BufferLayout.Structure<ICreate
|
|
|
16
17
|
* Withdraw stream instruction layout
|
|
17
18
|
*/
|
|
18
19
|
export declare const withdrawStreamLayout: BufferLayout.Structure<IWithdrawStreamLayout>;
|
|
20
|
+
/**
|
|
21
|
+
* Encode stream instruction layout
|
|
22
|
+
*/
|
|
23
|
+
export declare const encodeUpdateStream: (values: IUpdateStreamLayout, data: Buffer) => number;
|
|
19
24
|
/**
|
|
20
25
|
* Topup stream instruction layout
|
|
21
26
|
*/
|
package/dist/solana/layout.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.topupStreamLayout = exports.withdrawStreamLayout = exports.createUncheckedStreamLayout = exports.createStreamLayout = exports.streamLayout = void 0;
|
|
26
|
+
exports.topupStreamLayout = exports.encodeUpdateStream = exports.withdrawStreamLayout = exports.createUncheckedStreamLayout = exports.createStreamLayout = exports.streamLayout = void 0;
|
|
27
27
|
var BufferLayout = __importStar(require("@solana/buffer-layout"));
|
|
28
28
|
/**
|
|
29
29
|
* Stream layout
|
|
@@ -113,6 +113,43 @@ exports.createUncheckedStreamLayout = BufferLayout.struct([
|
|
|
113
113
|
* Withdraw stream instruction layout
|
|
114
114
|
*/
|
|
115
115
|
exports.withdrawStreamLayout = BufferLayout.struct([BufferLayout.blob(8, "amount")]);
|
|
116
|
+
/**
|
|
117
|
+
* Encode stream instruction layout
|
|
118
|
+
*/
|
|
119
|
+
var encodeUpdateStream = function (values, data) {
|
|
120
|
+
var _a, _b, _c;
|
|
121
|
+
var structs = [];
|
|
122
|
+
if (values.enable_automatic_withdrawal) {
|
|
123
|
+
structs.push(BufferLayout.u8("enable_automatic_withdrawal_exists"));
|
|
124
|
+
structs.push(BufferLayout.u8("enable_automatic_withdrawal"));
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
structs.push(BufferLayout.u8("enable_automatic_withdrawal_exists"));
|
|
128
|
+
}
|
|
129
|
+
if (values.withdraw_frequency) {
|
|
130
|
+
structs.push(BufferLayout.u8("withdraw_frequency_exists"));
|
|
131
|
+
structs.push(BufferLayout.blob(8, "withdraw_frequency"));
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
structs.push(BufferLayout.u8("withdraw_frequency_exists"));
|
|
135
|
+
}
|
|
136
|
+
if (values.amount_per_period) {
|
|
137
|
+
structs.push(BufferLayout.u8("amount_per_period_exists"));
|
|
138
|
+
structs.push(BufferLayout.blob(8, "amount_per_period"));
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
structs.push(BufferLayout.u8("amount_per_period_exists"));
|
|
142
|
+
}
|
|
143
|
+
return BufferLayout.struct(structs).encode({
|
|
144
|
+
enable_automatic_withdrawal_exists: values.enable_automatic_withdrawal ? 1 : 0,
|
|
145
|
+
enable_automatic_withdrawal: (_a = values.enable_automatic_withdrawal) !== null && _a !== void 0 ? _a : 0,
|
|
146
|
+
withdraw_frequency_exists: values.withdraw_frequency ? 1 : 0,
|
|
147
|
+
withdraw_frequency: (_b = values.withdraw_frequency) !== null && _b !== void 0 ? _b : 0,
|
|
148
|
+
amount_per_period_exists: values.amount_per_period ? 1 : 0,
|
|
149
|
+
amount_per_period: (_c = values.amount_per_period) !== null && _c !== void 0 ? _c : 0,
|
|
150
|
+
}, data);
|
|
151
|
+
};
|
|
152
|
+
exports.encodeUpdateStream = encodeUpdateStream;
|
|
116
153
|
/**
|
|
117
154
|
* Topup stream instruction layout
|
|
118
155
|
*/
|
package/dist/solana/utils.js
CHANGED
|
@@ -227,14 +227,15 @@ exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
|
|
|
227
227
|
* @return {Promise<BatchItemResult>} - Returns settled transaction item
|
|
228
228
|
*/
|
|
229
229
|
function sendAndConfirmStreamRawTransaction(connection, batchItem) {
|
|
230
|
+
var _a, _b;
|
|
230
231
|
return __awaiter(this, void 0, void 0, function () {
|
|
231
|
-
var rawTx,
|
|
232
|
-
return __generator(this, function (
|
|
233
|
-
switch (
|
|
232
|
+
var rawTx, _c, lastValidBlockHeight, signature, recentBlockhash, confirmationStrategy, completedTxSignature, error_1;
|
|
233
|
+
return __generator(this, function (_d) {
|
|
234
|
+
switch (_d.label) {
|
|
234
235
|
case 0:
|
|
235
|
-
|
|
236
|
+
_d.trys.push([0, 2, , 3]);
|
|
236
237
|
rawTx = batchItem.tx.serialize();
|
|
237
|
-
|
|
238
|
+
_c = batchItem.tx, lastValidBlockHeight = _c.lastValidBlockHeight, signature = _c.signature, recentBlockhash = _c.recentBlockhash;
|
|
238
239
|
if (!lastValidBlockHeight || !signature || !recentBlockhash)
|
|
239
240
|
throw { recipient: batchItem.recipient, error: "no recent blockhash" };
|
|
240
241
|
confirmationStrategy = {
|
|
@@ -244,11 +245,14 @@ function sendAndConfirmStreamRawTransaction(connection, batchItem) {
|
|
|
244
245
|
};
|
|
245
246
|
return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(connection, rawTx, confirmationStrategy)];
|
|
246
247
|
case 1:
|
|
247
|
-
completedTxSignature =
|
|
248
|
+
completedTxSignature = _d.sent();
|
|
248
249
|
return [2 /*return*/, __assign(__assign({}, batchItem), { signature: completedTxSignature })];
|
|
249
250
|
case 2:
|
|
250
|
-
error_1 =
|
|
251
|
-
throw {
|
|
251
|
+
error_1 = _d.sent();
|
|
252
|
+
throw {
|
|
253
|
+
recipient: batchItem.recipient,
|
|
254
|
+
error: (_b = (_a = error_1 === null || error_1 === void 0 ? void 0 : error_1.error) !== null && _a !== void 0 ? _a : error_1 === null || error_1 === void 0 ? void 0 : error_1.message) !== null && _b !== void 0 ? _b : error_1.toString(),
|
|
255
|
+
};
|
|
252
256
|
case 3: return [2 /*return*/];
|
|
253
257
|
}
|
|
254
258
|
});
|
package/package.json
CHANGED