@streamflow/stream 6.0.0-alpha.1 → 6.0.0-alpha.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.
@@ -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
@@ -29,30 +29,25 @@ export type ICreateStreamData = IStreamConfig & IRecipient;
29
29
  export type ICreateMultipleStreamData = IStreamConfig & {
30
30
  recipients: IRecipient[];
31
31
  };
32
- export interface IWithdrawData {
32
+ export interface IInteractData {
33
33
  id: string;
34
- amount: BN;
35
34
  }
36
- export interface IUpdateData {
37
- id: string;
35
+ export interface IWithdrawData extends IInteractData {
36
+ amount?: BN;
37
+ }
38
+ export interface IUpdateData extends IInteractData {
38
39
  enableAutomaticWithdrawal?: boolean;
39
40
  withdrawFrequency?: BN;
40
41
  amountPerPeriod?: BN;
41
42
  }
42
- export interface ICancelData {
43
- id: string;
44
- }
45
- export interface ITransferData {
46
- id: string;
43
+ export type ICancelData = IInteractData;
44
+ export interface ITransferData extends IInteractData {
47
45
  newRecipient: string;
48
46
  }
49
- export interface ITopUpData {
50
- id: string;
47
+ export interface ITopUpData extends IInteractData {
51
48
  amount: BN;
52
49
  }
53
- export interface IGetOneData {
54
- id: string;
55
- }
50
+ export type IGetOneData = IInteractData;
56
51
  export interface IGetFeesData {
57
52
  address: string;
58
53
  }
@@ -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>;
@@ -227,14 +227,15 @@ var EvmStreamClient = /** @class */ (function (_super) {
227
227
  });
228
228
  });
229
229
  };
230
- EvmStreamClient.prototype.withdraw = function (withdrawData) {
230
+ EvmStreamClient.prototype.withdraw = function (_a) {
231
+ var id = _a.id, _b = _a.amount, amount = _b === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _b;
231
232
  return __awaiter(this, void 0, void 0, function () {
232
233
  var result;
233
- return __generator(this, function (_a) {
234
- switch (_a.label) {
235
- case 0: return [4 /*yield*/, this.writeContract.withdraw(withdrawData.id, withdrawData.amount.toString())];
234
+ return __generator(this, function (_c) {
235
+ switch (_c.label) {
236
+ case 0: return [4 /*yield*/, this.writeContract.withdraw(id, amount.toString())];
236
237
  case 1:
237
- result = _a.sent();
238
+ result = _c.sent();
238
239
  return [2 /*return*/, {
239
240
  ixs: [],
240
241
  txId: result.hash,
@@ -1,4 +1,4 @@
1
- import { Connection, Commitment, ConnectionConfig } from "@solana/web3.js";
1
+ import { Connection, Keypair, PublicKey, TransactionInstruction, Commitment, ConnectionConfig } from "@solana/web3.js";
2
2
  import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } 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";
@@ -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
+ prepareWithdrawInstructions({ 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;
@@ -70,12 +109,12 @@ export default class SolanaStreamClient extends BaseStreamClient {
70
109
  * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
71
110
  */
72
111
  private prepareStreamInstructions;
73
- /**
74
- * Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
75
- */
76
- private checkAssociatedTokenAccounts;
77
112
  /**
78
113
  * Utility function to generate metadata for a Contract or return existing Pubkey
79
114
  */
80
115
  private getOrCreateStreamMetadata;
116
+ /**
117
+ * Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
118
+ */
119
+ private checkAssociatedTokenAccounts;
81
120
  }