@streamflow/stream 7.5.3 → 8.0.0-alpha.p287.25d0c28
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/cjs/BaseStreamClient-CQOC8m8V.d.cts +542 -0
- package/dist/cjs/aptos/index.cjs +456 -0
- package/dist/cjs/aptos/index.cjs.map +1 -0
- package/dist/cjs/aptos/index.d.cts +14 -0
- package/dist/cjs/evm/index.cjs +1915 -0
- package/dist/cjs/evm/index.cjs.map +1 -0
- package/dist/cjs/evm/index.d.cts +13 -0
- package/dist/cjs/index-CYu6i--S.d.cts +136 -0
- package/dist/cjs/index-DUVcpIhD.d.cts +203 -0
- package/dist/cjs/index-b7Qo5mCj.d.cts +664 -0
- package/dist/cjs/index-fNLnPKzv.d.cts +213 -0
- package/dist/cjs/index.cjs +7189 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +192 -0
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.cjs +4 -0
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.cjs.map +1 -0
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.d.cts +1234 -0
- package/dist/cjs/solana/index.cjs +3749 -0
- package/dist/cjs/solana/index.cjs.map +1 -0
- package/dist/cjs/solana/index.d.cts +17 -0
- package/dist/cjs/sui/index.cjs +1021 -0
- package/dist/cjs/sui/index.cjs.map +1 -0
- package/dist/cjs/sui/index.d.cts +13 -0
- package/dist/esm/BaseStreamClient-CQOC8m8V.d.ts +542 -0
- package/dist/esm/aptos/index.d.ts +14 -4
- package/dist/esm/aptos/index.js +443 -4
- package/dist/esm/aptos/index.js.map +1 -0
- package/dist/esm/evm/index.d.ts +13 -5
- package/dist/esm/evm/index.js +1902 -5
- package/dist/esm/evm/index.js.map +1 -0
- package/dist/esm/index-BEo0O2IG.d.ts +664 -0
- package/dist/esm/index-CWmb3-x9.d.ts +136 -0
- package/dist/esm/index-Cgv37xlG.d.ts +213 -0
- package/dist/esm/index-D6QYg8hn.d.ts +203 -0
- package/dist/esm/index.d.ts +192 -10
- package/dist/esm/index.js +7096 -10
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/solana/descriptor/idl/streamflow_aligned_unlocks.json +917 -1368
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.d.ts +3 -1
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js +3 -1
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js.map +1 -0
- package/dist/esm/solana/index.d.ts +17 -7
- package/dist/esm/solana/index.js +3693 -7
- package/dist/esm/solana/index.js.map +1 -0
- package/dist/esm/sui/index.d.ts +13 -4
- package/dist/esm/sui/index.js +1011 -4
- package/dist/esm/sui/index.js.map +1 -0
- package/package.json +57 -27
- package/dist/cjs/__tests__/aptos/streamClient.spec.js +0 -111
- package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +0 -45
- package/dist/cjs/aptos/StreamClient.js +0 -226
- package/dist/cjs/aptos/constants.js +0 -27
- package/dist/cjs/aptos/index.js +0 -38
- package/dist/cjs/aptos/types.js +0 -69
- package/dist/cjs/aptos/utils.js +0 -34
- package/dist/cjs/aptos/wallet.js +0 -34
- package/dist/cjs/common/BaseStreamClient.js +0 -23
- package/dist/cjs/common/GenericStreamClient.js +0 -102
- package/dist/cjs/common/constants.js +0 -10
- package/dist/cjs/common/contractUtils.js +0 -77
- package/dist/cjs/common/types.js +0 -141
- package/dist/cjs/common/utils.js +0 -69
- package/dist/cjs/evm/StreamClient.js +0 -238
- package/dist/cjs/evm/abi.js +0 -1257
- package/dist/cjs/evm/constants.js +0 -38
- package/dist/cjs/evm/ercAbi.js +0 -224
- package/dist/cjs/evm/index.js +0 -40
- package/dist/cjs/evm/types.js +0 -66
- package/dist/cjs/evm/utils.js +0 -11
- package/dist/cjs/index.js +0 -43
- package/dist/cjs/solana/StreamClient.js +0 -1042
- package/dist/cjs/solana/constants.js +0 -95
- package/dist/cjs/solana/descriptor/idl/streamflow_aligned_unlocks.json +0 -1437
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.js +0 -2
- package/dist/cjs/solana/index.js +0 -40
- package/dist/cjs/solana/instructionTypes.js +0 -2
- package/dist/cjs/solana/instructions.js +0 -298
- package/dist/cjs/solana/layout.js +0 -182
- package/dist/cjs/solana/lib/derive-accounts.js +0 -17
- package/dist/cjs/solana/lib/utils.js +0 -127
- package/dist/cjs/solana/timelockIDL.js +0 -422
- package/dist/cjs/solana/types.js +0 -93
- package/dist/cjs/sui/StreamClient.js +0 -416
- package/dist/cjs/sui/constants.js +0 -42
- package/dist/cjs/sui/index.js +0 -37
- package/dist/cjs/sui/types.js +0 -68
- package/dist/cjs/sui/utils.js +0 -46
- package/dist/cjs/sui/wallet.js +0 -40
- package/dist/esm/__tests__/aptos/streamClient.spec.d.ts +0 -1
- package/dist/esm/__tests__/aptos/streamClient.spec.js +0 -106
- package/dist/esm/__tests__/common/GenericStreamClient.spec.d.ts +0 -1
- package/dist/esm/__tests__/common/GenericStreamClient.spec.js +0 -40
- package/dist/esm/aptos/StreamClient.d.ts +0 -53
- package/dist/esm/aptos/StreamClient.js +0 -226
- package/dist/esm/aptos/constants.d.ts +0 -8
- package/dist/esm/aptos/constants.js +0 -24
- package/dist/esm/aptos/types.d.ts +0 -109
- package/dist/esm/aptos/types.js +0 -105
- package/dist/esm/aptos/utils.d.ts +0 -7
- package/dist/esm/aptos/utils.js +0 -30
- package/dist/esm/aptos/wallet.d.ts +0 -9
- package/dist/esm/aptos/wallet.js +0 -33
- package/dist/esm/common/BaseStreamClient.d.ts +0 -22
- package/dist/esm/common/BaseStreamClient.js +0 -19
- package/dist/esm/common/GenericStreamClient.d.ts +0 -72
- package/dist/esm/common/GenericStreamClient.js +0 -101
- package/dist/esm/common/constants.d.ts +0 -4
- package/dist/esm/common/constants.js +0 -4
- package/dist/esm/common/contractUtils.d.ts +0 -63
- package/dist/esm/common/contractUtils.js +0 -61
- package/dist/esm/common/types.d.ts +0 -353
- package/dist/esm/common/types.js +0 -135
- package/dist/esm/common/utils.d.ts +0 -32
- package/dist/esm/common/utils.js +0 -59
- package/dist/esm/evm/StreamClient.d.ts +0 -32
- package/dist/esm/evm/StreamClient.js +0 -237
- package/dist/esm/evm/abi.d.ts +0 -111
- package/dist/esm/evm/abi.js +0 -1255
- package/dist/esm/evm/constants.d.ts +0 -20
- package/dist/esm/evm/constants.js +0 -35
- package/dist/esm/evm/ercAbi.d.ts +0 -39
- package/dist/esm/evm/ercAbi.js +0 -222
- package/dist/esm/evm/types.d.ts +0 -98
- package/dist/esm/evm/types.js +0 -102
- package/dist/esm/evm/utils.d.ts +0 -1
- package/dist/esm/evm/utils.js +0 -8
- package/dist/esm/solana/StreamClient.d.ts +0 -150
- package/dist/esm/solana/StreamClient.js +0 -1017
- package/dist/esm/solana/constants.d.ts +0 -70
- package/dist/esm/solana/constants.js +0 -92
- package/dist/esm/solana/instructionTypes.d.ts +0 -101
- package/dist/esm/solana/instructionTypes.js +0 -1
- package/dist/esm/solana/instructions.d.ts +0 -142
- package/dist/esm/solana/instructions.js +0 -265
- package/dist/esm/solana/layout.d.ts +0 -27
- package/dist/esm/solana/layout.js +0 -155
- package/dist/esm/solana/lib/derive-accounts.d.ts +0 -4
- package/dist/esm/solana/lib/derive-accounts.js +0 -11
- package/dist/esm/solana/lib/utils.d.ts +0 -22
- package/dist/esm/solana/lib/utils.js +0 -117
- package/dist/esm/solana/timelockIDL.d.ts +0 -22
- package/dist/esm/solana/timelockIDL.js +0 -420
- package/dist/esm/solana/types.d.ts +0 -180
- package/dist/esm/solana/types.js +0 -142
- package/dist/esm/sui/StreamClient.d.ts +0 -82
- package/dist/esm/sui/StreamClient.js +0 -417
- package/dist/esm/sui/constants.d.ts +0 -10
- package/dist/esm/sui/constants.js +0 -39
- package/dist/esm/sui/types.d.ts +0 -167
- package/dist/esm/sui/types.js +0 -104
- package/dist/esm/sui/utils.d.ts +0 -11
- package/dist/esm/sui/utils.js +0 -39
- package/dist/esm/sui/wallet.d.ts +0 -17
- package/dist/esm/sui/wallet.js +0 -38
package/dist/esm/aptos/utils.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { APTOS_ERROR_MATCH_REGEX } from "./constants.js";
|
|
2
|
-
export function extractAptosErrorCode(errorText) {
|
|
3
|
-
const match = APTOS_ERROR_MATCH_REGEX.exec(errorText);
|
|
4
|
-
if (!match) {
|
|
5
|
-
return null;
|
|
6
|
-
}
|
|
7
|
-
return match[2];
|
|
8
|
-
}
|
|
9
|
-
function isAddressSpecial(address) {
|
|
10
|
-
if (address.length === 3) {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Aptos has inconsistencies in how it returns addresses.
|
|
17
|
-
* This method normalizes them to be 64+2(0x...) characters long, or leaves it as SPECIAL ADDRESS (0x0 - 0xf inclusive)
|
|
18
|
-
* Per this: https://github.com/aptos-labs/aptos-ts-sdk/blob/main/src/core/accountAddress.ts#L115
|
|
19
|
-
* */
|
|
20
|
-
export function normalizeAptosAddress(address) {
|
|
21
|
-
if (isAddressSpecial(address)) {
|
|
22
|
-
return address;
|
|
23
|
-
}
|
|
24
|
-
const length = address.length;
|
|
25
|
-
if (length === 66 || length < 3) {
|
|
26
|
-
return address;
|
|
27
|
-
}
|
|
28
|
-
const missingZeros = 66 - length;
|
|
29
|
-
return address.slice(0, 2) + "0".repeat(missingZeros) + address.slice(2);
|
|
30
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AptosAccount, AptosClient, Types, MaybeHexString } from "aptos";
|
|
2
|
-
import { WalletContextState } from "@manahippo/aptos-wallet-adapter";
|
|
3
|
-
export declare class AptosWalletWrapper<T extends WalletContextState | AptosAccount> {
|
|
4
|
-
wallet: T;
|
|
5
|
-
address: MaybeHexString;
|
|
6
|
-
client: AptosClient;
|
|
7
|
-
constructor(wallet: T, client: AptosClient);
|
|
8
|
-
signAndSubmitTransaction(input: Types.TransactionPayload_EntryFunctionPayload): Promise<string>;
|
|
9
|
-
}
|
package/dist/esm/aptos/wallet.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { AptosAccount, TransactionBuilderRemoteABI } from "aptos";
|
|
2
|
-
export class AptosWalletWrapper {
|
|
3
|
-
wallet;
|
|
4
|
-
address;
|
|
5
|
-
client;
|
|
6
|
-
constructor(wallet, client) {
|
|
7
|
-
this.client = client;
|
|
8
|
-
this.wallet = wallet;
|
|
9
|
-
if (wallet instanceof AptosAccount) {
|
|
10
|
-
this.address = wallet.address();
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
this.address = wallet.account.address;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async signAndSubmitTransaction(input) {
|
|
17
|
-
if (this.wallet instanceof AptosAccount) {
|
|
18
|
-
const builder = new TransactionBuilderRemoteABI(this.client, {
|
|
19
|
-
sender: this.address,
|
|
20
|
-
});
|
|
21
|
-
const rawTxn = await builder.build(input.function, input.type_arguments, input.arguments);
|
|
22
|
-
const res = await this.client.simulateTransaction(this.wallet, rawTxn);
|
|
23
|
-
if (!res[0].success) {
|
|
24
|
-
throw new Error(`Transaction Simulation failed: ${JSON.stringify(res)}`);
|
|
25
|
-
}
|
|
26
|
-
const signedTx = await this.client.signTransaction(this.wallet, rawTxn);
|
|
27
|
-
const tx = await this.client.submitSignedBCSTransaction(signedTx);
|
|
28
|
-
await this.client.waitForTransaction(tx.hash);
|
|
29
|
-
return tx.hash;
|
|
30
|
-
}
|
|
31
|
-
return (await this.wallet.signAndSubmitTransaction(input)).hash;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ICancelData, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IFees, IGetAllData, IGetFeesData, IGetOneData, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream } from "./types.js";
|
|
2
|
-
export declare abstract class BaseStreamClient {
|
|
3
|
-
abstract create(streamData: ICreateStreamData, chainSpecificParams: any): Promise<ICreateResult>;
|
|
4
|
-
abstract createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: any): Promise<IMultiTransactionResult>;
|
|
5
|
-
abstract withdraw(withdrawData: IWithdrawData, chainSpecificParams: any): Promise<ITransactionResult>;
|
|
6
|
-
abstract cancel(cancelData: ICancelData, chainSpecificParams: any): Promise<ITransactionResult>;
|
|
7
|
-
abstract transfer(transferData: ITransferData, chainSpecificParams: any): Promise<ITransactionResult>;
|
|
8
|
-
abstract topup(topupData: ITopUpData, chainSpecificParams: any): Promise<ITransactionResult>;
|
|
9
|
-
abstract getOne(getOneData: IGetOneData, chainSpecificParams: any): Promise<Stream>;
|
|
10
|
-
abstract get(getAllData: IGetAllData, chainSpecificParams: any): Promise<[string, Stream][]>;
|
|
11
|
-
abstract update(updateData: IUpdateData, chainSpecificParams: any): Promise<ITransactionResult>;
|
|
12
|
-
abstract getFees(getFeesData: IGetFeesData, chainSpecificParams?: any): Promise<IFees | null>;
|
|
13
|
-
abstract getDefaultStreamflowFee(chainSpecificParams?: any): Promise<number>;
|
|
14
|
-
/**
|
|
15
|
-
* Returns total fee percent, streamflow fees + partner fees
|
|
16
|
-
* @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
|
|
17
|
-
* @param chainSpecificParams additional parameters required by chain client
|
|
18
|
-
* @returns fee as floating number, so if fee is 0.99%, it will return 0.99
|
|
19
|
-
*/
|
|
20
|
-
getTotalFee(getFeesData: IGetFeesData, chainSpecificParams?: any): Promise<number>;
|
|
21
|
-
extractErrorCode(err: Error): string | null;
|
|
22
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export class BaseStreamClient {
|
|
2
|
-
/**
|
|
3
|
-
* Returns total fee percent, streamflow fees + partner fees
|
|
4
|
-
* @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
|
|
5
|
-
* @param chainSpecificParams additional parameters required by chain client
|
|
6
|
-
* @returns fee as floating number, so if fee is 0.99%, it will return 0.99
|
|
7
|
-
*/
|
|
8
|
-
async getTotalFee(getFeesData, chainSpecificParams) {
|
|
9
|
-
const fees = await this.getFees(getFeesData, chainSpecificParams);
|
|
10
|
-
if (fees) {
|
|
11
|
-
return fees.partnerFee + fees.streamflowFee;
|
|
12
|
-
}
|
|
13
|
-
return this.getDefaultStreamflowFee(chainSpecificParams);
|
|
14
|
-
}
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
-
extractErrorCode(err) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { BaseStreamClient } from "./BaseStreamClient.js";
|
|
2
|
-
import { ICancelData, IChain, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData, Stream, IFees, IGetFeesData, AptosStreamClientOptions, SuiStreamClientOptions, EvmStreamClientOptions, SolanaStreamClientOptions } from "./types.js";
|
|
3
|
-
import { AptosStreamClient, ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos/index.js";
|
|
4
|
-
import { EvmStreamClient } from "../evm/index.js";
|
|
5
|
-
import { SolanaStreamClient, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "../solana/index.js";
|
|
6
|
-
import { ICreateStreamSuiExt, ITransactionSuiExt, SuiStreamClient } from "../sui/index.js";
|
|
7
|
-
/** Type referencing options for specific Chain Client */
|
|
8
|
-
type StreamClientOptions<T extends IChain> = T extends IChain.Solana ? SolanaStreamClientOptions : T extends IChain.Aptos ? AptosStreamClientOptions : T extends IChain.Sui ? SuiStreamClientOptions : EvmStreamClientOptions;
|
|
9
|
-
/** Type referencing Chain Client implementation */
|
|
10
|
-
type StreamClientType<T extends IChain> = T extends IChain.Solana ? SolanaStreamClient : T extends IChain.Aptos ? AptosStreamClient : T extends IChain.Sui ? SuiStreamClient : EvmStreamClient;
|
|
11
|
-
/** Type referencing additional parameters used by a Chain Client */
|
|
12
|
-
type ChainSpecificParams<T, SolanaExt, AptosExt, SuiExt> = T extends SolanaStreamClient ? SolanaExt : T extends AptosStreamClient ? AptosExt : T extends SuiStreamClient ? SuiExt : undefined;
|
|
13
|
-
/** Type referencing additional parameters used on Create by a Chain Client */
|
|
14
|
-
type CreateSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, ICreateStreamSolanaExt, ICreateStreamAptosExt, ICreateStreamSuiExt>;
|
|
15
|
-
/** Type referencing additional parameters used on Topup by a Chain Client */
|
|
16
|
-
type TopupSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, ITopUpStreamSolanaExt, ITransactionAptosExt, ITransactionSuiExt>;
|
|
17
|
-
/** Type referencing additional parameters used on other interactions by a Chain Client */
|
|
18
|
-
type InteractSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, IInteractStreamSolanaExt, ITransactionAptosExt, ITransactionSuiExt>;
|
|
19
|
-
/** Generic Stream Client implementation that wrap Chain Client methods and enriches error messages if possible
|
|
20
|
-
* @property {StreamClientType} - Chain Client implementation
|
|
21
|
-
* @property {chain} - Chain
|
|
22
|
-
*/
|
|
23
|
-
export default class GenericStreamClient<T extends IChain> extends BaseStreamClient {
|
|
24
|
-
nativeStreamClient: StreamClientType<T>;
|
|
25
|
-
chain: IChain;
|
|
26
|
-
constructor(options: StreamClientOptions<T>);
|
|
27
|
-
/**
|
|
28
|
-
* Creates a new stream/vesting contract.
|
|
29
|
-
*/
|
|
30
|
-
create(streamData: ICreateStreamData, chainSpecificParams?: CreateSpecificParams<T>): Promise<ICreateResult>;
|
|
31
|
-
/**
|
|
32
|
-
* Creates multiple stream/vesting contracts.
|
|
33
|
-
*/
|
|
34
|
-
createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams?: CreateSpecificParams<T>): Promise<IMultiTransactionResult>;
|
|
35
|
-
/**
|
|
36
|
-
* Attempts withdrawing from the specified stream.
|
|
37
|
-
*/
|
|
38
|
-
withdraw({ id, amount }: IWithdrawData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
|
|
39
|
-
/**
|
|
40
|
-
* Attempts canceling the specified stream.
|
|
41
|
-
*/
|
|
42
|
-
cancel(cancelData: ICancelData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
|
|
43
|
-
/**
|
|
44
|
-
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
45
|
-
*/
|
|
46
|
-
transfer(transferData: ITransferData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
|
|
47
|
-
/**
|
|
48
|
-
* Tops up stream account with specified amount.
|
|
49
|
-
*/
|
|
50
|
-
topup(topupData: ITopUpData, chainSpecificParams?: TopupSpecificParams<T>): Promise<ITransactionResult>;
|
|
51
|
-
/**
|
|
52
|
-
* Fetch stream data by its id (address).
|
|
53
|
-
*/
|
|
54
|
-
getOne(getOneData: IGetOneData): Promise<Stream>;
|
|
55
|
-
/**
|
|
56
|
-
* Fetch streams by sender or recipient address.
|
|
57
|
-
*/
|
|
58
|
-
get(getAllData: IGetAllData): Promise<[string, Stream][]>;
|
|
59
|
-
/**
|
|
60
|
-
* Attempts updating the stream auto withdrawal params and amount per period
|
|
61
|
-
*/
|
|
62
|
-
update(updateData: IUpdateData, chainSpecificParams?: InteractSpecificParams<T>): Promise<ITransactionResult>;
|
|
63
|
-
/**
|
|
64
|
-
* Returns streamflow and partner fees for the specific wallet in %
|
|
65
|
-
*/
|
|
66
|
-
getFees(getFeesData: IGetFeesData): Promise<IFees | null>;
|
|
67
|
-
/**
|
|
68
|
-
* Returns default Streamflow Fee in %
|
|
69
|
-
*/
|
|
70
|
-
getDefaultStreamflowFee(): Promise<number>;
|
|
71
|
-
}
|
|
72
|
-
export {};
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { BaseStreamClient } from "./BaseStreamClient.js";
|
|
2
|
-
import { IChain, } from "./types.js";
|
|
3
|
-
import { handleContractError } from "./utils.js";
|
|
4
|
-
import { AptosStreamClient } from "../aptos/index.js";
|
|
5
|
-
import { EvmStreamClient } from "../evm/index.js";
|
|
6
|
-
import { SolanaStreamClient, } from "../solana/index.js";
|
|
7
|
-
import { SuiStreamClient } from "../sui/index.js";
|
|
8
|
-
import { WITHDRAW_AVAILABLE_AMOUNT } from "./constants.js";
|
|
9
|
-
/** Generic Stream Client implementation that wrap Chain Client methods and enriches error messages if possible
|
|
10
|
-
* @property {StreamClientType} - Chain Client implementation
|
|
11
|
-
* @property {chain} - Chain
|
|
12
|
-
*/
|
|
13
|
-
export default class GenericStreamClient extends BaseStreamClient {
|
|
14
|
-
nativeStreamClient;
|
|
15
|
-
chain;
|
|
16
|
-
constructor(options) {
|
|
17
|
-
super();
|
|
18
|
-
this.chain = options.chain;
|
|
19
|
-
switch (options.chain) {
|
|
20
|
-
case IChain.Solana:
|
|
21
|
-
this.nativeStreamClient = new SolanaStreamClient(options);
|
|
22
|
-
break;
|
|
23
|
-
case IChain.Aptos:
|
|
24
|
-
this.nativeStreamClient = new AptosStreamClient(options.clusterUrl, options.cluster, options.maxGas, options.programId);
|
|
25
|
-
break;
|
|
26
|
-
case IChain.BNB:
|
|
27
|
-
case IChain.Ethereum:
|
|
28
|
-
case IChain.Polygon:
|
|
29
|
-
this.nativeStreamClient = new EvmStreamClient(options.clusterUrl, options.chain, options.signer, options.cluster, options.programId);
|
|
30
|
-
break;
|
|
31
|
-
case IChain.Sui:
|
|
32
|
-
this.nativeStreamClient = new SuiStreamClient(options.clusterUrl, options.cluster, options.ids);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Creates a new stream/vesting contract.
|
|
37
|
-
*/
|
|
38
|
-
create(streamData, chainSpecificParams) {
|
|
39
|
-
return handleContractError(() => this.nativeStreamClient.create(streamData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Creates multiple stream/vesting contracts.
|
|
43
|
-
*/
|
|
44
|
-
createMultiple(multipleStreamData, chainSpecificParams) {
|
|
45
|
-
return handleContractError(() => this.nativeStreamClient.createMultiple(multipleStreamData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Attempts withdrawing from the specified stream.
|
|
49
|
-
*/
|
|
50
|
-
withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, chainSpecificParams) {
|
|
51
|
-
return handleContractError(() => this.nativeStreamClient.withdraw({ id, amount }, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Attempts canceling the specified stream.
|
|
55
|
-
*/
|
|
56
|
-
cancel(cancelData, chainSpecificParams) {
|
|
57
|
-
return handleContractError(() => this.nativeStreamClient.cancel(cancelData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
61
|
-
*/
|
|
62
|
-
transfer(transferData, chainSpecificParams) {
|
|
63
|
-
return handleContractError(() => this.nativeStreamClient.transfer(transferData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Tops up stream account with specified amount.
|
|
67
|
-
*/
|
|
68
|
-
topup(topupData, chainSpecificParams) {
|
|
69
|
-
return handleContractError(() => this.nativeStreamClient.topup(topupData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Fetch stream data by its id (address).
|
|
73
|
-
*/
|
|
74
|
-
getOne(getOneData) {
|
|
75
|
-
return this.nativeStreamClient.getOne(getOneData);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Fetch streams by sender or recipient address.
|
|
79
|
-
*/
|
|
80
|
-
get(getAllData) {
|
|
81
|
-
return this.nativeStreamClient.get(getAllData);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Attempts updating the stream auto withdrawal params and amount per period
|
|
85
|
-
*/
|
|
86
|
-
update(updateData, chainSpecificParams) {
|
|
87
|
-
return handleContractError(() => this.nativeStreamClient.update(updateData, chainSpecificParams), this.nativeStreamClient.extractErrorCode);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Returns streamflow and partner fees for the specific wallet in %
|
|
91
|
-
*/
|
|
92
|
-
getFees(getFeesData) {
|
|
93
|
-
return this.nativeStreamClient.getFees(getFeesData);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Returns default Streamflow Fee in %
|
|
97
|
-
*/
|
|
98
|
-
getDefaultStreamflowFee() {
|
|
99
|
-
return this.nativeStreamClient.getDefaultStreamflowFee();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import BN from "bn.js";
|
|
2
|
-
export const MAX_SAFE_UNIX_TIME_VALUE = 8640000000000;
|
|
3
|
-
export const BASE_FEE = 1009900; // Buffer to include usual fees when calculating stream amount
|
|
4
|
-
export const WITHDRAW_AVAILABLE_AMOUNT = new BN("18446744073709551615"); // Magical number to withdraw all available amount from a Contract
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import BN from "bn.js";
|
|
2
|
-
import { AlignedStream, ICreateAlignedStreamData, ICreateStreamData, Stream, StreamType } from "./types.js";
|
|
3
|
-
interface ICalculateUnlockedAmount {
|
|
4
|
-
depositedAmount: BN;
|
|
5
|
-
cliff: number;
|
|
6
|
-
cliffAmount: BN;
|
|
7
|
-
end: number;
|
|
8
|
-
currentTimestamp: number;
|
|
9
|
-
lastRateChangeTime: number;
|
|
10
|
-
period: number;
|
|
11
|
-
amountPerPeriod: BN;
|
|
12
|
-
fundsUnlockedAtLastRateChange: BN;
|
|
13
|
-
}
|
|
14
|
-
export declare const calculateUnlockedAmount: ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }: ICalculateUnlockedAmount) => BN;
|
|
15
|
-
export declare const isCliffCloseToDepositedAmount: (streamData: {
|
|
16
|
-
depositedAmount: BN;
|
|
17
|
-
cliffAmount: BN;
|
|
18
|
-
}) => boolean;
|
|
19
|
-
export declare const isPayment: (streamData: {
|
|
20
|
-
canTopup: boolean;
|
|
21
|
-
}) => boolean;
|
|
22
|
-
export declare const isVesting: (streamData: {
|
|
23
|
-
canTopup: boolean;
|
|
24
|
-
depositedAmount: BN;
|
|
25
|
-
cliffAmount: BN;
|
|
26
|
-
minPrice?: number;
|
|
27
|
-
maxPrice?: number;
|
|
28
|
-
minPercentage?: number;
|
|
29
|
-
maxPercentage?: number;
|
|
30
|
-
}) => boolean;
|
|
31
|
-
export declare const isAligned: (stream: Stream) => stream is AlignedStream;
|
|
32
|
-
export declare const isCreateAlignedStreamData: (obj: ICreateStreamData) => obj is ICreateAlignedStreamData;
|
|
33
|
-
export declare const isDynamicLock: (minPrice?: number, maxPrice?: number, minPercentage?: number, maxPercentage?: number) => boolean;
|
|
34
|
-
export declare const isTokenLock: (streamData: {
|
|
35
|
-
canTopup: boolean;
|
|
36
|
-
automaticWithdrawal: boolean;
|
|
37
|
-
cancelableBySender: boolean;
|
|
38
|
-
cancelableByRecipient: boolean;
|
|
39
|
-
transferableBySender: boolean;
|
|
40
|
-
transferableByRecipient: boolean;
|
|
41
|
-
depositedAmount: BN;
|
|
42
|
-
cliffAmount: BN;
|
|
43
|
-
minPrice?: number;
|
|
44
|
-
maxPrice?: number;
|
|
45
|
-
minPercentage?: number;
|
|
46
|
-
maxPercentage?: number;
|
|
47
|
-
}) => boolean;
|
|
48
|
-
export declare const buildStreamType: (streamData: {
|
|
49
|
-
canTopup: boolean;
|
|
50
|
-
automaticWithdrawal: boolean;
|
|
51
|
-
cancelableBySender: boolean;
|
|
52
|
-
cancelableByRecipient: boolean;
|
|
53
|
-
transferableBySender: boolean;
|
|
54
|
-
transferableByRecipient: boolean;
|
|
55
|
-
depositedAmount: BN;
|
|
56
|
-
cliffAmount: BN;
|
|
57
|
-
minPrice?: number;
|
|
58
|
-
maxPrice?: number;
|
|
59
|
-
minPercentage?: number;
|
|
60
|
-
maxPercentage?: number;
|
|
61
|
-
}) => StreamType;
|
|
62
|
-
export declare const decodeEndTime: (endTime: BN) => number;
|
|
63
|
-
export {};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import BN from "bn.js";
|
|
2
|
-
import { StreamType } from "./types.js";
|
|
3
|
-
import { MAX_SAFE_UNIX_TIME_VALUE } from "./constants.js";
|
|
4
|
-
export const calculateUnlockedAmount = ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }) => {
|
|
5
|
-
const deposited = depositedAmount;
|
|
6
|
-
if (currentTimestamp < cliff)
|
|
7
|
-
return new BN(0);
|
|
8
|
-
if (currentTimestamp > end)
|
|
9
|
-
return deposited;
|
|
10
|
-
const savedUnlockedFunds = lastRateChangeTime === 0 ? cliffAmount : fundsUnlockedAtLastRateChange;
|
|
11
|
-
const savedUnlockedFundsTime = lastRateChangeTime === 0 ? cliff : lastRateChangeTime;
|
|
12
|
-
const streamed = new BN(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period))
|
|
13
|
-
.mul(amountPerPeriod)
|
|
14
|
-
.add(savedUnlockedFunds);
|
|
15
|
-
return streamed.lt(deposited) ? streamed : deposited;
|
|
16
|
-
};
|
|
17
|
-
export const isCliffCloseToDepositedAmount = (streamData) => {
|
|
18
|
-
return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new BN(1)));
|
|
19
|
-
};
|
|
20
|
-
export const isPayment = (streamData) => {
|
|
21
|
-
return streamData.canTopup;
|
|
22
|
-
};
|
|
23
|
-
export const isVesting = (streamData) => {
|
|
24
|
-
return (!streamData.canTopup &&
|
|
25
|
-
!isCliffCloseToDepositedAmount(streamData) &&
|
|
26
|
-
!isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage));
|
|
27
|
-
};
|
|
28
|
-
export const isAligned = (stream) => {
|
|
29
|
-
return "minPrice" in stream && "maxPrice" in stream && "minPercentage" in stream && "maxPercentage" in stream;
|
|
30
|
-
};
|
|
31
|
-
export const isCreateAlignedStreamData = (obj) => {
|
|
32
|
-
return "minPrice" in obj && "maxPrice" in obj && "minPercentage" in obj && "maxPercentage" in obj;
|
|
33
|
-
};
|
|
34
|
-
export const isDynamicLock = (minPrice, maxPrice, minPercentage, maxPercentage) => {
|
|
35
|
-
return (!!minPrice && !!maxPrice && minPrice > 0 && maxPrice - minPrice <= 1 && minPercentage === 0 && maxPercentage === 100);
|
|
36
|
-
};
|
|
37
|
-
export const isTokenLock = (streamData) => {
|
|
38
|
-
return (!streamData.canTopup &&
|
|
39
|
-
!streamData.automaticWithdrawal &&
|
|
40
|
-
!streamData.cancelableBySender &&
|
|
41
|
-
!streamData.cancelableByRecipient &&
|
|
42
|
-
!streamData.transferableBySender &&
|
|
43
|
-
!streamData.transferableByRecipient &&
|
|
44
|
-
(isCliffCloseToDepositedAmount(streamData) ||
|
|
45
|
-
isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage)));
|
|
46
|
-
};
|
|
47
|
-
export const buildStreamType = (streamData) => {
|
|
48
|
-
if (isVesting(streamData)) {
|
|
49
|
-
return StreamType.Vesting;
|
|
50
|
-
}
|
|
51
|
-
if (isTokenLock(streamData)) {
|
|
52
|
-
return StreamType.Lock;
|
|
53
|
-
}
|
|
54
|
-
return StreamType.Payment;
|
|
55
|
-
};
|
|
56
|
-
export const decodeEndTime = (endTime) => {
|
|
57
|
-
if (endTime.gt(new BN(MAX_SAFE_UNIX_TIME_VALUE))) {
|
|
58
|
-
return MAX_SAFE_UNIX_TIME_VALUE;
|
|
59
|
-
}
|
|
60
|
-
return endTime.toNumber();
|
|
61
|
-
};
|