@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/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.u64 = exports.default = void 0;
|
|
17
|
+
var sdk_1 = require("./sdk");
|
|
18
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(sdk_1).default; } });
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
|
+
__exportStar(require("./instructions"), exports);
|
|
22
|
+
var spl_token_1 = require("@solana/spl-token");
|
|
23
|
+
Object.defineProperty(exports, "u64", { enumerable: true, get: function () { return spl_token_1.u64; } });
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import { u64 } from "@solana/spl-token";
|
|
3
|
+
interface CreateStreamData {
|
|
4
|
+
start: u64;
|
|
5
|
+
depositedAmount: u64;
|
|
6
|
+
period: u64;
|
|
7
|
+
amountPerPeriod: u64;
|
|
8
|
+
cliff: u64;
|
|
9
|
+
cliffAmount: u64;
|
|
10
|
+
cancelableBySender: boolean;
|
|
11
|
+
cancelableByRecipient: boolean;
|
|
12
|
+
automaticWithdrawal: boolean;
|
|
13
|
+
transferableBySender: boolean;
|
|
14
|
+
transferableByRecipient: boolean;
|
|
15
|
+
canTopup: boolean;
|
|
16
|
+
name: string;
|
|
17
|
+
withdrawFrequency: u64;
|
|
18
|
+
}
|
|
19
|
+
interface CreateStreamAccounts {
|
|
20
|
+
sender: PublicKey;
|
|
21
|
+
senderTokens: PublicKey;
|
|
22
|
+
recipient: PublicKey;
|
|
23
|
+
recipientTokens: PublicKey;
|
|
24
|
+
metadata: PublicKey;
|
|
25
|
+
escrowTokens: PublicKey;
|
|
26
|
+
streamflowTreasury: PublicKey;
|
|
27
|
+
streamflowTreasuryTokens: PublicKey;
|
|
28
|
+
partner: PublicKey;
|
|
29
|
+
partnerTokens: PublicKey;
|
|
30
|
+
mint: PublicKey;
|
|
31
|
+
feeOracle: PublicKey;
|
|
32
|
+
rent: PublicKey;
|
|
33
|
+
timelockProgram: PublicKey;
|
|
34
|
+
tokenProgram: PublicKey;
|
|
35
|
+
associatedTokenProgram: PublicKey;
|
|
36
|
+
withdrawor: PublicKey;
|
|
37
|
+
systemProgram: PublicKey;
|
|
38
|
+
}
|
|
39
|
+
export declare const createStreamInstruction: (data: CreateStreamData, programId: PublicKey, accounts: CreateStreamAccounts) => TransactionInstruction;
|
|
40
|
+
interface WithdrawAccounts {
|
|
41
|
+
authority: PublicKey;
|
|
42
|
+
recipient: PublicKey;
|
|
43
|
+
recipientTokens: PublicKey;
|
|
44
|
+
metadata: PublicKey;
|
|
45
|
+
escrowTokens: PublicKey;
|
|
46
|
+
streamflowTreasury: PublicKey;
|
|
47
|
+
streamflowTreasuryTokens: PublicKey;
|
|
48
|
+
partner: PublicKey;
|
|
49
|
+
partnerTokens: PublicKey;
|
|
50
|
+
mint: PublicKey;
|
|
51
|
+
tokenProgram: PublicKey;
|
|
52
|
+
}
|
|
53
|
+
export declare const withdrawStreamInstruction: (amount: u64, programId: PublicKey, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }: WithdrawAccounts) => TransactionInstruction;
|
|
54
|
+
interface CancelAccounts {
|
|
55
|
+
authority: PublicKey;
|
|
56
|
+
sender: PublicKey;
|
|
57
|
+
senderTokens: PublicKey;
|
|
58
|
+
recipient: PublicKey;
|
|
59
|
+
recipientTokens: PublicKey;
|
|
60
|
+
metadata: PublicKey;
|
|
61
|
+
escrowTokens: PublicKey;
|
|
62
|
+
streamflowTreasury: PublicKey;
|
|
63
|
+
streamflowTreasuryTokens: PublicKey;
|
|
64
|
+
partner: PublicKey;
|
|
65
|
+
partnerTokens: PublicKey;
|
|
66
|
+
mint: PublicKey;
|
|
67
|
+
tokenProgram: PublicKey;
|
|
68
|
+
}
|
|
69
|
+
export declare const cancelStreamInstruction: (programId: PublicKey, { authority, sender, senderTokens, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }: CancelAccounts) => TransactionInstruction;
|
|
70
|
+
interface TransferAccounts {
|
|
71
|
+
authority: PublicKey;
|
|
72
|
+
newRecipient: PublicKey;
|
|
73
|
+
newRecipientTokens: PublicKey;
|
|
74
|
+
metadata: PublicKey;
|
|
75
|
+
mint: PublicKey;
|
|
76
|
+
rent: PublicKey;
|
|
77
|
+
tokenProgram: PublicKey;
|
|
78
|
+
associatedTokenProgram: PublicKey;
|
|
79
|
+
systemProgram: PublicKey;
|
|
80
|
+
}
|
|
81
|
+
export declare const transferStreamInstruction: (programId: PublicKey, { authority, newRecipient, newRecipientTokens, metadata, mint, rent, tokenProgram, associatedTokenProgram, systemProgram, }: TransferAccounts) => TransactionInstruction;
|
|
82
|
+
interface TopupAccounts {
|
|
83
|
+
sender: PublicKey;
|
|
84
|
+
senderTokens: PublicKey;
|
|
85
|
+
metadata: PublicKey;
|
|
86
|
+
escrowTokens: PublicKey;
|
|
87
|
+
streamflowTreasury: PublicKey;
|
|
88
|
+
streamflowTreasuryTokens: PublicKey;
|
|
89
|
+
partner: PublicKey;
|
|
90
|
+
partnerTokens: PublicKey;
|
|
91
|
+
mint: PublicKey;
|
|
92
|
+
tokenProgram: PublicKey;
|
|
93
|
+
withdrawor: PublicKey;
|
|
94
|
+
systemProgram: PublicKey;
|
|
95
|
+
}
|
|
96
|
+
export declare const topupStreamInstruction: (amount: u64, programId: PublicKey, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }: TopupAccounts) => TransactionInstruction;
|
|
97
|
+
export {};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.withdrawStreamInstruction = exports.createStreamInstruction = void 0;
|
|
23
|
+
var buffer_1 = require("buffer");
|
|
24
|
+
var web3_js_1 = require("@solana/web3.js");
|
|
25
|
+
var js_sha256_1 = require("js-sha256");
|
|
26
|
+
var Layout = __importStar(require("./layout"));
|
|
27
|
+
var createStreamInstruction = function (data, programId, accounts) {
|
|
28
|
+
var keys = [
|
|
29
|
+
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
30
|
+
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
31
|
+
{ pubkey: accounts.recipient, isSigner: false, isWritable: true },
|
|
32
|
+
{ pubkey: accounts.metadata, isSigner: true, isWritable: true },
|
|
33
|
+
{ pubkey: accounts.escrowTokens, isSigner: false, isWritable: true },
|
|
34
|
+
{ pubkey: accounts.recipientTokens, isSigner: false, isWritable: true },
|
|
35
|
+
{
|
|
36
|
+
pubkey: accounts.streamflowTreasury,
|
|
37
|
+
isSigner: false,
|
|
38
|
+
isWritable: true,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
pubkey: accounts.streamflowTreasuryTokens,
|
|
42
|
+
isSigner: false,
|
|
43
|
+
isWritable: true,
|
|
44
|
+
},
|
|
45
|
+
{ pubkey: accounts.withdrawor, isSigner: false, isWritable: true },
|
|
46
|
+
{ pubkey: accounts.partner, isSigner: false, isWritable: true },
|
|
47
|
+
{ pubkey: accounts.partnerTokens, isSigner: false, isWritable: true },
|
|
48
|
+
{ pubkey: accounts.mint, isSigner: false, isWritable: false },
|
|
49
|
+
{ pubkey: accounts.feeOracle, isSigner: false, isWritable: false },
|
|
50
|
+
{ pubkey: accounts.rent, isSigner: false, isWritable: false },
|
|
51
|
+
{ pubkey: accounts.timelockProgram, isSigner: false, isWritable: false },
|
|
52
|
+
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
53
|
+
{
|
|
54
|
+
pubkey: accounts.associatedTokenProgram,
|
|
55
|
+
isSigner: false,
|
|
56
|
+
isWritable: false,
|
|
57
|
+
},
|
|
58
|
+
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
|
|
59
|
+
];
|
|
60
|
+
var bufferData = buffer_1.Buffer.alloc(Layout.createStreamLayout.span);
|
|
61
|
+
var encodedUIntArray = new TextEncoder().encode(data.name);
|
|
62
|
+
var streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
63
|
+
var decodedData = {
|
|
64
|
+
start_time: data.start.toBuffer(),
|
|
65
|
+
net_amount_deposited: data.depositedAmount.toBuffer(),
|
|
66
|
+
period: data.period.toBuffer(),
|
|
67
|
+
amount_per_period: data.amountPerPeriod.toBuffer(),
|
|
68
|
+
cliff: data.cliff.toBuffer(),
|
|
69
|
+
cliff_amount: data.cliffAmount.toBuffer(),
|
|
70
|
+
cancelable_by_sender: data.cancelableBySender,
|
|
71
|
+
cancelable_by_recipient: data.cancelableByRecipient,
|
|
72
|
+
automatic_withdrawal: data.automaticWithdrawal,
|
|
73
|
+
transferable_by_sender: data.transferableBySender,
|
|
74
|
+
transferable_by_recipient: data.transferableByRecipient,
|
|
75
|
+
can_topup: data.canTopup,
|
|
76
|
+
stream_name: streamNameBuffer,
|
|
77
|
+
withdraw_frequency: data.withdrawFrequency.toBuffer(),
|
|
78
|
+
};
|
|
79
|
+
var encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
|
|
80
|
+
bufferData = bufferData.slice(0, encodeLength);
|
|
81
|
+
bufferData = buffer_1.Buffer.concat([
|
|
82
|
+
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:create")).slice(0, 8),
|
|
83
|
+
bufferData,
|
|
84
|
+
]);
|
|
85
|
+
return new web3_js_1.TransactionInstruction({
|
|
86
|
+
keys: keys,
|
|
87
|
+
programId: programId,
|
|
88
|
+
data: bufferData,
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
exports.createStreamInstruction = createStreamInstruction;
|
|
92
|
+
var withdrawStreamInstruction = function (amount, programId, _a) {
|
|
93
|
+
var authority = _a.authority, recipient = _a.recipient, recipientTokens = _a.recipientTokens, metadata = _a.metadata, escrowTokens = _a.escrowTokens, streamflowTreasury = _a.streamflowTreasury, streamflowTreasuryTokens = _a.streamflowTreasuryTokens, partner = _a.partner, partnerTokens = _a.partnerTokens, mint = _a.mint, tokenProgram = _a.tokenProgram;
|
|
94
|
+
var keys = [
|
|
95
|
+
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
96
|
+
{ pubkey: recipient, isSigner: false, isWritable: true },
|
|
97
|
+
{ pubkey: recipientTokens, isSigner: false, isWritable: true },
|
|
98
|
+
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
99
|
+
{ pubkey: escrowTokens, isSigner: false, isWritable: true },
|
|
100
|
+
{
|
|
101
|
+
pubkey: streamflowTreasury,
|
|
102
|
+
isSigner: false,
|
|
103
|
+
isWritable: true,
|
|
104
|
+
},
|
|
105
|
+
{ pubkey: streamflowTreasuryTokens, isSigner: false, isWritable: true },
|
|
106
|
+
{ pubkey: partner, isSigner: false, isWritable: true },
|
|
107
|
+
{ pubkey: partnerTokens, isSigner: false, isWritable: true },
|
|
108
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
109
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
110
|
+
];
|
|
111
|
+
var data = buffer_1.Buffer.alloc(Layout.withdrawStreamLayout.span);
|
|
112
|
+
var decodedData = { amount: amount.toBuffer() };
|
|
113
|
+
var encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
|
|
114
|
+
data = data.slice(0, encodeLength);
|
|
115
|
+
data = buffer_1.Buffer.concat([
|
|
116
|
+
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:withdraw")).slice(0, 8),
|
|
117
|
+
data,
|
|
118
|
+
]);
|
|
119
|
+
return new web3_js_1.TransactionInstruction({
|
|
120
|
+
keys: keys,
|
|
121
|
+
programId: programId,
|
|
122
|
+
data: data,
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
exports.withdrawStreamInstruction = withdrawStreamInstruction;
|
|
126
|
+
var cancelStreamInstruction = function (programId, _a) {
|
|
127
|
+
var authority = _a.authority, sender = _a.sender, senderTokens = _a.senderTokens, recipient = _a.recipient, recipientTokens = _a.recipientTokens, metadata = _a.metadata, escrowTokens = _a.escrowTokens, streamflowTreasury = _a.streamflowTreasury, streamflowTreasuryTokens = _a.streamflowTreasuryTokens, partner = _a.partner, partnerTokens = _a.partnerTokens, mint = _a.mint, tokenProgram = _a.tokenProgram;
|
|
128
|
+
var keys = [
|
|
129
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
130
|
+
{ pubkey: sender, isSigner: false, isWritable: true },
|
|
131
|
+
{ pubkey: senderTokens, isSigner: false, isWritable: true },
|
|
132
|
+
{ pubkey: recipient, isSigner: false, isWritable: true },
|
|
133
|
+
{ pubkey: recipientTokens, isSigner: false, isWritable: true },
|
|
134
|
+
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
135
|
+
{ pubkey: escrowTokens, isSigner: false, isWritable: true },
|
|
136
|
+
{
|
|
137
|
+
pubkey: streamflowTreasury,
|
|
138
|
+
isSigner: false,
|
|
139
|
+
isWritable: true,
|
|
140
|
+
},
|
|
141
|
+
{ pubkey: streamflowTreasuryTokens, isSigner: false, isWritable: true },
|
|
142
|
+
{ pubkey: partner, isSigner: false, isWritable: true },
|
|
143
|
+
{ pubkey: partnerTokens, isSigner: false, isWritable: true },
|
|
144
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
145
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
146
|
+
];
|
|
147
|
+
var data = buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:cancel")).slice(0, 8);
|
|
148
|
+
return new web3_js_1.TransactionInstruction({
|
|
149
|
+
keys: keys,
|
|
150
|
+
programId: programId,
|
|
151
|
+
data: data,
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
exports.cancelStreamInstruction = cancelStreamInstruction;
|
|
155
|
+
var transferStreamInstruction = function (programId, _a) {
|
|
156
|
+
var authority = _a.authority, newRecipient = _a.newRecipient, newRecipientTokens = _a.newRecipientTokens, metadata = _a.metadata, mint = _a.mint, rent = _a.rent, tokenProgram = _a.tokenProgram, associatedTokenProgram = _a.associatedTokenProgram, systemProgram = _a.systemProgram;
|
|
157
|
+
var keys = [
|
|
158
|
+
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
159
|
+
{ pubkey: newRecipient, isSigner: false, isWritable: true },
|
|
160
|
+
{ pubkey: newRecipientTokens, isSigner: false, isWritable: true },
|
|
161
|
+
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
162
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
163
|
+
{ pubkey: rent, isSigner: false, isWritable: false },
|
|
164
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
165
|
+
{ pubkey: associatedTokenProgram, isSigner: false, isWritable: false },
|
|
166
|
+
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
167
|
+
];
|
|
168
|
+
var data = buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:transfer_recipient")).slice(0, 8);
|
|
169
|
+
return new web3_js_1.TransactionInstruction({
|
|
170
|
+
keys: keys,
|
|
171
|
+
programId: programId,
|
|
172
|
+
data: data,
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
exports.transferStreamInstruction = transferStreamInstruction;
|
|
176
|
+
var topupStreamInstruction = function (amount, programId, _a) {
|
|
177
|
+
var sender = _a.sender, senderTokens = _a.senderTokens, metadata = _a.metadata, escrowTokens = _a.escrowTokens, streamflowTreasury = _a.streamflowTreasury, streamflowTreasuryTokens = _a.streamflowTreasuryTokens, partner = _a.partner, partnerTokens = _a.partnerTokens, mint = _a.mint, tokenProgram = _a.tokenProgram, withdrawor = _a.withdrawor, systemProgram = _a.systemProgram;
|
|
178
|
+
var keys = [
|
|
179
|
+
{ pubkey: sender, isSigner: true, isWritable: true },
|
|
180
|
+
{ pubkey: senderTokens, isSigner: false, isWritable: true },
|
|
181
|
+
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
182
|
+
{ pubkey: escrowTokens, isSigner: false, isWritable: true },
|
|
183
|
+
{
|
|
184
|
+
pubkey: streamflowTreasury,
|
|
185
|
+
isSigner: false,
|
|
186
|
+
isWritable: true,
|
|
187
|
+
},
|
|
188
|
+
{ pubkey: streamflowTreasuryTokens, isSigner: false, isWritable: true },
|
|
189
|
+
{ pubkey: withdrawor, isSigner: false, isWritable: true },
|
|
190
|
+
{ pubkey: partner, isSigner: false, isWritable: true },
|
|
191
|
+
{ pubkey: partnerTokens, isSigner: false, isWritable: true },
|
|
192
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
193
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
194
|
+
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
195
|
+
];
|
|
196
|
+
var data = buffer_1.Buffer.alloc(Layout.topupStreamLayout.span);
|
|
197
|
+
var decodedData = { amount: amount.toBuffer() };
|
|
198
|
+
var encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
|
|
199
|
+
data = data.slice(0, encodeLength);
|
|
200
|
+
data = buffer_1.Buffer.concat([
|
|
201
|
+
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:topup")).slice(0, 8),
|
|
202
|
+
data,
|
|
203
|
+
]);
|
|
204
|
+
return new web3_js_1.TransactionInstruction({
|
|
205
|
+
keys: keys,
|
|
206
|
+
programId: programId,
|
|
207
|
+
data: data,
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
exports.topupStreamInstruction = topupStreamInstruction;
|
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const BufferLayout: any;
|
|
2
|
+
/**
|
|
3
|
+
* Stream layout
|
|
4
|
+
*/
|
|
5
|
+
export declare const streamLayout: typeof BufferLayout.Structure;
|
|
6
|
+
/**
|
|
7
|
+
* Create stream instruction layout
|
|
8
|
+
*/
|
|
9
|
+
export declare const createStreamLayout: typeof BufferLayout.Structure;
|
|
10
|
+
/**
|
|
11
|
+
* Withdraw stream instruction layout
|
|
12
|
+
*/
|
|
13
|
+
export declare const withdrawStreamLayout: typeof BufferLayout.Structure;
|
|
14
|
+
/**
|
|
15
|
+
* Topup stream instruction layout
|
|
16
|
+
*/
|
|
17
|
+
export declare const topupStreamLayout: typeof BufferLayout.Structure;
|
|
18
|
+
export {};
|
package/dist/layout.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.topupStreamLayout = exports.withdrawStreamLayout = exports.createStreamLayout = exports.streamLayout = void 0;
|
|
4
|
+
var BufferLayout = require("buffer-layout");
|
|
5
|
+
/**
|
|
6
|
+
* Stream layout
|
|
7
|
+
*/
|
|
8
|
+
exports.streamLayout = BufferLayout.struct([
|
|
9
|
+
BufferLayout.blob(8, "magic"),
|
|
10
|
+
BufferLayout.blob(1, "version"),
|
|
11
|
+
BufferLayout.blob(8, "created_at"),
|
|
12
|
+
BufferLayout.blob(8, "withdrawn_amount"),
|
|
13
|
+
BufferLayout.blob(8, "canceled_at"),
|
|
14
|
+
BufferLayout.blob(8, "end_time"),
|
|
15
|
+
BufferLayout.blob(8, "last_withdrawn_at"),
|
|
16
|
+
BufferLayout.blob(32, "sender"),
|
|
17
|
+
BufferLayout.blob(32, "sender_tokens"),
|
|
18
|
+
BufferLayout.blob(32, "recipient"),
|
|
19
|
+
BufferLayout.blob(32, "recipient_tokens"),
|
|
20
|
+
BufferLayout.blob(32, "mint"),
|
|
21
|
+
BufferLayout.blob(32, "escrow_tokens"),
|
|
22
|
+
BufferLayout.blob(32, "streamflow_treasury"),
|
|
23
|
+
BufferLayout.blob(32, "streamflow_treasury_tokens"),
|
|
24
|
+
BufferLayout.blob(8, "streamflow_fee_total"),
|
|
25
|
+
BufferLayout.blob(8, "streamflow_fee_withdrawn"),
|
|
26
|
+
BufferLayout.f32("streamflow_fee_percent"),
|
|
27
|
+
BufferLayout.blob(32, "partner"),
|
|
28
|
+
BufferLayout.blob(32, "partner_tokens"),
|
|
29
|
+
BufferLayout.blob(8, "partner_fee_total"),
|
|
30
|
+
BufferLayout.blob(8, "partner_fee_withdrawn"),
|
|
31
|
+
BufferLayout.f32("partner_fee_percent"),
|
|
32
|
+
BufferLayout.blob(8, "start_time"),
|
|
33
|
+
BufferLayout.blob(8, "net_amount_deposited"),
|
|
34
|
+
BufferLayout.blob(8, "period"),
|
|
35
|
+
BufferLayout.blob(8, "amount_per_period"),
|
|
36
|
+
BufferLayout.blob(8, "cliff"),
|
|
37
|
+
BufferLayout.blob(8, "cliff_amount"),
|
|
38
|
+
BufferLayout.u8("cancelable_by_sender"),
|
|
39
|
+
BufferLayout.u8("cancelable_by_recipient"),
|
|
40
|
+
BufferLayout.u8("automatic_withdrawal"),
|
|
41
|
+
BufferLayout.u8("transferable_by_sender"),
|
|
42
|
+
BufferLayout.u8("transferable_by_recipient"),
|
|
43
|
+
BufferLayout.u8("can_topup"),
|
|
44
|
+
BufferLayout.blob(64, "stream_name"),
|
|
45
|
+
BufferLayout.blob(8, "withdraw_frequency"),
|
|
46
|
+
]);
|
|
47
|
+
/**
|
|
48
|
+
* Create stream instruction layout
|
|
49
|
+
*/
|
|
50
|
+
exports.createStreamLayout = BufferLayout.struct([
|
|
51
|
+
BufferLayout.blob(8, "start_time"),
|
|
52
|
+
BufferLayout.blob(8, "net_amount_deposited"),
|
|
53
|
+
BufferLayout.blob(8, "period"),
|
|
54
|
+
BufferLayout.blob(8, "amount_per_period"),
|
|
55
|
+
BufferLayout.blob(8, "cliff"),
|
|
56
|
+
BufferLayout.blob(8, "cliff_amount"),
|
|
57
|
+
BufferLayout.u8("cancelable_by_sender"),
|
|
58
|
+
BufferLayout.u8("cancelable_by_recipient"),
|
|
59
|
+
BufferLayout.u8("automatic_withdrawal"),
|
|
60
|
+
BufferLayout.u8("transferable_by_sender"),
|
|
61
|
+
BufferLayout.u8("transferable_by_recipient"),
|
|
62
|
+
BufferLayout.u8("can_topup"),
|
|
63
|
+
BufferLayout.blob(64, "stream_name"),
|
|
64
|
+
BufferLayout.blob(8, "withdraw_frequency"),
|
|
65
|
+
]);
|
|
66
|
+
/**
|
|
67
|
+
* Withdraw stream instruction layout
|
|
68
|
+
*/
|
|
69
|
+
exports.withdrawStreamLayout = BufferLayout.struct([BufferLayout.blob(8, "amount")]);
|
|
70
|
+
/**
|
|
71
|
+
* Topup stream instruction layout
|
|
72
|
+
*/
|
|
73
|
+
exports.topupStreamLayout = BufferLayout.struct([BufferLayout.blob(8, "amount")]);
|
package/dist/sdk.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { web3 } from "@project-serum/anchor";
|
|
2
|
+
import { Commitment, ConnectionConfig } from "@solana/web3.js";
|
|
3
|
+
import { Stream as StreamData, CreateStreamParams, WithdrawStreamParams, TopupStreamParams, CancelStreamParams, TransferStreamParams, ClusterExtended, GetStreamParams, GetStreamsParams, CreateStreamResponse, TransactionResponse } from "./types";
|
|
4
|
+
export default class Stream {
|
|
5
|
+
private connection;
|
|
6
|
+
private cluster;
|
|
7
|
+
private programId;
|
|
8
|
+
private commitment;
|
|
9
|
+
/**
|
|
10
|
+
* Create Stream instance
|
|
11
|
+
*/
|
|
12
|
+
constructor(clusterUrl: string, cluster?: ClusterExtended, commitment?: Commitment | ConnectionConfig);
|
|
13
|
+
getConnection(): web3.Connection;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new stream/vesting contract.
|
|
16
|
+
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
17
|
+
* @param {CreateStreamParams} data
|
|
18
|
+
* @param {Wallet} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
|
|
19
|
+
* @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
|
|
20
|
+
* @param {string} data.mint - SPL Token mint.
|
|
21
|
+
* @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
|
|
22
|
+
* @param {u64} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
|
|
23
|
+
* @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
|
|
24
|
+
* @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
|
|
25
|
+
* @param {u64} data.cliffAmount - Amount unlocked at the "cliff".
|
|
26
|
+
* @param {u64} data.amountPerPeriod - Amount unlocked per each period.
|
|
27
|
+
* @param {string} data.name - Stream name/subject.
|
|
28
|
+
* @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
|
|
29
|
+
* @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
|
|
30
|
+
* @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
|
|
31
|
+
* @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
|
|
32
|
+
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
33
|
+
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
34
|
+
* @param {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
35
|
+
*/
|
|
36
|
+
create({ sender, recipient, mint, start, depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, partner, }: CreateStreamParams): Promise<CreateStreamResponse>;
|
|
37
|
+
/**
|
|
38
|
+
* Attempts withdrawal from the specified stream.
|
|
39
|
+
* @param {WithdrawStreamParams} data
|
|
40
|
+
* @param {Wallet} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (recipient) or transaction will fail.
|
|
41
|
+
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be withdrawn from.
|
|
42
|
+
* @param {u64} data.amount - Requested amount (in the smallest units) to withdraw (while streaming). If stream is completed, the whole amount will be withdrawn.
|
|
43
|
+
*/
|
|
44
|
+
withdraw({ invoker, id, amount, }: WithdrawStreamParams): Promise<TransactionResponse>;
|
|
45
|
+
/**
|
|
46
|
+
* Attempts canceling the specified stream.
|
|
47
|
+
* @param {CancelStreamParams} data
|
|
48
|
+
* @param {Wallet} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
|
|
49
|
+
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be canceled.
|
|
50
|
+
*/
|
|
51
|
+
cancel({ invoker, id, }: CancelStreamParams): Promise<TransactionResponse>;
|
|
52
|
+
/**
|
|
53
|
+
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
54
|
+
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
|
|
55
|
+
* @param {TransferStreamParams} data
|
|
56
|
+
* @param {Wallet} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
|
|
57
|
+
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be transferred.
|
|
58
|
+
* @param {string} data.recipientId - Address of a new recipient.
|
|
59
|
+
*/
|
|
60
|
+
transfer({ invoker, id, recipientId, }: TransferStreamParams): Promise<TransactionResponse>;
|
|
61
|
+
/**
|
|
62
|
+
* Tops up stream account deposited amount.
|
|
63
|
+
* @param {TopupStreamParams} data
|
|
64
|
+
* @param {Wallet} data.invoker - Wallet signing the transaction. It's address should match current stream sender or transaction will fail.
|
|
65
|
+
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be topped up.
|
|
66
|
+
* @param {u64} data.amount - Specified amount (in the smallest units) to topup (increases deposited amount).
|
|
67
|
+
*/
|
|
68
|
+
topup({ invoker, id, amount, }: TopupStreamParams): Promise<TransactionResponse>;
|
|
69
|
+
/**
|
|
70
|
+
* Fetch stream data by its id (address).
|
|
71
|
+
* @param {GetStreamParams} data
|
|
72
|
+
* @param {Connection} data.connection - A connection to the cluster.
|
|
73
|
+
* @param {string} data.id - Identifier of a stream that is fetched.
|
|
74
|
+
*/
|
|
75
|
+
getOne({ id }: GetStreamParams): Promise<StreamData>;
|
|
76
|
+
/**
|
|
77
|
+
* Fetch streams/contracts by providing direction.
|
|
78
|
+
* Streams are sorted by start time in ascending order.
|
|
79
|
+
* @param {GetStreamsParams} data
|
|
80
|
+
* @param {PublicKey} data.wallet - PublicKey of the wallet for which the streams/contracts are fetched.
|
|
81
|
+
* @param {StreamType} [data.type = StreamType.All] - It can be one of: stream, vesting, all.
|
|
82
|
+
* @param {StreamDirection} [data.direction = StreamDirection.All] - It can be one of: incoming, outgoing, all.
|
|
83
|
+
*/
|
|
84
|
+
get({ wallet, type, direction, }: GetStreamsParams): Promise<[string, StreamData][]>;
|
|
85
|
+
}
|