@streamflow/stream 5.10.4 → 5.11.1

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.
@@ -17,7 +17,7 @@ export default class AptosStreamClient extends BaseStreamClient {
17
17
  /**
18
18
  * Attempts withdrawing from the specified stream.
19
19
  */
20
- withdraw(withdrawData: IWithdrawData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
20
+ withdraw({ id, amount }: IWithdrawData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
21
21
  /**
22
22
  * Attempts canceling the specified stream.
23
23
  */
@@ -85,6 +85,7 @@ var constants_1 = require("./constants");
85
85
  var types_2 = require("./types");
86
86
  var wallet_1 = require("./wallet");
87
87
  var utils_1 = require("./utils");
88
+ var constants_2 = require("../common/constants");
88
89
  var AptosStreamClient = /** @class */ (function (_super) {
89
90
  __extends(AptosStreamClient, _super);
90
91
  function AptosStreamClient(clusterUrl, cluster, maxGas, programId) {
@@ -174,23 +175,24 @@ var AptosStreamClient = /** @class */ (function (_super) {
174
175
  /**
175
176
  * Attempts withdrawing from the specified stream.
176
177
  */
177
- AptosStreamClient.prototype.withdraw = function (withdrawData, _a) {
178
- var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
178
+ AptosStreamClient.prototype.withdraw = function (_a, _b) {
179
+ var id = _a.id, _c = _a.amount, amount = _c === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _c;
180
+ var senderWallet = _b.senderWallet, tokenId = _b.tokenId;
179
181
  return __awaiter(this, void 0, void 0, function () {
180
182
  var payload, wallet, hash;
181
- return __generator(this, function (_b) {
182
- switch (_b.label) {
183
+ return __generator(this, function (_d) {
184
+ switch (_d.label) {
183
185
  case 0:
184
186
  payload = {
185
187
  type: "withdraw",
186
188
  function: "".concat(this.programId, "::protocol::withdraw"),
187
189
  type_arguments: [tokenId],
188
- arguments: [withdrawData.id, withdrawData.amount.toString()],
190
+ arguments: [id, amount.toString()],
189
191
  };
190
192
  wallet = new wallet_1.AptosWalletWrapper(senderWallet, this.client);
191
193
  return [4 /*yield*/, wallet.signAndSubmitTransaction(payload)];
192
194
  case 1:
193
- hash = _b.sent();
195
+ hash = _d.sent();
194
196
  return [2 /*return*/, { ixs: [payload], txId: hash }];
195
197
  }
196
198
  });
@@ -64,7 +64,7 @@ export default class GenericStreamClient<T extends IChain> extends BaseStreamCli
64
64
  /**
65
65
  * Attempts withdrawing from the specified stream.
66
66
  */
67
- withdraw(withdrawData: IWithdrawData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
67
+ withdraw({ id, amount }: IWithdrawData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
68
68
  /**
69
69
  * Attempts canceling the specified stream.
70
70
  */
@@ -22,6 +22,7 @@ var aptos_1 = require("../aptos");
22
22
  var evm_1 = require("../evm");
23
23
  var solana_1 = require("../solana");
24
24
  var sui_1 = require("../sui");
25
+ var constants_1 = require("./constants");
25
26
  /** Generic Stream Client implementation that wrap Chain Client methods and enriches error messages if possible
26
27
  * @property {StreamClientType} - Chain Client implementation
27
28
  * @property {chain} - Chain
@@ -65,9 +66,10 @@ var GenericStreamClient = /** @class */ (function (_super) {
65
66
  /**
66
67
  * Attempts withdrawing from the specified stream.
67
68
  */
68
- GenericStreamClient.prototype.withdraw = function (withdrawData, chainSpecificParams) {
69
+ GenericStreamClient.prototype.withdraw = function (_a, chainSpecificParams) {
69
70
  var _this = this;
70
- return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.withdraw(withdrawData, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
71
+ var id = _a.id, _b = _a.amount, amount = _b === void 0 ? constants_1.WITHDRAW_AVAILABLE_AMOUNT : _b;
72
+ return (0, utils_1.handleContractError)(function () { return _this.nativeStreamClient.withdraw({ id: id, amount: amount }, chainSpecificParams); }, this.nativeStreamClient.extractErrorCode);
71
73
  };
72
74
  /**
73
75
  * Attempts canceling the specified stream.
@@ -1 +1,3 @@
1
+ import BN from "bn.js";
1
2
  export declare const BASE_FEE = 1009900;
3
+ export declare const WITHDRAW_AVAILABLE_AMOUNT: BN;
@@ -1,4 +1,9 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BASE_FEE = void 0;
6
+ exports.WITHDRAW_AVAILABLE_AMOUNT = exports.BASE_FEE = void 0;
7
+ var bn_js_1 = __importDefault(require("bn.js"));
4
8
  exports.BASE_FEE = 1009900; // Buffer to include usual fees when calculating stream amount
9
+ exports.WITHDRAW_AVAILABLE_AMOUNT = new bn_js_1.default("18446744073709551615"); // Magical number to withdraw all available amount from a Contract
@@ -28,30 +28,25 @@ export type ICreateStreamData = IStreamConfig & IRecipient;
28
28
  export type ICreateMultipleStreamData = IStreamConfig & {
29
29
  recipients: IRecipient[];
30
30
  };
31
- export interface IWithdrawData {
31
+ export interface IInteractData {
32
32
  id: string;
33
- amount: BN;
34
33
  }
35
- export interface IUpdateData {
36
- id: string;
34
+ export interface IWithdrawData extends IInteractData {
35
+ amount?: BN;
36
+ }
37
+ export interface IUpdateData extends IInteractData {
37
38
  enableAutomaticWithdrawal?: boolean;
38
39
  withdrawFrequency?: BN;
39
40
  amountPerPeriod?: BN;
40
41
  }
41
- export interface ICancelData {
42
- id: string;
43
- }
44
- export interface ITransferData {
45
- id: string;
42
+ export type ICancelData = IInteractData;
43
+ export interface ITransferData extends IInteractData {
46
44
  newRecipient: string;
47
45
  }
48
- export interface ITopUpData {
49
- id: string;
46
+ export interface ITopUpData extends IInteractData {
50
47
  amount: BN;
51
48
  }
52
- export interface IGetOneData {
53
- id: string;
54
- }
49
+ export type IGetOneData = IInteractData;
55
50
  export interface IGetFeesData {
56
51
  address: string;
57
52
  }
@@ -11,7 +11,7 @@ export default class EvmStreamClient extends BaseStreamClient {
11
11
  constructor(clusterUrl: string, chain: IChain, signer: ethers.Signer, cluster?: ICluster, programId?: string);
12
12
  create(streamData: ICreateStreamData): Promise<ICreateResult>;
13
13
  createMultiple(multipleStreamData: ICreateMultipleStreamData): Promise<IMultiTransactionResult>;
14
- withdraw(withdrawData: IWithdrawData): Promise<ITransactionResult>;
14
+ withdraw({ id, amount, }: IWithdrawData): Promise<ITransactionResult>;
15
15
  cancel(cancelData: ICancelData): Promise<ITransactionResult>;
16
16
  transfer(transferData: ITransferData): Promise<ITransactionResult>;
17
17
  topup(topupData: ITopUpData): Promise<ITransactionResult>;
@@ -226,14 +226,15 @@ var EvmStreamClient = /** @class */ (function (_super) {
226
226
  });
227
227
  });
228
228
  };
229
- EvmStreamClient.prototype.withdraw = function (withdrawData) {
229
+ EvmStreamClient.prototype.withdraw = function (_a) {
230
+ var id = _a.id, _b = _a.amount, amount = _b === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _b;
230
231
  return __awaiter(this, void 0, void 0, function () {
231
232
  var result;
232
- return __generator(this, function (_a) {
233
- switch (_a.label) {
234
- case 0: return [4 /*yield*/, this.writeContract.withdraw(withdrawData.id, withdrawData.amount.toString())];
233
+ return __generator(this, function (_c) {
234
+ switch (_c.label) {
235
+ case 0: return [4 /*yield*/, this.writeContract.withdraw(id, amount.toString())];
235
236
  case 1:
236
- result = _a.sent();
237
+ result = _c.sent();
237
238
  return [2 /*return*/, {
238
239
  ixs: [],
239
240
  txId: result.hash,
@@ -1,5 +1,5 @@
1
- import { Connection, Commitment, ConnectionConfig } from "@solana/web3.js";
2
- import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "./types";
1
+ import { Connection, Keypair, PublicKey, TransactionInstruction, Commitment, ConnectionConfig } from "@solana/web3.js";
2
+ import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt, ITransactionSolanaExt } from "./types";
3
3
  import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetFeesData, IGetOneData, IFees, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream } from "../common/types";
4
4
  import { BaseStreamClient } from "../common/BaseStreamClient";
5
5
  export default class SolanaStreamClient extends BaseStreamClient {
@@ -11,12 +11,22 @@ export default class SolanaStreamClient extends BaseStreamClient {
11
11
  */
12
12
  constructor(clusterUrl: string, cluster?: ICluster, commitment?: Commitment | ConnectionConfig, programId?: string);
13
13
  getConnection(): Connection;
14
+ getCommitment(): Commitment | undefined;
14
15
  getProgramId(): string;
15
16
  /**
16
17
  * Creates a new stream/vesting contract.
17
18
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
18
19
  */
19
- create({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: ICreateStreamData, { sender, metadataPubKeys, isNative }: ICreateStreamSolanaExt): Promise<ICreateResult>;
20
+ create(data: ICreateStreamData, extParams: ICreateStreamSolanaExt): Promise<ICreateResult>;
21
+ /**
22
+ * Creates a new stream/vesting contract.
23
+ * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
24
+ */
25
+ prepareCreateInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: ICreateStreamData, { sender, metadataPubKeys, isNative, computePrice, computeLimit, }: ICreateStreamSolanaExt): Promise<{
26
+ ixs: TransactionInstruction[];
27
+ metadata: Keypair | undefined;
28
+ metadataPubKey: PublicKey;
29
+ }>;
20
30
  /**
21
31
  * Creates a new stream/vesting contract using unchecked instruction.
22
32
  *
@@ -27,29 +37,54 @@ export default class SolanaStreamClient extends BaseStreamClient {
27
37
  *
28
38
  * If you are not sure if you should use create or create_unchecked, go for create to be safer.
29
39
  */
30
- createUnchecked({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: ICreateStreamData, { sender, metadataPubKeys, isNative }: ICreateStreamSolanaExt): Promise<ICreateResult>;
40
+ createUnchecked(data: ICreateStreamData, extParams: ICreateStreamSolanaExt): Promise<ICreateResult>;
41
+ /**
42
+ * Create Transaction instructions for `createUnchecked`
43
+ */
44
+ prepareCreateUncheckedInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: ICreateStreamData, { sender, metadataPubKeys, isNative, computePrice, computeLimit, }: ICreateStreamSolanaExt): Promise<{
45
+ ixs: TransactionInstruction[];
46
+ metadata: Keypair | undefined;
47
+ metadataPubKey: PublicKey;
48
+ }>;
31
49
  /**
32
50
  * Creates multiple stream/vesting contracts.
33
51
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
34
52
  */
35
- createMultiple(data: ICreateMultipleStreamData, { sender, metadataPubKeys, isNative }: ICreateStreamSolanaExt): Promise<IMultiTransactionResult>;
53
+ createMultiple(data: ICreateMultipleStreamData, { sender, metadataPubKeys, isNative, computePrice, computeLimit, }: ICreateStreamSolanaExt): Promise<IMultiTransactionResult>;
36
54
  /**
37
55
  * Attempts withdrawing from the specified stream.
38
56
  */
39
- withdraw({ id, amount }: IWithdrawData, { invoker, checkTokenAccounts }: IInteractStreamSolanaExt): Promise<ITransactionResult>;
57
+ withdraw({ id, amount }: IWithdrawData, extParams: IInteractStreamSolanaExt): Promise<ITransactionResult>;
58
+ /**
59
+ * Creates Transaction Instructions for withdrawal
60
+ */
61
+ prepareWithdawInstructions({ id, amount }: IWithdrawData, { invoker, checkTokenAccounts, computePrice, computeLimit }: IInteractStreamSolanaExt): Promise<TransactionInstruction[]>;
40
62
  /**
41
63
  * Attempts canceling the specified stream.
42
64
  */
43
- cancel({ id }: ICancelData, { invoker, checkTokenAccounts }: IInteractStreamSolanaExt): Promise<ITransactionResult>;
65
+ cancel({ id }: ICancelData, extParams: IInteractStreamSolanaExt): Promise<ITransactionResult>;
66
+ /**
67
+ * Creates Transaction Instructions for cancel
68
+ */
69
+ prepareCancelInstructions({ id }: ICancelData, { invoker, checkTokenAccounts, computePrice, computeLimit }: IInteractStreamSolanaExt): Promise<TransactionInstruction[]>;
70
+ /**
71
+ * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
72
+ * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
73
+ */
74
+ transfer({ id, newRecipient }: ITransferData, extParams: IInteractStreamSolanaExt): Promise<ITransactionResult>;
44
75
  /**
45
76
  * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
46
77
  * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
47
78
  */
48
- transfer({ id, newRecipient: newRecipientString }: ITransferData, { invoker }: IInteractStreamSolanaExt): Promise<ITransactionResult>;
79
+ prepareTransferInstructions({ id, newRecipient }: ITransferData, { invoker, computePrice, computeLimit }: IInteractStreamSolanaExt): Promise<TransactionInstruction[]>;
49
80
  /**
50
81
  * Tops up stream account with specified amount.
51
82
  */
52
- topup({ id, amount }: ITopUpData, { invoker, isNative }: ITopUpStreamSolanaExt): Promise<ITransactionResult>;
83
+ topup({ id, amount }: ITopUpData, extParams: ITopUpStreamSolanaExt): Promise<ITransactionResult>;
84
+ /**
85
+ * Create Transaction instructions for topup
86
+ */
87
+ prepareTopupInstructions({ id, amount }: ITopUpData, { invoker, isNative, computePrice, computeLimit }: ITopUpStreamSolanaExt): Promise<TransactionInstruction[]>;
53
88
  /**
54
89
  * Fetch stream data by its id (address).
55
90
  */
@@ -62,7 +97,11 @@ export default class SolanaStreamClient extends BaseStreamClient {
62
97
  /**
63
98
  * Attempts updating the stream auto withdrawal params and amount per period
64
99
  */
65
- update(data: IUpdateData, { invoker }: IInteractStreamSolanaExt): Promise<ITransactionResult>;
100
+ update(data: IUpdateData, extParams: IInteractStreamSolanaExt): Promise<ITransactionResult>;
101
+ /**
102
+ * Create Transaction instructions for update
103
+ */
104
+ prepareUpdateInstructions(data: IUpdateData, { invoker, computePrice, computeLimit }: IInteractStreamSolanaExt): Promise<TransactionInstruction[]>;
66
105
  getFees({ address }: IGetFeesData): Promise<IFees | null>;
67
106
  getDefaultStreamflowFee(): Promise<number>;
68
107
  extractErrorCode(err: Error): string | null;
@@ -71,11 +110,17 @@ export default class SolanaStreamClient extends BaseStreamClient {
71
110
  */
72
111
  private prepareStreamInstructions;
73
112
  /**
74
- * Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
113
+ * Create Base instructions for Solana
114
+ * - sets compute price if `computePrice` is provided
115
+ * - sets compute limit if `computeLimit` is provided
75
116
  */
76
- private checkAssociatedTokenAccounts;
117
+ prepareBaseInstructions({ computePrice, computeLimit, }: ITransactionSolanaExt): TransactionInstruction[];
77
118
  /**
78
119
  * Utility function to generate metadata for a Contract or return existing Pubkey
79
120
  */
80
121
  private getOrCreateStreamMetadata;
122
+ /**
123
+ * Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
124
+ */
125
+ private checkAssociatedTokenAccounts;
81
126
  }