@streamflow/stream 2.2.2 → 3.0.0-test.2
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 +140 -101
- package/dist/{sdk.d.ts → Stream.d.ts} +2 -2
- package/dist/{sdk.js → Stream.js} +10 -25
- package/dist/StreamClient.d.ts +107 -0
- package/dist/StreamClient.js +750 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +3 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +8 -5
- 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/types.d.ts +59 -4
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +29 -68
- package/package.json +1 -1
package/dist/constants.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export declare const PROGRAM_ID: {
|
|
|
8
8
|
testnet: string;
|
|
9
9
|
local: string;
|
|
10
10
|
};
|
|
11
|
+
export declare const STREAMFLOW_PROGRAM_ID = "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m";
|
|
12
|
+
export declare const STREAMFLOW_DEVNET_PROGRAM_ID = "FGjLaVo5zLGdzCxMo9gu9tXr1kzTToKd8C8K7YS5hNM1";
|
|
11
13
|
export declare const STREAMFLOW_TREASURY_PUBLIC_KEY: PublicKey;
|
|
12
14
|
export declare const WITHDRAWOR_PUBLIC_KEY: PublicKey;
|
|
13
15
|
export declare const FEE_ORACLE_PUBLIC_KEY: PublicKey;
|
package/dist/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.PROGRAM_ID = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
|
|
4
|
+
exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.STREAMFLOW_DEVNET_PROGRAM_ID = exports.STREAMFLOW_PROGRAM_ID = exports.PROGRAM_ID = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
|
|
5
5
|
var web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
var types_1 = require("./types");
|
|
7
7
|
exports.TX_FINALITY_CONFIRMED = "confirmed";
|
|
@@ -13,6 +13,8 @@ exports.PROGRAM_ID = (_a = {},
|
|
|
13
13
|
_a[types_1.Cluster.Testnet] = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
|
|
14
14
|
_a[types_1.LocalCluster.Local] = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
|
|
15
15
|
_a);
|
|
16
|
+
exports.STREAMFLOW_PROGRAM_ID = "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m";
|
|
17
|
+
exports.STREAMFLOW_DEVNET_PROGRAM_ID = "FGjLaVo5zLGdzCxMo9gu9tXr1kzTToKd8C8K7YS5hNM1";
|
|
16
18
|
exports.STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js_1.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
|
|
17
19
|
exports.WITHDRAWOR_PUBLIC_KEY = new web3_js_1.PublicKey("wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u");
|
|
18
20
|
exports.FEE_ORACLE_PUBLIC_KEY = new web3_js_1.PublicKey("B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT");
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { default } from "./
|
|
1
|
+
export { default } from "./Stream";
|
|
2
|
+
export { default as StreamClient } from "./StreamClient";
|
|
2
3
|
export * from "./utils";
|
|
3
4
|
export * from "./types";
|
|
4
|
-
export
|
|
5
|
+
export * from "./instructions";
|
|
6
|
+
export { default as BN } from "bn.js";
|
package/dist/index.js
CHANGED
|
@@ -13,10 +13,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.BN = exports.default = void 0;
|
|
17
|
-
var
|
|
18
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(
|
|
16
|
+
exports.BN = exports.StreamClient = exports.default = void 0;
|
|
17
|
+
var Stream_1 = require("./Stream");
|
|
18
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(Stream_1).default; } });
|
|
19
|
+
var StreamClient_1 = require("./StreamClient");
|
|
20
|
+
Object.defineProperty(exports, "StreamClient", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
|
|
19
21
|
__exportStar(require("./utils"), exports);
|
|
20
22
|
__exportStar(require("./types"), exports);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
__exportStar(require("./instructions"), exports);
|
|
24
|
+
var bn_js_1 = require("bn.js");
|
|
25
|
+
Object.defineProperty(exports, "BN", { enumerable: true, get: function () { return __importDefault(bn_js_1).default; } });
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import BN from "bn.js";
|
|
3
|
+
interface CreateStreamData {
|
|
4
|
+
start: BN;
|
|
5
|
+
depositedAmount: BN;
|
|
6
|
+
period: BN;
|
|
7
|
+
amountPerPeriod: BN;
|
|
8
|
+
cliff: BN;
|
|
9
|
+
cliffAmount: BN;
|
|
10
|
+
cancelableBySender: boolean;
|
|
11
|
+
cancelableByRecipient: boolean;
|
|
12
|
+
automaticWithdrawal: boolean;
|
|
13
|
+
transferableBySender: boolean;
|
|
14
|
+
transferableByRecipient: boolean;
|
|
15
|
+
canTopup: boolean;
|
|
16
|
+
name: string;
|
|
17
|
+
withdrawFrequency: BN;
|
|
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: BN, 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: BN, 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/types.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="bn.js" />
|
|
3
|
-
import { BN } from "@project-serum/anchor";
|
|
4
2
|
import { Wallet } from "@project-serum/anchor/src/provider";
|
|
5
3
|
import { WalletAdapterNetwork } from "@solana/wallet-adapter-base";
|
|
6
|
-
import { AccountInfo, Connection, PublicKey, TransactionSignature } from "@solana/web3.js";
|
|
4
|
+
import { AccountInfo, Connection, PublicKey, Keypair, TransactionSignature, TransactionInstruction } from "@solana/web3.js";
|
|
5
|
+
import BN from "bn.js";
|
|
7
6
|
export { WalletAdapterNetwork as Cluster } from "@solana/wallet-adapter-base";
|
|
8
7
|
export declare enum StreamDirection {
|
|
9
8
|
Outgoing = "outgoing",
|
|
@@ -41,12 +40,41 @@ export interface CreateStreamData {
|
|
|
41
40
|
automaticWithdrawal?: boolean;
|
|
42
41
|
withdrawalFrequency?: number;
|
|
43
42
|
}
|
|
43
|
+
export interface MultiRecipient {
|
|
44
|
+
recipient: string;
|
|
45
|
+
depositedAmount: BN;
|
|
46
|
+
name: string;
|
|
47
|
+
}
|
|
48
|
+
export interface CreateMultiData {
|
|
49
|
+
recipientsData: MultiRecipient[];
|
|
50
|
+
mint: string;
|
|
51
|
+
start: number;
|
|
52
|
+
period: number;
|
|
53
|
+
cliff: number;
|
|
54
|
+
cliffAmount: BN;
|
|
55
|
+
amountPerPeriod: BN;
|
|
56
|
+
canTopup: boolean;
|
|
57
|
+
cancelableBySender: boolean;
|
|
58
|
+
cancelableByRecipient: boolean;
|
|
59
|
+
transferableBySender: boolean;
|
|
60
|
+
transferableByRecipient: boolean;
|
|
61
|
+
automaticWithdrawal?: boolean;
|
|
62
|
+
withdrawalFrequency?: number;
|
|
63
|
+
}
|
|
44
64
|
export interface CreateStreamParams extends CreateStreamData {
|
|
45
65
|
connection: Connection;
|
|
46
66
|
sender: Wallet;
|
|
47
67
|
partner?: string;
|
|
48
68
|
cluster?: ClusterExtended;
|
|
49
69
|
}
|
|
70
|
+
export interface CreateParams extends CreateStreamData {
|
|
71
|
+
sender: Wallet | Keypair;
|
|
72
|
+
partner?: string | null;
|
|
73
|
+
}
|
|
74
|
+
export interface CreateMultiParams extends CreateMultiData {
|
|
75
|
+
sender: Wallet | Keypair;
|
|
76
|
+
partner?: string | null;
|
|
77
|
+
}
|
|
50
78
|
export interface WithdrawStreamData {
|
|
51
79
|
id: string;
|
|
52
80
|
amount: BN;
|
|
@@ -56,6 +84,9 @@ export interface WithdrawStreamParams extends WithdrawStreamData {
|
|
|
56
84
|
invoker: Wallet;
|
|
57
85
|
cluster?: ClusterExtended;
|
|
58
86
|
}
|
|
87
|
+
export interface WithdrawParams extends WithdrawStreamData {
|
|
88
|
+
invoker: Wallet;
|
|
89
|
+
}
|
|
59
90
|
export interface TopupStreamData {
|
|
60
91
|
id: string;
|
|
61
92
|
amount: BN;
|
|
@@ -65,6 +96,9 @@ export interface TopupStreamParams extends TopupStreamData {
|
|
|
65
96
|
invoker: Wallet;
|
|
66
97
|
cluster?: ClusterExtended;
|
|
67
98
|
}
|
|
99
|
+
export interface TopupParams extends TopupStreamData {
|
|
100
|
+
invoker: Wallet;
|
|
101
|
+
}
|
|
68
102
|
export interface CancelStreamData {
|
|
69
103
|
id: string;
|
|
70
104
|
}
|
|
@@ -73,6 +107,9 @@ export interface CancelStreamParams extends CancelStreamData {
|
|
|
73
107
|
invoker: Wallet;
|
|
74
108
|
cluster?: ClusterExtended;
|
|
75
109
|
}
|
|
110
|
+
export interface CancelParams extends CancelStreamData {
|
|
111
|
+
invoker: Wallet;
|
|
112
|
+
}
|
|
76
113
|
export interface TransferStreamData {
|
|
77
114
|
id: string;
|
|
78
115
|
recipientId: string;
|
|
@@ -82,6 +119,9 @@ export interface TransferStreamParams extends TransferStreamData {
|
|
|
82
119
|
invoker: Wallet;
|
|
83
120
|
cluster?: ClusterExtended;
|
|
84
121
|
}
|
|
122
|
+
export interface TransferParams extends TransferStreamData {
|
|
123
|
+
invoker: Wallet;
|
|
124
|
+
}
|
|
85
125
|
export interface GetStreamParams {
|
|
86
126
|
connection: Connection;
|
|
87
127
|
id: string;
|
|
@@ -93,6 +133,11 @@ export interface GetStreamsParams {
|
|
|
93
133
|
direction?: StreamDirection;
|
|
94
134
|
cluster?: ClusterExtended;
|
|
95
135
|
}
|
|
136
|
+
export interface GetAllParams {
|
|
137
|
+
wallet: PublicKey;
|
|
138
|
+
type?: StreamType;
|
|
139
|
+
direction?: StreamDirection;
|
|
140
|
+
}
|
|
96
141
|
export interface Stream {
|
|
97
142
|
magic: number;
|
|
98
143
|
version: number;
|
|
@@ -169,7 +214,7 @@ export interface DecodedStream {
|
|
|
169
214
|
transferableByRecipient: boolean;
|
|
170
215
|
canTopup: boolean;
|
|
171
216
|
name: string;
|
|
172
|
-
|
|
217
|
+
withdrawFrequency: BN;
|
|
173
218
|
}
|
|
174
219
|
export interface TransactionResponse {
|
|
175
220
|
tx: TransactionSignature;
|
|
@@ -177,3 +222,13 @@ export interface TransactionResponse {
|
|
|
177
222
|
export interface CreateStreamResponse extends TransactionResponse {
|
|
178
223
|
id: string;
|
|
179
224
|
}
|
|
225
|
+
export interface TxResponse {
|
|
226
|
+
ixs: TransactionInstruction[];
|
|
227
|
+
tx: TransactionSignature;
|
|
228
|
+
}
|
|
229
|
+
export interface CreateResponse extends TxResponse {
|
|
230
|
+
metadata: Keypair;
|
|
231
|
+
}
|
|
232
|
+
export interface CreateMultiResponse {
|
|
233
|
+
txs: TransactionSignature[];
|
|
234
|
+
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import
|
|
2
|
+
import BN from "bn.js";
|
|
3
3
|
import { Stream, DecodedStream } from "./types";
|
|
4
4
|
export declare const decodeStream: (buf: Buffer) => DecodedStream;
|
|
5
5
|
export declare const formatDecodedStream: (stream: DecodedStream) => Stream;
|