@streamflow/stream 4.0.3 → 4.1.0-beta.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.
@@ -139,7 +139,7 @@ describe("AptosStreamClient", function () {
139
139
  type: "create",
140
140
  type_arguments: ["0xtest::token::Token"],
141
141
  });
142
- expect(result).toEqual({ txId: mockReturn });
142
+ expect(result.txId).toEqual(mockReturn);
143
143
  return [2 /*return*/];
144
144
  }
145
145
  });
@@ -1,6 +1,6 @@
1
1
  import { BaseStreamClient } from "../common/BaseStreamClient";
2
- import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData } from "../common/types";
3
- import { Contract, ICreateStreamAptosExt, IMultiTransactionResult, ITransactionAptosExt, ITransactionResult } from "./types";
2
+ import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetOneData, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData } from "../common/types";
3
+ import { Contract, ICreateStreamAptosExt, ITransactionAptosExt } from "./types";
4
4
  export default class AptosStreamClient extends BaseStreamClient {
5
5
  private programId;
6
6
  private maxGas;
@@ -9,7 +9,7 @@ export default class AptosStreamClient extends BaseStreamClient {
9
9
  /**
10
10
  * Creates a new stream/vesting contract.
11
11
  */
12
- create(streamData: ICreateStreamData, { senderWallet }: ICreateStreamAptosExt): Promise<ITransactionResult>;
12
+ create(streamData: ICreateStreamData, { senderWallet }: ICreateStreamAptosExt): Promise<ICreateResult>;
13
13
  /**
14
14
  * Creates multiple stream/vesting contracts.
15
15
  */
@@ -34,6 +34,7 @@ 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
+ get(): Promise<[string, Contract][]>;
37
38
  /**
38
39
  * Attempts updating the stream auto withdrawal params and amount per period
39
40
  */
@@ -106,7 +106,7 @@ var AptosStreamClient = /** @class */ (function (_super) {
106
106
  return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
107
107
  case 1:
108
108
  hash = (_b.sent()).hash;
109
- return [2 /*return*/, { txId: hash }];
109
+ return [2 /*return*/, { ixs: [payload], txId: hash, metadataId: seeds }];
110
110
  }
111
111
  });
112
112
  });
@@ -185,7 +185,7 @@ var AptosStreamClient = /** @class */ (function (_super) {
185
185
  return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
186
186
  case 1:
187
187
  hash = (_b.sent()).hash;
188
- return [2 /*return*/, { txId: hash }];
188
+ return [2 /*return*/, { ixs: [payload], txId: hash }];
189
189
  }
190
190
  });
191
191
  });
@@ -209,7 +209,7 @@ var AptosStreamClient = /** @class */ (function (_super) {
209
209
  return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
210
210
  case 1:
211
211
  hash = (_b.sent()).hash;
212
- return [2 /*return*/, { txId: hash }];
212
+ return [2 /*return*/, { ixs: [payload], txId: hash }];
213
213
  }
214
214
  });
215
215
  });
@@ -233,7 +233,7 @@ var AptosStreamClient = /** @class */ (function (_super) {
233
233
  return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
234
234
  case 1:
235
235
  hash = (_b.sent()).hash;
236
- return [2 /*return*/, { txId: hash }];
236
+ return [2 /*return*/, { ixs: [payload], txId: hash }];
237
237
  }
238
238
  });
239
239
  });
@@ -257,7 +257,7 @@ var AptosStreamClient = /** @class */ (function (_super) {
257
257
  return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
258
258
  case 1:
259
259
  hash = (_b.sent()).hash;
260
- return [2 /*return*/, { txId: hash }];
260
+ return [2 /*return*/, { ixs: [payload], txId: hash }];
261
261
  }
262
262
  });
263
263
  });
@@ -287,6 +287,13 @@ var AptosStreamClient = /** @class */ (function (_super) {
287
287
  });
288
288
  });
289
289
  };
290
+ AptosStreamClient.prototype.get = function () {
291
+ return __awaiter(this, void 0, void 0, function () {
292
+ return __generator(this, function (_a) {
293
+ throw new Error("Get all method is not supported for Aptos chain!");
294
+ });
295
+ });
296
+ };
290
297
  /**
291
298
  * Attempts updating the stream auto withdrawal params and amount per period
292
299
  */
@@ -311,7 +318,7 @@ var AptosStreamClient = /** @class */ (function (_super) {
311
318
  return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
312
319
  case 1:
313
320
  hash = (_b.sent()).hash;
314
- return [2 /*return*/, { txId: hash }];
321
+ return [2 /*return*/, { ixs: [payload], txId: hash }];
315
322
  }
316
323
  });
317
324
  });
@@ -1,23 +1,8 @@
1
1
  import { WalletContextState } from "@manahippo/aptos-wallet-adapter";
2
2
  import BN from "bn.js";
3
- import { IRecipient } from "../common/types";
4
3
  export interface ICreateStreamAptosExt {
5
4
  senderWallet: WalletContextState;
6
5
  }
7
- declare type MetadataId = string;
8
- export interface CreateMultiError {
9
- recipient: string;
10
- error: string;
11
- }
12
- export interface IMultiTransactionResult {
13
- txs: string[];
14
- metadatas: MetadataId[];
15
- metadataToRecipient: Record<MetadataId, IRecipient>;
16
- errors: CreateMultiError[];
17
- }
18
- export interface ITransactionResult {
19
- txId: string;
20
- }
21
6
  export declare type ITransactionAptosExt = ICreateStreamAptosExt & {
22
7
  tokenId: string;
23
8
  };
@@ -142,4 +127,3 @@ export declare class Contract implements Stream {
142
127
  unlocked(currentTimestamp: number, decimals: number): number;
143
128
  remaining(decimals: number): number;
144
129
  }
145
- export {};
@@ -1,11 +1,13 @@
1
- import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData, IUpdateData } from "./types";
1
+ import { Stream } from "../solana";
2
+ import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData, IUpdateData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData } from "./types";
2
3
  export declare abstract class BaseStreamClient {
3
- protected abstract create(streamData: ICreateStreamData, chainSpecificParams: any): Promise<any>;
4
- protected abstract createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: any): Promise<any>;
5
- protected abstract withdraw(withdrawData: IWithdrawData, chainSpecificParams: any): Promise<any>;
6
- protected abstract cancel(cancelData: ICancelData, chainSpecificParams: any): Promise<any>;
7
- protected abstract transfer(transferData: ITransferData, chainSpecificParams: any): Promise<any>;
8
- protected abstract topup(topupData: ITopUpData, chainSpecificParams: any): Promise<any>;
9
- protected abstract getOne(getOneData: IGetOneData, chainSpecificParams: any): Promise<any>;
10
- protected abstract update(updateData: IUpdateData, chainSpecificParams: any): Promise<any>;
4
+ protected abstract create(streamData: ICreateStreamData, chainSpecificParams: any): Promise<ICreateResult>;
5
+ protected abstract createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: any): Promise<IMultiTransactionResult>;
6
+ protected abstract withdraw(withdrawData: IWithdrawData, chainSpecificParams: any): Promise<ITransactionResult>;
7
+ protected abstract cancel(cancelData: ICancelData, chainSpecificParams: any): Promise<ITransactionResult>;
8
+ protected abstract transfer(transferData: ITransferData, chainSpecificParams: any): Promise<ITransactionResult>;
9
+ protected abstract topup(topupData: ITopUpData, chainSpecificParams: any): Promise<ITransactionResult>;
10
+ protected abstract getOne(getOneData: IGetOneData, chainSpecificParams: any): Promise<Stream>;
11
+ protected abstract get(getAllData: IGetAllData, chainSpecificParams: any): Promise<[string, Stream][]>;
12
+ protected abstract update(updateData: IUpdateData, chainSpecificParams: any): Promise<ITransactionResult>;
11
13
  }
@@ -1,10 +1,12 @@
1
1
  import { Commitment, ConnectionConfig } from "@solana/web3.js";
2
+ import { Signer } from "ethers";
2
3
  import SolanaStreamClient from "../solana/StreamClient";
3
4
  import AptosStreamClient from "../aptos/StreamClient";
4
5
  import { BaseStreamClient } from "./BaseStreamClient";
5
- import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData } from "./types";
6
- import { CreateMultiResponse, CreateResponse, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt, Stream, TxResponse } from "../solana";
7
- import { ICreateStreamAptosExt, IMultiTransactionResult, ITransactionAptosExt, ITransactionResult } from "../aptos";
6
+ import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData } from "./types";
7
+ import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt, Stream } from "../solana";
8
+ import { ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos";
9
+ import { EvmStreamClient } from "../evm";
8
10
  export interface SolanaStreamClientOptions {
9
11
  chain: IChain.Solana;
10
12
  clusterUrl: string;
@@ -19,42 +21,53 @@ export interface AptosStreamClientOptions {
19
21
  programId?: string;
20
22
  maxGas?: string;
21
23
  }
22
- declare type GenericStreamClientOptions = SolanaStreamClientOptions | AptosStreamClientOptions;
24
+ export interface EvmStreamClientOptions {
25
+ chain: IChain.Etherium | IChain.BSC;
26
+ clusterUrl: string;
27
+ signer: Signer;
28
+ cluster?: ICluster;
29
+ programId?: string;
30
+ }
31
+ declare type GenericStreamClientOptions = SolanaStreamClientOptions | AptosStreamClientOptions | EvmStreamClientOptions;
23
32
  export default class GenericStreamClient extends BaseStreamClient {
24
- nativeStreamClient: SolanaStreamClient | AptosStreamClient;
33
+ nativeStreamClient: SolanaStreamClient | AptosStreamClient | EvmStreamClient;
25
34
  chain: IChain;
26
35
  constructor(options: GenericStreamClientOptions);
27
36
  /**
28
37
  * Creates a new stream/vesting contract.
29
38
  */
30
- create(streamData: ICreateStreamData, chainSpecificParams: ICreateStreamAptosExt | ICreateStreamSolanaExt): Promise<CreateResponse | ITransactionResult>;
39
+ create(streamData: ICreateStreamData, chainSpecificParams: ICreateStreamAptosExt | ICreateStreamSolanaExt): Promise<ICreateResult>;
31
40
  /**
32
41
  * Creates multiple stream/vesting contracts.
33
42
  */
34
- createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: ICreateStreamAptosExt | ICreateStreamSolanaExt): Promise<CreateMultiResponse | IMultiTransactionResult>;
43
+ createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: ICreateStreamAptosExt | ICreateStreamSolanaExt): Promise<IMultiTransactionResult>;
35
44
  /**
36
45
  * Attempts withdrawing from the specified stream.
37
46
  */
38
- withdraw(withdrawData: IWithdrawData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<TxResponse | ITransactionResult>;
47
+ withdraw(withdrawData: IWithdrawData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<ITransactionResult>;
39
48
  /**
40
49
  * Attempts canceling the specified stream.
41
50
  */
42
- cancel(cancelData: ICancelData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<TxResponse | ITransactionResult>;
51
+ cancel(cancelData: ICancelData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<ITransactionResult>;
43
52
  /**
44
53
  * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
45
54
  */
46
- transfer(transferData: ITransferData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<TxResponse | ITransactionResult>;
55
+ transfer(transferData: ITransferData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<ITransactionResult>;
47
56
  /**
48
57
  * Tops up stream account with specified amount.
49
58
  */
50
- topup(topupData: ITopUpData, chainSpecificParams: ITransactionAptosExt | ITopUpStreamSolanaExt): Promise<TxResponse | ITransactionResult>;
59
+ topup(topupData: ITopUpData, chainSpecificParams: ITransactionAptosExt | ITopUpStreamSolanaExt): Promise<ITransactionResult>;
51
60
  /**
52
61
  * Fetch stream data by its id (address).
53
62
  */
54
63
  getOne(getOneData: IGetOneData): Promise<Stream>;
64
+ /**
65
+ * Fetch streams by sender or recipient address.
66
+ */
67
+ get(getAllData: IGetAllData): Promise<[string, Stream][]>;
55
68
  /**
56
69
  * Attempts updating the stream auto withdrawal params and amount per period
57
70
  */
58
- update(updateData: IUpdateData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<TxResponse | ITransactionResult>;
71
+ update(updateData: IUpdateData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<ITransactionResult>;
59
72
  }
60
73
  export {};
@@ -22,16 +22,23 @@ var StreamClient_1 = __importDefault(require("../solana/StreamClient"));
22
22
  var StreamClient_2 = __importDefault(require("../aptos/StreamClient"));
23
23
  var BaseStreamClient_1 = require("./BaseStreamClient");
24
24
  var types_1 = require("./types");
25
+ var evm_1 = require("../evm");
25
26
  var GenericStreamClient = /** @class */ (function (_super) {
26
27
  __extends(GenericStreamClient, _super);
27
28
  function GenericStreamClient(options) {
28
29
  var _this = _super.call(this) || this;
29
30
  _this.chain = options.chain;
30
- if (options.chain === types_1.IChain.Solana) {
31
- _this.nativeStreamClient = new StreamClient_1.default(options.clusterUrl, options.cluster, options.commitment, options.programId);
32
- }
33
- else {
34
- _this.nativeStreamClient = new StreamClient_2.default(options.clusterUrl, options.cluster, options.maxGas, options.programId);
31
+ switch (options.chain) {
32
+ case types_1.IChain.Solana:
33
+ _this.nativeStreamClient = new StreamClient_1.default(options.clusterUrl, options.cluster, options.commitment, options.programId);
34
+ break;
35
+ case types_1.IChain.Aptos:
36
+ _this.nativeStreamClient = new StreamClient_2.default(options.clusterUrl, options.cluster, options.maxGas, options.programId);
37
+ break;
38
+ case types_1.IChain.BSC:
39
+ case types_1.IChain.Etherium:
40
+ _this.nativeStreamClient = new evm_1.EvmStreamClient(options.clusterUrl, options.chain, options.signer, options.cluster, options.programId);
41
+ break;
35
42
  }
36
43
  return _this;
37
44
  }
@@ -119,6 +126,12 @@ var GenericStreamClient = /** @class */ (function (_super) {
119
126
  GenericStreamClient.prototype.getOne = function (getOneData) {
120
127
  return this.nativeStreamClient.getOne(getOneData);
121
128
  };
129
+ /**
130
+ * Fetch streams by sender or recipient address.
131
+ */
132
+ GenericStreamClient.prototype.get = function (getAllData) {
133
+ return this.nativeStreamClient.get(getAllData);
134
+ };
122
135
  /**
123
136
  * Attempts updating the stream auto withdrawal params and amount per period
124
137
  */
@@ -1,3 +1,5 @@
1
+ import { TransactionInstruction } from "@solana/web3.js";
2
+ import { Types } from "aptos";
1
3
  import BN from "bn.js";
2
4
  export interface IRecipient {
3
5
  recipient: string;
@@ -49,6 +51,29 @@ export interface ITopUpData {
49
51
  export interface IGetOneData {
50
52
  id: string;
51
53
  }
54
+ export interface IGetAllData {
55
+ address: string;
56
+ type?: StreamType;
57
+ direction?: StreamDirection;
58
+ }
59
+ export interface ICreateMultiError {
60
+ recipient: string;
61
+ error: string;
62
+ }
63
+ declare type MetadataId = string;
64
+ export interface ITransactionResult {
65
+ ixs: (TransactionInstruction | Types.TransactionPayload)[];
66
+ txId: string;
67
+ }
68
+ export interface ICreateResult extends ITransactionResult {
69
+ metadataId: MetadataId;
70
+ }
71
+ export interface IMultiTransactionResult {
72
+ txs: string[];
73
+ metadatas: MetadataId[];
74
+ metadataToRecipient: Record<MetadataId, IRecipient>;
75
+ errors: ICreateMultiError[];
76
+ }
52
77
  export declare enum ICluster {
53
78
  Mainnet = "mainnet",
54
79
  Devnet = "devnet",
@@ -67,5 +92,8 @@ export declare enum StreamType {
67
92
  }
68
93
  export declare enum IChain {
69
94
  Solana = "Solana",
70
- Aptos = "Aptos"
95
+ Aptos = "Aptos",
96
+ Etherium = "Etherium",
97
+ BSC = "BSC"
71
98
  }
99
+ export {};
@@ -25,4 +25,6 @@ var IChain;
25
25
  (function (IChain) {
26
26
  IChain["Solana"] = "Solana";
27
27
  IChain["Aptos"] = "Aptos";
28
+ IChain["Etherium"] = "Etherium";
29
+ IChain["BSC"] = "BSC";
28
30
  })(IChain = exports.IChain || (exports.IChain = {}));
@@ -12,9 +12,12 @@ var bn_js_1 = __importDefault(require("bn.js"));
12
12
  * @param {number} decimals - Number of decimals the token has.
13
13
  */
14
14
  var getBN = function (value, decimals) {
15
- return value > (Math.pow(2, 53) - 1) / Math.pow(10, decimals)
16
- ? new bn_js_1.default(value).mul(new bn_js_1.default(Math.pow(10, decimals)))
17
- : new bn_js_1.default(value * Math.pow(10, decimals));
15
+ var decimalPart = value - Math.trunc(value);
16
+ var integerPart = new bn_js_1.default(Math.trunc(value));
17
+ var decimalE = new bn_js_1.default(decimalPart * 1e9);
18
+ var sum = integerPart.mul(new bn_js_1.default(1e9)).add(decimalE);
19
+ var resultE = sum.mul(new bn_js_1.default(10).pow(new bn_js_1.default(decimals)));
20
+ return resultE.div(new bn_js_1.default(1e9));
18
21
  };
19
22
  exports.getBN = getBN;
20
23
  /**
@@ -0,0 +1,27 @@
1
+ import { ethers } from "ethers";
2
+ import { BaseStreamClient } from "../common/BaseStreamClient";
3
+ import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetOneData, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData } from "../common/types";
4
+ import { Stream } from "../solana";
5
+ export default class EvmStreamClient extends BaseStreamClient {
6
+ private programId;
7
+ private provider;
8
+ private signer;
9
+ private readContract;
10
+ private writeContract;
11
+ constructor(clusterUrl: string, chain: IChain, signer: ethers.Signer, cluster?: ICluster, programId?: string);
12
+ create(streamData: ICreateStreamData): Promise<ICreateResult>;
13
+ createMultiple(multipleStreamData: ICreateMultipleStreamData): Promise<IMultiTransactionResult>;
14
+ withdraw(withdrawData: IWithdrawData): Promise<ITransactionResult>;
15
+ cancel(cancelData: ICancelData): Promise<ITransactionResult>;
16
+ transfer(transferData: ITransferData): Promise<ITransactionResult>;
17
+ topup(topupData: ITopUpData): Promise<ITransactionResult>;
18
+ update(updateData: IUpdateData): Promise<ITransactionResult>;
19
+ getOne({ id }: IGetOneData): Promise<Stream>;
20
+ get({ address, direction, }: IGetAllData): Promise<[string, Stream][]>;
21
+ /**
22
+ * Returns StreamClient protocol program ID.
23
+ */
24
+ getProgramId(): string;
25
+ private generateMultiPayloads;
26
+ private getFeeParams;
27
+ }