@streamflow/stream 2.0.2-beta.24
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/README.md +203 -0
- package/dist/constants.d.ts +14 -0
- package/dist/constants.js +19 -0
- package/dist/idl.d.ts +22 -0
- package/dist/idl.js +422 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +23 -0
- package/dist/instructions.d.ts +97 -0
- package/dist/instructions.js +210 -0
- package/dist/layout.d.ts +18 -0
- package/dist/layout.js +73 -0
- package/dist/sdk.d.ts +85 -0
- package/dist/sdk.js +573 -0
- package/dist/types.d.ts +165 -0
- package/dist/types.js +21 -0
- package/dist/utils.d.ts +19 -0
- package/dist/utils.js +118 -0
- package/package.json +13 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Wallet } from "@project-serum/anchor/src/provider";
|
|
3
|
+
import { WalletAdapterNetwork } from "@solana/wallet-adapter-base";
|
|
4
|
+
import { AccountInfo, PublicKey, Keypair, TransactionSignature, TransactionInstruction } from "@solana/web3.js";
|
|
5
|
+
import { u64 } from "@solana/spl-token";
|
|
6
|
+
export { WalletAdapterNetwork as Cluster } from "@solana/wallet-adapter-base";
|
|
7
|
+
export declare enum StreamDirection {
|
|
8
|
+
Outgoing = "outgoing",
|
|
9
|
+
Incoming = "incoming",
|
|
10
|
+
All = "all"
|
|
11
|
+
}
|
|
12
|
+
export declare enum StreamType {
|
|
13
|
+
Stream = "stream",
|
|
14
|
+
Vesting = "vesting",
|
|
15
|
+
All = "all"
|
|
16
|
+
}
|
|
17
|
+
export interface Account {
|
|
18
|
+
pubkey: PublicKey;
|
|
19
|
+
account: AccountInfo<Buffer>;
|
|
20
|
+
}
|
|
21
|
+
export declare enum LocalCluster {
|
|
22
|
+
Local = "local"
|
|
23
|
+
}
|
|
24
|
+
export declare type ClusterExtended = WalletAdapterNetwork | LocalCluster;
|
|
25
|
+
export interface CreateStreamData {
|
|
26
|
+
recipient: string;
|
|
27
|
+
mint: string;
|
|
28
|
+
start: number;
|
|
29
|
+
depositedAmount: u64;
|
|
30
|
+
period: number;
|
|
31
|
+
cliff: number;
|
|
32
|
+
cliffAmount: u64;
|
|
33
|
+
amountPerPeriod: u64;
|
|
34
|
+
name: string;
|
|
35
|
+
canTopup: boolean;
|
|
36
|
+
cancelableBySender: boolean;
|
|
37
|
+
cancelableByRecipient: boolean;
|
|
38
|
+
transferableBySender: boolean;
|
|
39
|
+
transferableByRecipient: boolean;
|
|
40
|
+
automaticWithdrawal: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface CreateStreamParams extends CreateStreamData {
|
|
43
|
+
sender: Wallet;
|
|
44
|
+
partner?: string | null;
|
|
45
|
+
}
|
|
46
|
+
export interface WithdrawStreamData {
|
|
47
|
+
id: string;
|
|
48
|
+
amount: u64;
|
|
49
|
+
}
|
|
50
|
+
export interface WithdrawStreamParams extends WithdrawStreamData {
|
|
51
|
+
invoker: Wallet;
|
|
52
|
+
}
|
|
53
|
+
export interface TopupStreamData {
|
|
54
|
+
id: string;
|
|
55
|
+
amount: u64;
|
|
56
|
+
}
|
|
57
|
+
export interface TopupStreamParams extends TopupStreamData {
|
|
58
|
+
invoker: Wallet;
|
|
59
|
+
}
|
|
60
|
+
export interface CancelStreamData {
|
|
61
|
+
id: string;
|
|
62
|
+
}
|
|
63
|
+
export interface CancelStreamParams extends CancelStreamData {
|
|
64
|
+
invoker: Wallet;
|
|
65
|
+
}
|
|
66
|
+
export interface TransferStreamData {
|
|
67
|
+
id: string;
|
|
68
|
+
recipientId: string;
|
|
69
|
+
}
|
|
70
|
+
export interface TransferStreamParams extends TransferStreamData {
|
|
71
|
+
invoker: Wallet;
|
|
72
|
+
}
|
|
73
|
+
export interface GetStreamParams {
|
|
74
|
+
id: string;
|
|
75
|
+
}
|
|
76
|
+
export interface GetStreamsParams {
|
|
77
|
+
wallet: PublicKey;
|
|
78
|
+
type?: StreamType;
|
|
79
|
+
direction?: StreamDirection;
|
|
80
|
+
}
|
|
81
|
+
export interface Stream {
|
|
82
|
+
magic: number;
|
|
83
|
+
version: number;
|
|
84
|
+
createdAt: number;
|
|
85
|
+
withdrawnAmount: u64;
|
|
86
|
+
canceledAt: number;
|
|
87
|
+
end: number;
|
|
88
|
+
lastWithdrawnAt: number;
|
|
89
|
+
sender: string;
|
|
90
|
+
senderTokens: string;
|
|
91
|
+
recipient: string;
|
|
92
|
+
recipientTokens: string;
|
|
93
|
+
mint: string;
|
|
94
|
+
escrowTokens: string;
|
|
95
|
+
streamflowTreasury: string;
|
|
96
|
+
streamflowTreasuryTokens: string;
|
|
97
|
+
streamflowFeeTotal: u64;
|
|
98
|
+
streamflowFeeWithdrawn: u64;
|
|
99
|
+
streamflowFeePercent: number;
|
|
100
|
+
partnerFeeTotal: u64;
|
|
101
|
+
partnerFeeWithdrawn: u64;
|
|
102
|
+
partnerFeePercent: number;
|
|
103
|
+
partner: string;
|
|
104
|
+
partnerTokens: string;
|
|
105
|
+
start: number;
|
|
106
|
+
depositedAmount: u64;
|
|
107
|
+
period: number;
|
|
108
|
+
amountPerPeriod: u64;
|
|
109
|
+
cliff: number;
|
|
110
|
+
cliffAmount: u64;
|
|
111
|
+
cancelableBySender: boolean;
|
|
112
|
+
cancelableByRecipient: boolean;
|
|
113
|
+
automaticWithdrawal: boolean;
|
|
114
|
+
transferableBySender: boolean;
|
|
115
|
+
transferableByRecipient: boolean;
|
|
116
|
+
canTopup: boolean;
|
|
117
|
+
name: string;
|
|
118
|
+
withdrawFrequency: number;
|
|
119
|
+
}
|
|
120
|
+
export interface DecodedStream {
|
|
121
|
+
magic: u64;
|
|
122
|
+
version: u64;
|
|
123
|
+
createdAt: u64;
|
|
124
|
+
withdrawnAmount: u64;
|
|
125
|
+
canceledAt: u64;
|
|
126
|
+
end: u64;
|
|
127
|
+
lastWithdrawnAt: u64;
|
|
128
|
+
sender: PublicKey;
|
|
129
|
+
senderTokens: PublicKey;
|
|
130
|
+
recipient: PublicKey;
|
|
131
|
+
recipientTokens: PublicKey;
|
|
132
|
+
mint: PublicKey;
|
|
133
|
+
escrowTokens: PublicKey;
|
|
134
|
+
streamflowTreasury: PublicKey;
|
|
135
|
+
streamflowTreasuryTokens: PublicKey;
|
|
136
|
+
streamflowFeeTotal: u64;
|
|
137
|
+
streamflowFeeWithdrawn: u64;
|
|
138
|
+
streamflowFeePercent: u64;
|
|
139
|
+
partnerFeeTotal: u64;
|
|
140
|
+
partnerFeeWithdrawn: u64;
|
|
141
|
+
partnerFeePercent: u64;
|
|
142
|
+
partner: PublicKey;
|
|
143
|
+
partnerTokens: PublicKey;
|
|
144
|
+
start: u64;
|
|
145
|
+
depositedAmount: u64;
|
|
146
|
+
period: u64;
|
|
147
|
+
amountPerPeriod: u64;
|
|
148
|
+
cliff: u64;
|
|
149
|
+
cliffAmount: u64;
|
|
150
|
+
cancelableBySender: boolean;
|
|
151
|
+
cancelableByRecipient: boolean;
|
|
152
|
+
automaticWithdrawal: boolean;
|
|
153
|
+
transferableBySender: boolean;
|
|
154
|
+
transferableByRecipient: boolean;
|
|
155
|
+
canTopup: boolean;
|
|
156
|
+
name: string;
|
|
157
|
+
withdrawFrequency: u64;
|
|
158
|
+
}
|
|
159
|
+
export interface TransactionResponse {
|
|
160
|
+
ixs: TransactionInstruction[];
|
|
161
|
+
tx: TransactionSignature;
|
|
162
|
+
}
|
|
163
|
+
export interface CreateStreamResponse extends TransactionResponse {
|
|
164
|
+
metadata: Keypair;
|
|
165
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalCluster = exports.StreamType = exports.StreamDirection = exports.Cluster = void 0;
|
|
4
|
+
var wallet_adapter_base_1 = require("@solana/wallet-adapter-base");
|
|
5
|
+
Object.defineProperty(exports, "Cluster", { enumerable: true, get: function () { return wallet_adapter_base_1.WalletAdapterNetwork; } });
|
|
6
|
+
var StreamDirection;
|
|
7
|
+
(function (StreamDirection) {
|
|
8
|
+
StreamDirection["Outgoing"] = "outgoing";
|
|
9
|
+
StreamDirection["Incoming"] = "incoming";
|
|
10
|
+
StreamDirection["All"] = "all";
|
|
11
|
+
})(StreamDirection = exports.StreamDirection || (exports.StreamDirection = {}));
|
|
12
|
+
var StreamType;
|
|
13
|
+
(function (StreamType) {
|
|
14
|
+
StreamType["Stream"] = "stream";
|
|
15
|
+
StreamType["Vesting"] = "vesting";
|
|
16
|
+
StreamType["All"] = "all";
|
|
17
|
+
})(StreamType = exports.StreamType || (exports.StreamType = {}));
|
|
18
|
+
var LocalCluster;
|
|
19
|
+
(function (LocalCluster) {
|
|
20
|
+
LocalCluster["Local"] = "local";
|
|
21
|
+
})(LocalCluster = exports.LocalCluster || (exports.LocalCluster = {}));
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { u64 } from "@solana/spl-token";
|
|
3
|
+
import { Stream, DecodedStream } from "./types";
|
|
4
|
+
export declare const decodeStream: (buf: Buffer) => DecodedStream;
|
|
5
|
+
export declare const formatDecodedStream: (stream: DecodedStream) => Stream;
|
|
6
|
+
/**
|
|
7
|
+
* Used for conversion of token amounts to their Big Number representation.
|
|
8
|
+
* Get Big Number representation in the smallest units from the same value in the highest units.
|
|
9
|
+
* @param {number} value - Number of tokens you want to convert to its u64 representation.
|
|
10
|
+
* @param {number} decimals - Number of decimals the token has.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getBN: (value: number, decimals: number) => u64;
|
|
13
|
+
/**
|
|
14
|
+
* Used for token amounts conversion from their Big Number representation to number.
|
|
15
|
+
* Get value in the highest units from u64 representation of the same value in the smallest units.
|
|
16
|
+
* @param {u64} value - Big Number representation of value in the smallest units.
|
|
17
|
+
* @param {number} decimals - Number of decimals the token has.
|
|
18
|
+
*/
|
|
19
|
+
export declare const getNumberFromBN: (value: u64, decimals: number) => number;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNumberFromBN = exports.getBN = exports.formatDecodedStream = exports.decodeStream = void 0;
|
|
4
|
+
var web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
var spl_token_1 = require("@solana/spl-token");
|
|
6
|
+
var layout_1 = require("./layout");
|
|
7
|
+
var decoder = new TextDecoder("utf-8");
|
|
8
|
+
var LE = "le"; //little endian
|
|
9
|
+
var decodeStream = function (buf) {
|
|
10
|
+
var raw = layout_1.streamLayout.decode(buf);
|
|
11
|
+
return {
|
|
12
|
+
magic: new spl_token_1.u64(raw.magic, LE),
|
|
13
|
+
version: new spl_token_1.u64(raw.version, LE),
|
|
14
|
+
createdAt: new spl_token_1.u64(raw.created_at, LE),
|
|
15
|
+
withdrawnAmount: new spl_token_1.u64(raw.withdrawn_amount, LE),
|
|
16
|
+
canceledAt: new spl_token_1.u64(raw.canceled_at, LE),
|
|
17
|
+
end: new spl_token_1.u64(raw.end_time, LE),
|
|
18
|
+
lastWithdrawnAt: new spl_token_1.u64(raw.last_withdrawn_at, LE),
|
|
19
|
+
sender: new web3_js_1.PublicKey(raw.sender),
|
|
20
|
+
senderTokens: new web3_js_1.PublicKey(raw.sender_tokens),
|
|
21
|
+
recipient: new web3_js_1.PublicKey(raw.recipient),
|
|
22
|
+
recipientTokens: new web3_js_1.PublicKey(raw.recipient_tokens),
|
|
23
|
+
mint: new web3_js_1.PublicKey(raw.mint),
|
|
24
|
+
escrowTokens: new web3_js_1.PublicKey(raw.escrow_tokens),
|
|
25
|
+
streamflowTreasury: new web3_js_1.PublicKey(raw.streamflow_treasury),
|
|
26
|
+
streamflowTreasuryTokens: new web3_js_1.PublicKey(raw.streamflow_treasury_tokens),
|
|
27
|
+
streamflowFeeTotal: new spl_token_1.u64(raw.streamflow_fee_total, LE),
|
|
28
|
+
streamflowFeeWithdrawn: new spl_token_1.u64(raw.streamflow_fee_withdrawn, LE),
|
|
29
|
+
streamflowFeePercent: new spl_token_1.u64(raw.streamflow_fee_percent, LE),
|
|
30
|
+
partnerFeeTotal: new spl_token_1.u64(raw.partner_fee_total, LE),
|
|
31
|
+
partnerFeeWithdrawn: new spl_token_1.u64(raw.partner_fee_withdrawn, LE),
|
|
32
|
+
partnerFeePercent: new spl_token_1.u64(raw.partner_fee_percent, LE),
|
|
33
|
+
partner: new web3_js_1.PublicKey(raw.partner),
|
|
34
|
+
partnerTokens: new web3_js_1.PublicKey(raw.partner_tokens),
|
|
35
|
+
start: new spl_token_1.u64(raw.start_time, LE),
|
|
36
|
+
depositedAmount: new spl_token_1.u64(raw.net_amount_deposited, LE),
|
|
37
|
+
period: new spl_token_1.u64(raw.period, LE),
|
|
38
|
+
amountPerPeriod: new spl_token_1.u64(raw.amount_per_period, LE),
|
|
39
|
+
cliff: new spl_token_1.u64(raw.cliff, LE),
|
|
40
|
+
cliffAmount: new spl_token_1.u64(raw.cliff_amount, LE),
|
|
41
|
+
cancelableBySender: Boolean(raw.cancelable_by_sender),
|
|
42
|
+
cancelableByRecipient: Boolean(raw.cancelable_by_recipient),
|
|
43
|
+
automaticWithdrawal: Boolean(raw.automatic_withdrawal),
|
|
44
|
+
transferableBySender: Boolean(raw.transferable_by_sender),
|
|
45
|
+
transferableByRecipient: Boolean(raw.transferable_by_recipient),
|
|
46
|
+
canTopup: Boolean(raw.can_topup),
|
|
47
|
+
name: decoder.decode(raw.stream_name),
|
|
48
|
+
withdrawFrequency: new spl_token_1.u64(raw.withdraw_frequency, LE),
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
exports.decodeStream = decodeStream;
|
|
52
|
+
var formatDecodedStream = function (stream) {
|
|
53
|
+
var _a;
|
|
54
|
+
return ({
|
|
55
|
+
magic: stream.magic.toNumber(),
|
|
56
|
+
version: stream.version.toNumber(),
|
|
57
|
+
createdAt: stream.createdAt.toNumber(),
|
|
58
|
+
withdrawnAmount: stream.withdrawnAmount,
|
|
59
|
+
canceledAt: stream.canceledAt.toNumber(),
|
|
60
|
+
end: stream.end.toNumber(),
|
|
61
|
+
lastWithdrawnAt: stream.lastWithdrawnAt.toNumber(),
|
|
62
|
+
sender: stream.sender.toBase58(),
|
|
63
|
+
senderTokens: stream.senderTokens.toBase58(),
|
|
64
|
+
recipient: stream.recipient.toBase58(),
|
|
65
|
+
recipientTokens: stream.recipientTokens.toBase58(),
|
|
66
|
+
mint: stream.mint.toBase58(),
|
|
67
|
+
escrowTokens: stream.escrowTokens.toBase58(),
|
|
68
|
+
streamflowTreasury: stream.streamflowTreasury.toBase58(),
|
|
69
|
+
streamflowTreasuryTokens: stream.streamflowTreasuryTokens.toBase58(),
|
|
70
|
+
streamflowFeeTotal: stream.streamflowFeeTotal,
|
|
71
|
+
streamflowFeeWithdrawn: stream.streamflowFeeWithdrawn,
|
|
72
|
+
streamflowFeePercent: stream.streamflowFeePercent.toNumber(),
|
|
73
|
+
partnerFeeTotal: stream.partnerFeeTotal,
|
|
74
|
+
partnerFeeWithdrawn: stream.partnerFeeWithdrawn,
|
|
75
|
+
partnerFeePercent: stream.partnerFeePercent.toNumber(),
|
|
76
|
+
partner: stream.partner.toBase58(),
|
|
77
|
+
partnerTokens: (_a = stream.partnerTokens) === null || _a === void 0 ? void 0 : _a.toBase58(),
|
|
78
|
+
start: stream.start.toNumber(),
|
|
79
|
+
depositedAmount: stream.depositedAmount,
|
|
80
|
+
period: stream.period.toNumber(),
|
|
81
|
+
amountPerPeriod: stream.amountPerPeriod,
|
|
82
|
+
cliff: stream.cliff.toNumber(),
|
|
83
|
+
cliffAmount: stream.cliffAmount,
|
|
84
|
+
cancelableBySender: stream.cancelableBySender,
|
|
85
|
+
cancelableByRecipient: stream.cancelableByRecipient,
|
|
86
|
+
automaticWithdrawal: stream.automaticWithdrawal,
|
|
87
|
+
transferableBySender: stream.transferableBySender,
|
|
88
|
+
transferableByRecipient: stream.transferableByRecipient,
|
|
89
|
+
canTopup: stream.canTopup,
|
|
90
|
+
name: stream.name,
|
|
91
|
+
withdrawFrequency: stream.withdrawFrequency.toNumber(),
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
exports.formatDecodedStream = formatDecodedStream;
|
|
95
|
+
/**
|
|
96
|
+
* Used for conversion of token amounts to their Big Number representation.
|
|
97
|
+
* Get Big Number representation in the smallest units from the same value in the highest units.
|
|
98
|
+
* @param {number} value - Number of tokens you want to convert to its u64 representation.
|
|
99
|
+
* @param {number} decimals - Number of decimals the token has.
|
|
100
|
+
*/
|
|
101
|
+
var getBN = function (value, decimals) {
|
|
102
|
+
return value > (Math.pow(2, 53) - 1) / Math.pow(10, decimals)
|
|
103
|
+
? new spl_token_1.u64(value).mul(new spl_token_1.u64(Math.pow(10, decimals)))
|
|
104
|
+
: new spl_token_1.u64(value * Math.pow(10, decimals));
|
|
105
|
+
};
|
|
106
|
+
exports.getBN = getBN;
|
|
107
|
+
/**
|
|
108
|
+
* Used for token amounts conversion from their Big Number representation to number.
|
|
109
|
+
* Get value in the highest units from u64 representation of the same value in the smallest units.
|
|
110
|
+
* @param {u64} value - Big Number representation of value in the smallest units.
|
|
111
|
+
* @param {number} decimals - Number of decimals the token has.
|
|
112
|
+
*/
|
|
113
|
+
var getNumberFromBN = function (value, decimals) {
|
|
114
|
+
return value.gt(new spl_token_1.u64(Math.pow(2, 53) - 1))
|
|
115
|
+
? value.div(new spl_token_1.u64(Math.pow(10, decimals))).toNumber()
|
|
116
|
+
: value.toNumber() / Math.pow(10, decimals);
|
|
117
|
+
};
|
|
118
|
+
exports.getNumberFromBN = getNumberFromBN;
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@streamflow/stream",
|
|
3
|
+
"version": "2.0.2-beta.24",
|
|
4
|
+
"description": "JavaScript SDK to interact with Streamflow protocol.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc --outDir ./dist",
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"gitHead": "a37306eba0e762af096db642fa22f07194014cfd"
|
|
13
|
+
}
|