@streamflow/stream 5.6.0 → 5.6.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.
Files changed (74) hide show
  1. package/LICENSE +674 -0
  2. package/package.json +5 -6
  3. package/dist/__tests__/aptos/streamClient.spec.d.ts +0 -1
  4. package/dist/__tests__/aptos/streamClient.spec.js +0 -161
  5. package/dist/aptos/StreamClient.d.ts +0 -51
  6. package/dist/aptos/StreamClient.js +0 -387
  7. package/dist/aptos/constants.d.ts +0 -8
  8. package/dist/aptos/constants.js +0 -28
  9. package/dist/aptos/index.d.ts +0 -2
  10. package/dist/aptos/index.js +0 -24
  11. package/dist/aptos/types.d.ts +0 -97
  12. package/dist/aptos/types.js +0 -76
  13. package/dist/aptos/utils.d.ts +0 -1
  14. package/dist/aptos/utils.js +0 -12
  15. package/dist/aptos/wallet.d.ts +0 -9
  16. package/dist/aptos/wallet.js +0 -89
  17. package/dist/common/BaseStreamClient.d.ts +0 -13
  18. package/dist/common/BaseStreamClient.js +0 -13
  19. package/dist/common/GenericStreamClient.d.ts +0 -93
  20. package/dist/common/GenericStreamClient.js +0 -114
  21. package/dist/common/constants.d.ts +0 -1
  22. package/dist/common/constants.js +0 -4
  23. package/dist/common/contractUtils.d.ts +0 -47
  24. package/dist/common/contractUtils.js +0 -55
  25. package/dist/common/types.d.ts +0 -252
  26. package/dist/common/types.js +0 -165
  27. package/dist/common/utils.d.ts +0 -22
  28. package/dist/common/utils.js +0 -101
  29. package/dist/evm/StreamClient.d.ts +0 -30
  30. package/dist/evm/StreamClient.js +0 -461
  31. package/dist/evm/abi.d.ts +0 -111
  32. package/dist/evm/abi.js +0 -1257
  33. package/dist/evm/constants.d.ts +0 -20
  34. package/dist/evm/constants.js +0 -39
  35. package/dist/evm/ercAbi.d.ts +0 -39
  36. package/dist/evm/ercAbi.js +0 -224
  37. package/dist/evm/index.d.ts +0 -2
  38. package/dist/evm/index.js +0 -24
  39. package/dist/evm/types.d.ts +0 -93
  40. package/dist/evm/types.js +0 -75
  41. package/dist/evm/utils.d.ts +0 -1
  42. package/dist/evm/utils.js +0 -12
  43. package/dist/index.d.ts +0 -8
  44. package/dist/index.js +0 -41
  45. package/dist/solana/StreamClient.d.ts +0 -72
  46. package/dist/solana/StreamClient.js +0 -927
  47. package/dist/solana/constants.d.ts +0 -22
  48. package/dist/solana/constants.js +0 -50
  49. package/dist/solana/index.d.ts +0 -7
  50. package/dist/solana/index.js +0 -43
  51. package/dist/solana/instructionTypes.d.ts +0 -96
  52. package/dist/solana/instructionTypes.js +0 -2
  53. package/dist/solana/instructions.d.ts +0 -139
  54. package/dist/solana/instructions.js +0 -407
  55. package/dist/solana/layout.d.ts +0 -27
  56. package/dist/solana/layout.js +0 -170
  57. package/dist/solana/timelockIDL.d.ts +0 -22
  58. package/dist/solana/timelockIDL.js +0 -422
  59. package/dist/solana/types.d.ts +0 -292
  60. package/dist/solana/types.js +0 -81
  61. package/dist/solana/utils.d.ts +0 -44
  62. package/dist/solana/utils.js +0 -303
  63. package/dist/sui/StreamClient.d.ts +0 -79
  64. package/dist/sui/StreamClient.js +0 -571
  65. package/dist/sui/constants.d.ts +0 -10
  66. package/dist/sui/constants.js +0 -43
  67. package/dist/sui/index.d.ts +0 -2
  68. package/dist/sui/index.js +0 -23
  69. package/dist/sui/types.d.ts +0 -141
  70. package/dist/sui/types.js +0 -102
  71. package/dist/sui/utils.d.ts +0 -2
  72. package/dist/sui/utils.js +0 -29
  73. package/dist/sui/wallet.d.ts +0 -11
  74. package/dist/sui/wallet.js +0 -75
@@ -1,252 +0,0 @@
1
- import { TransactionInstruction } from "@solana/web3.js";
2
- import { Types } from "aptos";
3
- import BN from "bn.js";
4
- export interface IRecipient {
5
- recipient: string;
6
- amount: BN;
7
- name: string;
8
- cliffAmount: BN;
9
- amountPerPeriod: BN;
10
- }
11
- export interface IStreamConfig {
12
- period: number;
13
- start: number;
14
- cliff: number;
15
- cancelableBySender: boolean;
16
- cancelableByRecipient: boolean;
17
- transferableBySender: boolean;
18
- transferableByRecipient: boolean;
19
- canTopup: boolean;
20
- automaticWithdrawal?: boolean;
21
- withdrawalFrequency?: number;
22
- tokenId: string;
23
- canPause?: boolean;
24
- canUpdateRate?: boolean;
25
- partner?: string;
26
- }
27
- export declare type ICreateStreamData = IStreamConfig & IRecipient;
28
- export declare type ICreateMultipleStreamData = IStreamConfig & {
29
- recipients: IRecipient[];
30
- };
31
- export interface IWithdrawData {
32
- id: string;
33
- amount: BN;
34
- }
35
- export interface IUpdateData {
36
- id: string;
37
- enableAutomaticWithdrawal?: boolean;
38
- withdrawFrequency?: BN;
39
- amountPerPeriod?: BN;
40
- }
41
- export interface ICancelData {
42
- id: string;
43
- }
44
- export interface ITransferData {
45
- id: string;
46
- newRecipient: string;
47
- }
48
- export interface ITopUpData {
49
- id: string;
50
- amount: BN;
51
- }
52
- export interface IGetOneData {
53
- id: string;
54
- }
55
- export interface IGetAllData {
56
- address: string;
57
- type?: StreamType;
58
- direction?: StreamDirection;
59
- }
60
- export interface ICreateMultiError {
61
- recipient: string;
62
- error: string;
63
- contractErrorCode?: string;
64
- }
65
- declare type MetadataId = string;
66
- export interface ITransactionResult {
67
- ixs: (TransactionInstruction | Types.TransactionPayload)[];
68
- txId: string;
69
- }
70
- export interface ICreateResult extends ITransactionResult {
71
- metadataId: MetadataId;
72
- }
73
- export interface IMultiTransactionResult {
74
- txs: string[];
75
- metadatas: MetadataId[];
76
- metadataToRecipient: Record<MetadataId, IRecipient>;
77
- errors: ICreateMultiError[];
78
- }
79
- export declare enum ICluster {
80
- Mainnet = "mainnet",
81
- Devnet = "devnet",
82
- Testnet = "testnet",
83
- Local = "local"
84
- }
85
- export declare enum StreamDirection {
86
- Outgoing = "outgoing",
87
- Incoming = "incoming",
88
- All = "all"
89
- }
90
- export declare enum StreamType {
91
- All = "all",
92
- Payment = "payment",
93
- Vesting = "vesting",
94
- Lock = "lock"
95
- }
96
- export declare enum IChain {
97
- Solana = "Solana",
98
- Aptos = "Aptos",
99
- Ethereum = "Ethereum",
100
- BNB = "BNB",
101
- Polygon = "Polygon",
102
- Sui = "Sui"
103
- }
104
- /**
105
- * Error codes raised by all protocols except for Solana
106
- */
107
- export declare enum ContractErrorCode {
108
- /** Contract does not exist */
109
- ECONTRACT_NOT_INIT = "ECONTRACT_NOT_INIT",
110
- /** Invalid total amount */
111
- EBAD_AMOUNT = "EBAD_AMOUNT",
112
- /** No permissions to perform an operation */
113
- ENO_PERMISSIONS = "ENO_PERMISSIONS",
114
- /** Invalid input parameters on create/update */
115
- EBADINPUT = "EBADINPUT",
116
- /** Contract is already ended */
117
- ECLOSED = "ECLOSED",
118
- /** Invalid amount per period input */
119
- EBAD_INPUT_AMOUNT_PER_PERIOD = "EBAD_INPUT_AMOUNT_PER_PERIOD",
120
- /** Pause feature is not supported */
121
- EBAD_INPUT_PAUSABLE = "EBAD_INPUT_PAUSABLE",
122
- /** Not used currently */
123
- EBAD_INPUT_UPDATE_RATE = "EBAD_INPUT_UPDATE_RATE",
124
- /** Invalid cliff amount input */
125
- EBAD_INPUT_CLIFF_AMOUNT = "EBAD_INPUT_CLIFF_AMOUNT",
126
- /** Invalid period input */
127
- EBAD_INPUT_PERIOD = "EBAD_INPUT_PERIOD",
128
- /** Invalid start time of the contract */
129
- EBAD_INPUT_START = "EBAD_INPUT_START",
130
- /** EVM: token allowance is not enough to create a Contract */
131
- EBAD_INSUFFICIENT_TOKEN_ALLOWANCE = "EBAD_INSUFFICIENT_TOKEN_ALLOWANCE",
132
- /** EVM: not enough coins were passed for withdrawal fees */
133
- EBAD_INSUFFICIENT_WITHDRAWAL_FEES = "EBAD_INSUFFICIENT_WITHDRAWAL_FEES",
134
- /** Sui: Insufficient amount of tokens passed */
135
- EBAD_INSUFFICIENT_AMOUNT = "EBAD_INSUFFICIENT_AMOUNT",
136
- /** Contract is already paused */
137
- EPAUSED = "EPAUSED",
138
- /** Contract is not paused */
139
- ENOTPAUSED = "ENOTPAUSED",
140
- /** Aptos: user opt out from direct coin transfers feature and has not coin wallet registered */
141
- ENO_RECIPIENT_COIN_ADDRESS = "ENO_RECIPIENT_COIN_ADDRESS"
142
- }
143
- /**
144
- * Error codes raised by Solana protocol specifically
145
- */
146
- export declare enum SolanaContractErrorCode {
147
- /** Accounts not writable */
148
- AccountsNotWritable = "AccountsNotWritable",
149
- /** Invalid Metadata */
150
- InvalidMetadata = "InvalidMetadata",
151
- /** Invalid metadata account */
152
- InvalidMetadataAccount = "InvalidMetadataAccount",
153
- /** Provided accounts don't match the ones in contract */
154
- MetadataAccountMismatch = "MetadataAccountMismatch",
155
- /** Invalid escrow account */
156
- InvalidEscrowAccount = "InvalidEscrowAccount",
157
- /** Provided account(s) is/are not valid associated token accounts */
158
- NotAssociated = "NotAssociated",
159
- /** Sender mint does not match accounts mint */
160
- MintMismatch = "MintMismatch",
161
- /** Recipient not transferable for account */
162
- TransferNotAllowed = "TransferNotAllowed",
163
- /** Contract closed */
164
- ContractClosed = "ContractClosed",
165
- /** Invalid Streamflow Treasury accounts supplied */
166
- InvalidTreasury = "InvalidTreasury",
167
- /** Given timestamps are invalid */
168
- InvalidTimestamps = "InvalidTimestamps",
169
- /** Invalid deposit configuration */
170
- InvalidDepositConfiguration = "InvalidDepositConfiguration",
171
- /** Amount cannot be zero */
172
- AmountIsZero = "AmountIsZero",
173
- /** Amount requested is larger than available */
174
- AmountMoreThanAvailable = "AmountMoreThanAvailable",
175
- /** Amount currently available is zero */
176
- AmountAvailableIsZero = "AmountAvailableIsZero",
177
- /** Arithmetic error */
178
- ArithmeticError = "ArithmeticError",
179
- /** Metadata account data must be 1104 bytes long */
180
- InvalidMetadataSize = "InvalidMetadataSize",
181
- /** Metadata state account must be initialized */
182
- UninitializedMetadata = "UninitializedMetadata",
183
- /** Authority does not have permission for this action */
184
- Unauthorized = "Unauthorized",
185
- /** Contract is not transferable to the original recipient */
186
- SelfTransfer = "SelfTransfer",
187
- /** Contract is already paused */
188
- AlreadyPaused = "AlreadyPaused",
189
- /** Contract is not paused */
190
- NotPaused = "NotPaused",
191
- /** Meta account is not rent exempt */
192
- MetadataNotRentExempt = "MetadataNotRentExempt"
193
- }
194
- export interface Stream {
195
- magic: number;
196
- version: number;
197
- createdAt: number;
198
- withdrawnAmount: BN;
199
- canceledAt: number;
200
- end: number;
201
- lastWithdrawnAt: number;
202
- sender: string;
203
- senderTokens: string;
204
- recipient: string;
205
- recipientTokens: string;
206
- mint: string;
207
- escrowTokens: string;
208
- streamflowTreasury: string;
209
- streamflowTreasuryTokens: string;
210
- streamflowFeeTotal: BN;
211
- streamflowFeeWithdrawn: BN;
212
- streamflowFeePercent: number;
213
- partnerFeeTotal: BN;
214
- partnerFeeWithdrawn: BN;
215
- partnerFeePercent: number;
216
- partner: string;
217
- partnerTokens: string;
218
- start: number;
219
- depositedAmount: BN;
220
- period: number;
221
- amountPerPeriod: BN;
222
- cliff: number;
223
- cliffAmount: BN;
224
- cancelableBySender: boolean;
225
- cancelableByRecipient: boolean;
226
- automaticWithdrawal: boolean;
227
- transferableBySender: boolean;
228
- transferableByRecipient: boolean;
229
- canTopup: boolean;
230
- name: string;
231
- withdrawalFrequency: number;
232
- closed: boolean;
233
- currentPauseStart: number;
234
- pauseCumulative: BN;
235
- lastRateChangeTime: number;
236
- fundsUnlockedAtLastRateChange: BN;
237
- type: StreamType;
238
- unlocked(currentTimestamp: number): BN;
239
- }
240
- /**
241
- * Error wrapper for calls made to the contract on chain
242
- */
243
- export declare class ContractError extends Error {
244
- contractErrorCode: string | null;
245
- /**
246
- * Constructs the Error Wrapper
247
- * @param error Original error raised probably by the chain SDK
248
- * @param code extracted code from the error if managed to parse it
249
- */
250
- constructor(error: Error, code?: string | null);
251
- }
252
- export {};
@@ -1,165 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.ContractError = exports.SolanaContractErrorCode = exports.ContractErrorCode = exports.IChain = exports.StreamType = exports.StreamDirection = exports.ICluster = void 0;
19
- // Utility types
20
- var ICluster;
21
- (function (ICluster) {
22
- ICluster["Mainnet"] = "mainnet";
23
- ICluster["Devnet"] = "devnet";
24
- ICluster["Testnet"] = "testnet";
25
- ICluster["Local"] = "local";
26
- })(ICluster = exports.ICluster || (exports.ICluster = {}));
27
- var StreamDirection;
28
- (function (StreamDirection) {
29
- StreamDirection["Outgoing"] = "outgoing";
30
- StreamDirection["Incoming"] = "incoming";
31
- StreamDirection["All"] = "all";
32
- })(StreamDirection = exports.StreamDirection || (exports.StreamDirection = {}));
33
- var StreamType;
34
- (function (StreamType) {
35
- StreamType["All"] = "all";
36
- StreamType["Payment"] = "payment";
37
- StreamType["Vesting"] = "vesting";
38
- StreamType["Lock"] = "lock";
39
- })(StreamType = exports.StreamType || (exports.StreamType = {}));
40
- var IChain;
41
- (function (IChain) {
42
- IChain["Solana"] = "Solana";
43
- IChain["Aptos"] = "Aptos";
44
- IChain["Ethereum"] = "Ethereum";
45
- IChain["BNB"] = "BNB";
46
- IChain["Polygon"] = "Polygon";
47
- IChain["Sui"] = "Sui";
48
- })(IChain = exports.IChain || (exports.IChain = {}));
49
- /**
50
- * Error codes raised by all protocols except for Solana
51
- */
52
- var ContractErrorCode;
53
- (function (ContractErrorCode) {
54
- /** Contract does not exist */
55
- ContractErrorCode["ECONTRACT_NOT_INIT"] = "ECONTRACT_NOT_INIT";
56
- /** Invalid total amount */
57
- ContractErrorCode["EBAD_AMOUNT"] = "EBAD_AMOUNT";
58
- /** No permissions to perform an operation */
59
- ContractErrorCode["ENO_PERMISSIONS"] = "ENO_PERMISSIONS";
60
- /** Invalid input parameters on create/update */
61
- ContractErrorCode["EBADINPUT"] = "EBADINPUT";
62
- /** Contract is already ended */
63
- ContractErrorCode["ECLOSED"] = "ECLOSED";
64
- /** Invalid amount per period input */
65
- ContractErrorCode["EBAD_INPUT_AMOUNT_PER_PERIOD"] = "EBAD_INPUT_AMOUNT_PER_PERIOD";
66
- /** Pause feature is not supported */
67
- ContractErrorCode["EBAD_INPUT_PAUSABLE"] = "EBAD_INPUT_PAUSABLE";
68
- /** Not used currently */
69
- ContractErrorCode["EBAD_INPUT_UPDATE_RATE"] = "EBAD_INPUT_UPDATE_RATE";
70
- /** Invalid cliff amount input */
71
- ContractErrorCode["EBAD_INPUT_CLIFF_AMOUNT"] = "EBAD_INPUT_CLIFF_AMOUNT";
72
- /** Invalid period input */
73
- ContractErrorCode["EBAD_INPUT_PERIOD"] = "EBAD_INPUT_PERIOD";
74
- /** Invalid start time of the contract */
75
- ContractErrorCode["EBAD_INPUT_START"] = "EBAD_INPUT_START";
76
- /** EVM: token allowance is not enough to create a Contract */
77
- ContractErrorCode["EBAD_INSUFFICIENT_TOKEN_ALLOWANCE"] = "EBAD_INSUFFICIENT_TOKEN_ALLOWANCE";
78
- /** EVM: not enough coins were passed for withdrawal fees */
79
- ContractErrorCode["EBAD_INSUFFICIENT_WITHDRAWAL_FEES"] = "EBAD_INSUFFICIENT_WITHDRAWAL_FEES";
80
- /** Sui: Insufficient amount of tokens passed */
81
- ContractErrorCode["EBAD_INSUFFICIENT_AMOUNT"] = "EBAD_INSUFFICIENT_AMOUNT";
82
- /** Contract is already paused */
83
- ContractErrorCode["EPAUSED"] = "EPAUSED";
84
- /** Contract is not paused */
85
- ContractErrorCode["ENOTPAUSED"] = "ENOTPAUSED";
86
- /** Aptos: user opt out from direct coin transfers feature and has not coin wallet registered */
87
- ContractErrorCode["ENO_RECIPIENT_COIN_ADDRESS"] = "ENO_RECIPIENT_COIN_ADDRESS";
88
- })(ContractErrorCode = exports.ContractErrorCode || (exports.ContractErrorCode = {}));
89
- /**
90
- * Error codes raised by Solana protocol specifically
91
- */
92
- var SolanaContractErrorCode;
93
- (function (SolanaContractErrorCode) {
94
- /** Accounts not writable */
95
- SolanaContractErrorCode["AccountsNotWritable"] = "AccountsNotWritable";
96
- /** Invalid Metadata */
97
- SolanaContractErrorCode["InvalidMetadata"] = "InvalidMetadata";
98
- /** Invalid metadata account */
99
- SolanaContractErrorCode["InvalidMetadataAccount"] = "InvalidMetadataAccount";
100
- /** Provided accounts don't match the ones in contract */
101
- SolanaContractErrorCode["MetadataAccountMismatch"] = "MetadataAccountMismatch";
102
- /** Invalid escrow account */
103
- SolanaContractErrorCode["InvalidEscrowAccount"] = "InvalidEscrowAccount";
104
- /** Provided account(s) is/are not valid associated token accounts */
105
- SolanaContractErrorCode["NotAssociated"] = "NotAssociated";
106
- /** Sender mint does not match accounts mint */
107
- SolanaContractErrorCode["MintMismatch"] = "MintMismatch";
108
- /** Recipient not transferable for account */
109
- SolanaContractErrorCode["TransferNotAllowed"] = "TransferNotAllowed";
110
- /** Contract closed */
111
- SolanaContractErrorCode["ContractClosed"] = "ContractClosed";
112
- /** Invalid Streamflow Treasury accounts supplied */
113
- SolanaContractErrorCode["InvalidTreasury"] = "InvalidTreasury";
114
- /** Given timestamps are invalid */
115
- SolanaContractErrorCode["InvalidTimestamps"] = "InvalidTimestamps";
116
- /** Invalid deposit configuration */
117
- SolanaContractErrorCode["InvalidDepositConfiguration"] = "InvalidDepositConfiguration";
118
- /** Amount cannot be zero */
119
- SolanaContractErrorCode["AmountIsZero"] = "AmountIsZero";
120
- /** Amount requested is larger than available */
121
- SolanaContractErrorCode["AmountMoreThanAvailable"] = "AmountMoreThanAvailable";
122
- /** Amount currently available is zero */
123
- SolanaContractErrorCode["AmountAvailableIsZero"] = "AmountAvailableIsZero";
124
- /** Arithmetic error */
125
- SolanaContractErrorCode["ArithmeticError"] = "ArithmeticError";
126
- /** Metadata account data must be 1104 bytes long */
127
- SolanaContractErrorCode["InvalidMetadataSize"] = "InvalidMetadataSize";
128
- /** Metadata state account must be initialized */
129
- SolanaContractErrorCode["UninitializedMetadata"] = "UninitializedMetadata";
130
- /** Authority does not have permission for this action */
131
- SolanaContractErrorCode["Unauthorized"] = "Unauthorized";
132
- /** Contract is not transferable to the original recipient */
133
- SolanaContractErrorCode["SelfTransfer"] = "SelfTransfer";
134
- /** Contract is already paused */
135
- SolanaContractErrorCode["AlreadyPaused"] = "AlreadyPaused";
136
- /** Contract is not paused */
137
- SolanaContractErrorCode["NotPaused"] = "NotPaused";
138
- /** Meta account is not rent exempt */
139
- SolanaContractErrorCode["MetadataNotRentExempt"] = "MetadataNotRentExempt";
140
- })(SolanaContractErrorCode = exports.SolanaContractErrorCode || (exports.SolanaContractErrorCode = {}));
141
- /**
142
- * Error wrapper for calls made to the contract on chain
143
- */
144
- var ContractError = /** @class */ (function (_super) {
145
- __extends(ContractError, _super);
146
- /**
147
- * Constructs the Error Wrapper
148
- * @param error Original error raised probably by the chain SDK
149
- * @param code extracted code from the error if managed to parse it
150
- */
151
- function ContractError(error, code) {
152
- var _this = _super.call(this, error.message) || this;
153
- _this.name = "ContractError"; // Set the name property
154
- _this.contractErrorCode = code !== null && code !== void 0 ? code : null;
155
- // Copy properties from the original error
156
- Object.getOwnPropertyNames(error).forEach(function (key) {
157
- _this[key] = error[key];
158
- });
159
- // If you want to capture the stack trace:
160
- _this.stack = error.stack;
161
- return _this;
162
- }
163
- return ContractError;
164
- }(Error));
165
- exports.ContractError = ContractError;
@@ -1,22 +0,0 @@
1
- import BN from "bn.js";
2
- /**
3
- * Used for conversion of token amounts to their Big Number representation.
4
- * Get Big Number representation in the smallest units from the same value in the highest units.
5
- * @param {number} value - Number of tokens you want to convert to its BN representation.
6
- * @param {number} decimals - Number of decimals the token has.
7
- */
8
- export declare const getBN: (value: number, decimals: number) => BN;
9
- /**
10
- * Used for token amounts conversion from their Big Number representation to number.
11
- * Get value in the highest units from BN representation of the same value in the smallest units.
12
- * @param {BN} value - Big Number representation of value in the smallest units.
13
- * @param {number} decimals - Number of decimals the token has.
14
- */
15
- export declare const getNumberFromBN: (value: BN, decimals: number) => number;
16
- /**
17
- * Used to make on chain calls to the contract and wrap raised errors if any
18
- * @param func function that interacts with the contract
19
- * @param callback callback that may be used to extract error code
20
- * @returns {T}
21
- */
22
- export declare function handleContractError<T>(func: () => Promise<T>, callback?: (err: Error) => string | null): Promise<T>;
@@ -1,101 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.handleContractError = exports.getNumberFromBN = exports.getBN = void 0;
43
- var bn_js_1 = __importDefault(require("bn.js"));
44
- var types_1 = require("./types");
45
- /**
46
- * Used for conversion of token amounts to their Big Number representation.
47
- * Get Big Number representation in the smallest units from the same value in the highest units.
48
- * @param {number} value - Number of tokens you want to convert to its BN representation.
49
- * @param {number} decimals - Number of decimals the token has.
50
- */
51
- var getBN = function (value, decimals) {
52
- var decimalPart = value - Math.trunc(value);
53
- var integerPart = new bn_js_1.default(Math.trunc(value));
54
- var decimalE = new bn_js_1.default(decimalPart * 1e9);
55
- var sum = integerPart.mul(new bn_js_1.default(1e9)).add(decimalE);
56
- var resultE = sum.mul(new bn_js_1.default(10).pow(new bn_js_1.default(decimals)));
57
- return resultE.div(new bn_js_1.default(1e9));
58
- };
59
- exports.getBN = getBN;
60
- /**
61
- * Used for token amounts conversion from their Big Number representation to number.
62
- * Get value in the highest units from BN representation of the same value in the smallest units.
63
- * @param {BN} value - Big Number representation of value in the smallest units.
64
- * @param {number} decimals - Number of decimals the token has.
65
- */
66
- var getNumberFromBN = function (value, decimals) {
67
- return value.gt(new bn_js_1.default(Math.pow(2, 53) - 1))
68
- ? value.div(new bn_js_1.default(Math.pow(10, decimals))).toNumber()
69
- : value.toNumber() / Math.pow(10, decimals);
70
- };
71
- exports.getNumberFromBN = getNumberFromBN;
72
- /**
73
- * Used to make on chain calls to the contract and wrap raised errors if any
74
- * @param func function that interacts with the contract
75
- * @param callback callback that may be used to extract error code
76
- * @returns {T}
77
- */
78
- function handleContractError(func, callback) {
79
- return __awaiter(this, void 0, void 0, function () {
80
- var err_1;
81
- return __generator(this, function (_a) {
82
- switch (_a.label) {
83
- case 0:
84
- _a.trys.push([0, 2, , 3]);
85
- return [4 /*yield*/, func()];
86
- case 1: return [2 /*return*/, _a.sent()];
87
- case 2:
88
- err_1 = _a.sent();
89
- if (err_1 instanceof Error) {
90
- if (callback) {
91
- throw new types_1.ContractError(err_1, callback(err_1));
92
- }
93
- throw new types_1.ContractError(err_1);
94
- }
95
- throw err_1;
96
- case 3: return [2 /*return*/];
97
- }
98
- });
99
- });
100
- }
101
- exports.handleContractError = handleContractError;
@@ -1,30 +0,0 @@
1
- import { ethers } from "ethers";
2
- import BN from "bn.js";
3
- import { BaseStreamClient } from "../common/BaseStreamClient";
4
- import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetOneData, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream } from "../common/types";
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
- extractErrorCode(err: Error): string | null;
22
- /**
23
- * Returns StreamClient protocol program ID.
24
- */
25
- getProgramId(): string;
26
- approveTokens(tokenId: string, amount: BN): Promise<void>;
27
- private generateMultiPayloads;
28
- private getFeeParams;
29
- private formatMetadataId;
30
- }