@streamflow/stream 7.0.0-alpha.2 → 7.0.0-alpha.20
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 +70 -67
- package/dist/cjs/__tests__/aptos/streamClient.spec.js +83 -134
- package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +9 -9
- package/dist/cjs/aptos/StreamClient.js +162 -367
- package/dist/cjs/aptos/constants.js +7 -8
- package/dist/cjs/aptos/index.js +3 -3
- package/dist/cjs/aptos/types.js +28 -37
- package/dist/cjs/aptos/utils.js +4 -4
- package/dist/cjs/aptos/wallet.js +20 -75
- package/dist/cjs/common/BaseStreamClient.js +11 -59
- package/dist/cjs/common/GenericStreamClient.js +46 -72
- package/dist/cjs/common/constants.js +4 -3
- package/dist/cjs/common/contractUtils.js +33 -18
- package/dist/cjs/common/types.js +30 -1
- package/dist/cjs/common/utils.js +38 -80
- package/dist/cjs/evm/StreamClient.js +198 -456
- package/dist/cjs/evm/constants.js +19 -20
- package/dist/cjs/evm/types.js +25 -34
- package/dist/cjs/evm/utils.js +2 -2
- package/dist/cjs/index.js +10 -10
- package/dist/cjs/solana/StreamClient.js +759 -1090
- package/dist/cjs/solana/constants.js +44 -11
- package/dist/cjs/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.js +2 -0
- package/dist/cjs/solana/index.js +2 -1
- package/dist/cjs/solana/instructions.js +75 -81
- package/dist/cjs/solana/layout.js +7 -8
- package/dist/cjs/solana/lib/derive-accounts.js +17 -0
- package/dist/cjs/solana/lib/utils.js +127 -0
- package/dist/cjs/solana/types.js +40 -27
- package/dist/cjs/sui/StreamClient.js +325 -571
- package/dist/cjs/sui/constants.js +19 -20
- package/dist/cjs/sui/types.js +28 -62
- package/dist/cjs/sui/utils.js +7 -7
- package/dist/cjs/sui/wallet.js +13 -63
- package/dist/esm/__tests__/aptos/streamClient.spec.js +4 -4
- package/dist/esm/aptos/index.d.ts +3 -3
- package/dist/esm/aptos/index.js +3 -3
- package/dist/esm/aptos/types.d.ts +14 -14
- package/dist/esm/aptos/types.js +13 -13
- package/dist/esm/common/GenericStreamClient.d.ts +4 -4
- package/dist/esm/common/GenericStreamClient.js +4 -4
- package/dist/esm/common/constants.d.ts +3 -2
- package/dist/esm/common/constants.js +3 -2
- package/dist/esm/common/contractUtils.d.ts +18 -15
- package/dist/esm/common/contractUtils.js +19 -6
- package/dist/esm/common/types.d.ts +112 -57
- package/dist/esm/common/types.js +29 -0
- package/dist/esm/common/utils.d.ts +11 -11
- package/dist/esm/common/utils.js +19 -16
- package/dist/esm/evm/StreamClient.d.ts +2 -2
- package/dist/esm/evm/StreamClient.js +7 -7
- package/dist/esm/evm/types.d.ts +14 -14
- package/dist/esm/evm/types.js +13 -13
- package/dist/esm/index.d.ts +9 -9
- package/dist/esm/index.js +9 -9
- package/dist/esm/solana/StreamClient.d.ts +24 -16
- package/dist/esm/solana/StreamClient.js +324 -156
- package/dist/esm/solana/constants.d.ts +17 -0
- package/dist/esm/solana/constants.js +35 -1
- package/dist/esm/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.d.ts +1272 -0
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js +1 -0
- package/dist/esm/solana/index.d.ts +2 -1
- package/dist/esm/solana/index.js +2 -1
- package/dist/esm/solana/instructions.d.ts +17 -17
- package/dist/esm/solana/instructions.js +18 -19
- package/dist/esm/solana/lib/derive-accounts.d.ts +4 -0
- package/dist/esm/solana/lib/derive-accounts.js +11 -0
- package/dist/esm/solana/{utils.d.ts → lib/utils.d.ts} +1 -3
- package/dist/esm/solana/{utils.js → lib/utils.js} +28 -34
- package/dist/esm/solana/types.d.ts +72 -39
- package/dist/esm/solana/types.js +32 -4
- package/dist/esm/sui/StreamClient.js +1 -1
- package/dist/esm/sui/types.d.ts +14 -14
- package/dist/esm/sui/types.js +13 -13
- package/package.json +12 -10
- package/dist/cjs/solana/utils.js +0 -222
package/dist/cjs/solana/index.js
CHANGED
|
@@ -31,7 +31,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.timelockIDL = exports.constants = void 0;
|
|
33
33
|
__exportStar(require("./StreamClient.js"), exports);
|
|
34
|
-
__exportStar(require("./utils.js"), exports);
|
|
34
|
+
__exportStar(require("./lib/utils.js"), exports);
|
|
35
|
+
__exportStar(require("./lib/derive-accounts.js"), exports);
|
|
35
36
|
__exportStar(require("./types.js"), exports);
|
|
36
37
|
__exportStar(require("./instructions.js"), exports);
|
|
37
38
|
exports.constants = __importStar(require("./constants.js"));
|
|
@@ -24,17 +24,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.updateStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
digest: function (data) { return new Uint8Array(hasher().update(data).digest()); },
|
|
27
|
+
const buffer_1 = require("buffer");
|
|
28
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
29
|
+
const node_crypto_1 = require("node:crypto");
|
|
30
|
+
const Layout = __importStar(require("./layout.js"));
|
|
31
|
+
const hasher = () => (0, node_crypto_1.createHash)("sha256");
|
|
32
|
+
const sha256 = {
|
|
33
|
+
digest: (data) => new Uint8Array(hasher().update(data).digest()),
|
|
35
34
|
};
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const createStreamInstruction = (data, programId, accounts) => {
|
|
36
|
+
const keys = [
|
|
38
37
|
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
39
38
|
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
40
39
|
{ pubkey: accounts.recipient, isSigner: false, isWritable: true },
|
|
@@ -66,16 +65,16 @@ var createStreamInstruction = function (data, programId, accounts) {
|
|
|
66
65
|
},
|
|
67
66
|
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
|
|
68
67
|
];
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
start_time: (
|
|
74
|
-
net_amount_deposited: (
|
|
75
|
-
period: (
|
|
76
|
-
amount_per_period: (
|
|
77
|
-
cliff: (
|
|
78
|
-
cliff_amount: (
|
|
68
|
+
let bufferData = buffer_1.Buffer.alloc(Layout.createStreamLayout.span);
|
|
69
|
+
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
70
|
+
const streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
71
|
+
const decodedData = {
|
|
72
|
+
start_time: data.start.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
73
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
74
|
+
period: data.period.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
75
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
76
|
+
cliff: data.cliff.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
77
|
+
cliff_amount: data.cliffAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
79
78
|
cancelable_by_sender: Number(data.cancelableBySender),
|
|
80
79
|
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
81
80
|
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
@@ -87,20 +86,20 @@ var createStreamInstruction = function (data, programId, accounts) {
|
|
|
87
86
|
_can_update_rate_discriminator: 1,
|
|
88
87
|
pausable: Number(data.canPause),
|
|
89
88
|
stream_name: streamNameBuffer,
|
|
90
|
-
withdraw_frequency: (
|
|
89
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
91
90
|
};
|
|
92
|
-
|
|
91
|
+
const encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
|
|
93
92
|
bufferData = bufferData.slice(0, encodeLength);
|
|
94
93
|
bufferData = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:create")).slice(0, 8), bufferData, buffer_1.Buffer.alloc(10)]);
|
|
95
94
|
return new web3_js_1.TransactionInstruction({
|
|
96
|
-
keys
|
|
97
|
-
programId
|
|
95
|
+
keys,
|
|
96
|
+
programId,
|
|
98
97
|
data: bufferData,
|
|
99
98
|
});
|
|
100
99
|
};
|
|
101
100
|
exports.createStreamInstruction = createStreamInstruction;
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
const createUncheckedStreamInstruction = (data, programId, accounts) => {
|
|
102
|
+
const keys = [
|
|
104
103
|
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
105
104
|
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
106
105
|
{ pubkey: accounts.metadata, isSigner: false, isWritable: true },
|
|
@@ -120,16 +119,16 @@ var createUncheckedStreamInstruction = function (data, programId, accounts) {
|
|
|
120
119
|
isWritable: true,
|
|
121
120
|
});
|
|
122
121
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
start_time: (
|
|
128
|
-
net_amount_deposited: (
|
|
129
|
-
period: (
|
|
130
|
-
amount_per_period: (
|
|
131
|
-
cliff: (
|
|
132
|
-
cliff_amount: (
|
|
122
|
+
let bufferData = buffer_1.Buffer.alloc(Layout.createUncheckedStreamLayout.span);
|
|
123
|
+
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
124
|
+
const streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
125
|
+
const decodedData = {
|
|
126
|
+
start_time: data.start.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
127
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
128
|
+
period: data.period.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
129
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
130
|
+
cliff: data.cliff.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
131
|
+
cliff_amount: data.cliffAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
133
132
|
cancelable_by_sender: Number(data.cancelableBySender),
|
|
134
133
|
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
135
134
|
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
@@ -137,28 +136,27 @@ var createUncheckedStreamInstruction = function (data, programId, accounts) {
|
|
|
137
136
|
transferable_by_recipient: Number(data.transferableByRecipient),
|
|
138
137
|
can_topup: Number(data.canTopup),
|
|
139
138
|
stream_name: streamNameBuffer,
|
|
140
|
-
withdraw_frequency: (
|
|
139
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
141
140
|
recipient: data.recipient.toBuffer(),
|
|
142
141
|
partner: data.partner.toBuffer(),
|
|
143
142
|
pausable: Number(data.canPause),
|
|
144
143
|
can_update_rate: Number(data.canUpdateRate),
|
|
145
144
|
};
|
|
146
|
-
|
|
145
|
+
const encodeLength = Layout.createUncheckedStreamLayout.encode(decodedData, bufferData);
|
|
147
146
|
bufferData = bufferData.slice(0, encodeLength);
|
|
148
|
-
|
|
147
|
+
const digest = accounts.payer
|
|
149
148
|
? sha256.digest("global:create_unchecked_with_payer")
|
|
150
149
|
: sha256.digest("global:create_unchecked");
|
|
151
150
|
bufferData = buffer_1.Buffer.concat([buffer_1.Buffer.from(digest).slice(0, 8), bufferData, buffer_1.Buffer.alloc(10)]);
|
|
152
151
|
return new web3_js_1.TransactionInstruction({
|
|
153
|
-
keys
|
|
154
|
-
programId
|
|
152
|
+
keys,
|
|
153
|
+
programId,
|
|
155
154
|
data: bufferData,
|
|
156
155
|
});
|
|
157
156
|
};
|
|
158
157
|
exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
var keys = [
|
|
158
|
+
const withdrawStreamInstruction = (amount, programId, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }) => {
|
|
159
|
+
const keys = [
|
|
162
160
|
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
163
161
|
{ pubkey: recipient, isSigner: false, isWritable: true },
|
|
164
162
|
{ pubkey: recipientTokens, isSigner: false, isWritable: true },
|
|
@@ -175,33 +173,32 @@ var withdrawStreamInstruction = function (amount, programId, _a) {
|
|
|
175
173
|
{ pubkey: mint, isSigner: false, isWritable: true },
|
|
176
174
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
177
175
|
];
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
176
|
+
let data = buffer_1.Buffer.alloc(Layout.withdrawStreamLayout.span);
|
|
177
|
+
const decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
|
|
178
|
+
const encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
|
|
181
179
|
data = data.slice(0, encodeLength);
|
|
182
180
|
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:withdraw")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
|
|
183
181
|
return new web3_js_1.TransactionInstruction({
|
|
184
|
-
keys
|
|
185
|
-
programId
|
|
186
|
-
data
|
|
182
|
+
keys,
|
|
183
|
+
programId,
|
|
184
|
+
data,
|
|
187
185
|
});
|
|
188
186
|
};
|
|
189
187
|
exports.withdrawStreamInstruction = withdrawStreamInstruction;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
var keys = [
|
|
188
|
+
const updateStreamInstruction = (params, programId, { authority, metadata, withdrawor, systemProgram }) => {
|
|
189
|
+
const keys = [
|
|
193
190
|
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
194
191
|
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
195
192
|
{ pubkey: withdrawor, isSigner: false, isWritable: true },
|
|
196
193
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
197
194
|
];
|
|
198
|
-
|
|
199
|
-
|
|
195
|
+
let data = buffer_1.Buffer.alloc(100);
|
|
196
|
+
const decodedData = {
|
|
200
197
|
enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
|
|
201
|
-
withdraw_frequency: params.withdrawFrequency ? (
|
|
202
|
-
amount_per_period: params.amountPerPeriod ? (
|
|
198
|
+
withdraw_frequency: params.withdrawFrequency ? params.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8) : undefined,
|
|
199
|
+
amount_per_period: params.amountPerPeriod ? params.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8) : undefined,
|
|
203
200
|
};
|
|
204
|
-
|
|
201
|
+
const encodeLength = Layout.encodeUpdateStream(decodedData, data);
|
|
205
202
|
data = data.slice(0, encodeLength);
|
|
206
203
|
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:update")).slice(0, 8), data, buffer_1.Buffer.alloc(20)]);
|
|
207
204
|
return new web3_js_1.TransactionInstruction({
|
|
@@ -211,9 +208,8 @@ var updateStreamInstruction = function (params, programId, _a) {
|
|
|
211
208
|
});
|
|
212
209
|
};
|
|
213
210
|
exports.updateStreamInstruction = updateStreamInstruction;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
var keys = [
|
|
211
|
+
const cancelStreamInstruction = (programId, { authority, sender, senderTokens, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }) => {
|
|
212
|
+
const keys = [
|
|
217
213
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
218
214
|
{ pubkey: sender, isSigner: false, isWritable: true },
|
|
219
215
|
{ pubkey: senderTokens, isSigner: false, isWritable: true },
|
|
@@ -232,17 +228,16 @@ var cancelStreamInstruction = function (programId, _a) {
|
|
|
232
228
|
{ pubkey: mint, isSigner: false, isWritable: true },
|
|
233
229
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
234
230
|
];
|
|
235
|
-
|
|
231
|
+
const data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:cancel")).slice(0, 8), buffer_1.Buffer.alloc(10)]);
|
|
236
232
|
return new web3_js_1.TransactionInstruction({
|
|
237
|
-
keys
|
|
238
|
-
programId
|
|
239
|
-
data
|
|
233
|
+
keys,
|
|
234
|
+
programId,
|
|
235
|
+
data,
|
|
240
236
|
});
|
|
241
237
|
};
|
|
242
238
|
exports.cancelStreamInstruction = cancelStreamInstruction;
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
var keys = [
|
|
239
|
+
const transferStreamInstruction = (programId, { authority, newRecipient, newRecipientTokens, metadata, mint, rent, tokenProgram, associatedTokenProgram, systemProgram, }) => {
|
|
240
|
+
const keys = [
|
|
246
241
|
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
247
242
|
{ pubkey: newRecipient, isSigner: false, isWritable: true },
|
|
248
243
|
{ pubkey: newRecipientTokens, isSigner: false, isWritable: true },
|
|
@@ -253,17 +248,16 @@ var transferStreamInstruction = function (programId, _a) {
|
|
|
253
248
|
{ pubkey: associatedTokenProgram, isSigner: false, isWritable: false },
|
|
254
249
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
255
250
|
];
|
|
256
|
-
|
|
251
|
+
const data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:transfer_recipient")).slice(0, 8), buffer_1.Buffer.alloc(10)]);
|
|
257
252
|
return new web3_js_1.TransactionInstruction({
|
|
258
|
-
keys
|
|
259
|
-
programId
|
|
260
|
-
data
|
|
253
|
+
keys,
|
|
254
|
+
programId,
|
|
255
|
+
data,
|
|
261
256
|
});
|
|
262
257
|
};
|
|
263
258
|
exports.transferStreamInstruction = transferStreamInstruction;
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
var keys = [
|
|
259
|
+
const topupStreamInstruction = (amount, programId, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }) => {
|
|
260
|
+
const keys = [
|
|
267
261
|
{ pubkey: sender, isSigner: true, isWritable: true },
|
|
268
262
|
{ pubkey: senderTokens, isSigner: false, isWritable: true },
|
|
269
263
|
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
@@ -281,15 +275,15 @@ var topupStreamInstruction = function (amount, programId, _a) {
|
|
|
281
275
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
282
276
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
283
277
|
];
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
278
|
+
let data = buffer_1.Buffer.alloc(Layout.topupStreamLayout.span);
|
|
279
|
+
const decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
|
|
280
|
+
const encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
|
|
287
281
|
data = data.slice(0, encodeLength);
|
|
288
282
|
data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:topup")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
|
|
289
283
|
return new web3_js_1.TransactionInstruction({
|
|
290
|
-
keys
|
|
291
|
-
programId
|
|
292
|
-
data
|
|
284
|
+
keys,
|
|
285
|
+
programId,
|
|
286
|
+
data,
|
|
293
287
|
});
|
|
294
288
|
};
|
|
295
289
|
exports.topupStreamInstruction = topupStreamInstruction;
|
|
@@ -24,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.topupStreamLayout = exports.encodeUpdateStream = exports.withdrawStreamLayout = exports.createUncheckedStreamLayout = exports.createStreamLayout = exports.partnerLayout = exports.streamLayout = void 0;
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const BufferLayout = __importStar(require("@solana/buffer-layout"));
|
|
28
|
+
const constants_js_1 = require("./constants.js");
|
|
29
29
|
/**
|
|
30
30
|
* Stream layout
|
|
31
31
|
*/
|
|
@@ -141,9 +141,8 @@ exports.withdrawStreamLayout = BufferLayout.struct([
|
|
|
141
141
|
/**
|
|
142
142
|
* Encode stream instruction layout
|
|
143
143
|
*/
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
var structs = [];
|
|
144
|
+
const encodeUpdateStream = (values, data) => {
|
|
145
|
+
const structs = [];
|
|
147
146
|
if (values.enable_automatic_withdrawal) {
|
|
148
147
|
structs.push(BufferLayout.u8("enable_automatic_withdrawal_exists"));
|
|
149
148
|
structs.push(BufferLayout.u8("enable_automatic_withdrawal"));
|
|
@@ -167,11 +166,11 @@ var encodeUpdateStream = function (values, data) {
|
|
|
167
166
|
}
|
|
168
167
|
return BufferLayout.struct(structs).encode({
|
|
169
168
|
enable_automatic_withdrawal_exists: values.enable_automatic_withdrawal ? 1 : 0,
|
|
170
|
-
enable_automatic_withdrawal:
|
|
169
|
+
enable_automatic_withdrawal: values.enable_automatic_withdrawal ?? 0,
|
|
171
170
|
withdraw_frequency_exists: values.withdraw_frequency ? 1 : 0,
|
|
172
|
-
withdraw_frequency:
|
|
171
|
+
withdraw_frequency: values.withdraw_frequency ?? 0,
|
|
173
172
|
amount_per_period_exists: values.amount_per_period ? 1 : 0,
|
|
174
|
-
amount_per_period:
|
|
173
|
+
amount_per_period: values.amount_per_period ?? 0,
|
|
175
174
|
}, data);
|
|
176
175
|
};
|
|
177
176
|
exports.encodeUpdateStream = encodeUpdateStream;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deriveTestOraclePDA = exports.deriveEscrowPDA = exports.deriveContractPDA = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const deriveContractPDA = (programId, streamMetadata) => {
|
|
7
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.CONTRACT_SEED, streamMetadata.toBuffer()], programId)[0];
|
|
8
|
+
};
|
|
9
|
+
exports.deriveContractPDA = deriveContractPDA;
|
|
10
|
+
const deriveEscrowPDA = (programId, streamMetadata) => {
|
|
11
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.ESCROW_SEED, streamMetadata.toBuffer()], programId)[0];
|
|
12
|
+
};
|
|
13
|
+
exports.deriveEscrowPDA = deriveEscrowPDA;
|
|
14
|
+
const deriveTestOraclePDA = (programId, mint, creator) => {
|
|
15
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.TEST_ORACLE_SEED, mint.toBuffer(), creator.toBuffer()], programId)[0];
|
|
16
|
+
};
|
|
17
|
+
exports.deriveTestOraclePDA = deriveTestOraclePDA;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.extractSolanaErrorCode = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.decodeStream = void 0;
|
|
7
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
8
|
+
const solana_1 = require("@streamflow/common/solana");
|
|
9
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
10
|
+
const layout_js_1 = require("../layout.js");
|
|
11
|
+
const constants_js_1 = require("../constants.js");
|
|
12
|
+
const decoder = new TextDecoder("utf-8");
|
|
13
|
+
const LE = "le"; //little endian
|
|
14
|
+
const decodeStream = (buf) => {
|
|
15
|
+
const raw = layout_js_1.streamLayout.decode(buf);
|
|
16
|
+
return {
|
|
17
|
+
magic: new bn_js_1.default(raw.magic, LE),
|
|
18
|
+
version: new bn_js_1.default(raw.version, LE),
|
|
19
|
+
createdAt: new bn_js_1.default(raw.created_at, LE),
|
|
20
|
+
withdrawnAmount: new bn_js_1.default(raw.withdrawn_amount, LE),
|
|
21
|
+
canceledAt: new bn_js_1.default(raw.canceled_at, LE),
|
|
22
|
+
end: new bn_js_1.default(raw.end_time, LE),
|
|
23
|
+
lastWithdrawnAt: new bn_js_1.default(raw.last_withdrawn_at, LE),
|
|
24
|
+
sender: new web3_js_1.PublicKey(raw.sender),
|
|
25
|
+
senderTokens: new web3_js_1.PublicKey(raw.sender_tokens),
|
|
26
|
+
recipient: new web3_js_1.PublicKey(raw.recipient),
|
|
27
|
+
recipientTokens: new web3_js_1.PublicKey(raw.recipient_tokens),
|
|
28
|
+
mint: new web3_js_1.PublicKey(raw.mint),
|
|
29
|
+
escrowTokens: new web3_js_1.PublicKey(raw.escrow_tokens),
|
|
30
|
+
streamflowTreasury: new web3_js_1.PublicKey(raw.streamflow_treasury),
|
|
31
|
+
streamflowTreasuryTokens: new web3_js_1.PublicKey(raw.streamflow_treasury_tokens),
|
|
32
|
+
streamflowFeeTotal: new bn_js_1.default(raw.streamflow_fee_total, LE),
|
|
33
|
+
streamflowFeeWithdrawn: new bn_js_1.default(raw.streamflow_fee_withdrawn, LE),
|
|
34
|
+
streamflowFeePercent: new bn_js_1.default(raw.streamflow_fee_percent, LE),
|
|
35
|
+
partnerFeeTotal: new bn_js_1.default(raw.partner_fee_total, LE),
|
|
36
|
+
partnerFeeWithdrawn: new bn_js_1.default(raw.partner_fee_withdrawn, LE),
|
|
37
|
+
partnerFeePercent: new bn_js_1.default(raw.partner_fee_percent, LE),
|
|
38
|
+
partner: new web3_js_1.PublicKey(raw.partner),
|
|
39
|
+
partnerTokens: new web3_js_1.PublicKey(raw.partner_tokens),
|
|
40
|
+
start: new bn_js_1.default(raw.start_time, LE),
|
|
41
|
+
depositedAmount: new bn_js_1.default(raw.net_amount_deposited, LE),
|
|
42
|
+
period: new bn_js_1.default(raw.period, LE),
|
|
43
|
+
amountPerPeriod: new bn_js_1.default(raw.amount_per_period, LE),
|
|
44
|
+
cliff: new bn_js_1.default(raw.cliff, LE),
|
|
45
|
+
cliffAmount: new bn_js_1.default(raw.cliff_amount, LE),
|
|
46
|
+
cancelableBySender: Boolean(raw.cancelable_by_sender),
|
|
47
|
+
cancelableByRecipient: Boolean(raw.cancelable_by_recipient),
|
|
48
|
+
automaticWithdrawal: Boolean(raw.automatic_withdrawal),
|
|
49
|
+
transferableBySender: Boolean(raw.transferable_by_sender),
|
|
50
|
+
transferableByRecipient: Boolean(raw.transferable_by_recipient),
|
|
51
|
+
canTopup: Boolean(raw.can_topup),
|
|
52
|
+
name: decoder.decode(raw.stream_name),
|
|
53
|
+
withdrawFrequency: new bn_js_1.default(raw.withdraw_frequency, LE),
|
|
54
|
+
closed: Boolean(raw.closed),
|
|
55
|
+
currentPauseStart: new bn_js_1.default(raw.current_pause_start, LE),
|
|
56
|
+
pauseCumulative: new bn_js_1.default(raw.pause_cumulative, LE),
|
|
57
|
+
lastRateChangeTime: new bn_js_1.default(raw.last_rate_change_time, LE),
|
|
58
|
+
fundsUnlockedAtLastRateChange: new bn_js_1.default(raw.funds_unlocked_at_last_rate_change, LE),
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
exports.decodeStream = decodeStream;
|
|
62
|
+
/**
|
|
63
|
+
* Sign passed BatchItems with wallet request or KeyPair
|
|
64
|
+
* @param {Keypair | SignerWalletAdapter} sender - Wallet or Keypair of sendin account
|
|
65
|
+
* @param {BatchItem[]} items - Multiple recipient contracts split into separate items
|
|
66
|
+
* @return {BatchItem[]} - Returns items with signatures.
|
|
67
|
+
*/
|
|
68
|
+
async function signAllTransactionWithRecipients(sender, items) {
|
|
69
|
+
const isKeypair = (0, solana_1.isSignerKeypair)(sender);
|
|
70
|
+
const isWallet = (0, solana_1.isSignerWallet)(sender);
|
|
71
|
+
if (isKeypair) {
|
|
72
|
+
return items.map((t) => {
|
|
73
|
+
t.tx.sign([sender]);
|
|
74
|
+
return { tx: t.tx, recipient: t.recipient };
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else if (isWallet) {
|
|
78
|
+
const signedTxs = await sender.signAllTransactions(items.map((t) => t.tx));
|
|
79
|
+
return items.map((item, index) => ({
|
|
80
|
+
...item,
|
|
81
|
+
tx: signedTxs[index],
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
// If signer is not passed
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
|
|
90
|
+
/**
|
|
91
|
+
* Sign passed BatchItems with wallet request or KeyPair
|
|
92
|
+
* @param {Connection} connection - Solana web3 connection object.
|
|
93
|
+
* @param {BatchItem} batchItem - Signed transaction ready to be send.
|
|
94
|
+
* @param confirmationParams - Confirmation Params that will be used for execution
|
|
95
|
+
* @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
|
|
96
|
+
* @return {Promise<BatchItemResult>} - Returns settled transaction item
|
|
97
|
+
*/
|
|
98
|
+
async function sendAndConfirmStreamRawTransaction(connection, batchItem, confirmationParams, throttleParams) {
|
|
99
|
+
try {
|
|
100
|
+
const completedTxSignature = await (0, solana_1.executeTransaction)(connection, batchItem.tx, confirmationParams, throttleParams);
|
|
101
|
+
return { ...batchItem, signature: completedTxSignature };
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
throw {
|
|
105
|
+
recipient: batchItem.recipient,
|
|
106
|
+
error,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;
|
|
111
|
+
function extractSolanaErrorCode(errorText, logs) {
|
|
112
|
+
let match = constants_js_1.SOLANA_ERROR_MATCH_REGEX.exec(errorText);
|
|
113
|
+
if (!match && logs) {
|
|
114
|
+
for (const logLine of logs) {
|
|
115
|
+
match = constants_js_1.SOLANA_ERROR_MATCH_REGEX.exec(logLine);
|
|
116
|
+
if (match !== null) {
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (!match) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
const errorCode = Number(match[1]);
|
|
125
|
+
return constants_js_1.SOLANA_ERROR_MAP[errorCode] || null;
|
|
126
|
+
}
|
|
127
|
+
exports.extractSolanaErrorCode = extractSolanaErrorCode;
|
package/dist/cjs/solana/types.js
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.Contract = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
exports.AlignedContract = exports.Contract = exports.ContractError = exports.ICluster = exports.IChain = void 0;
|
|
4
|
+
const contractUtils_js_1 = require("../common/contractUtils.js");
|
|
5
|
+
const utils_js_1 = require("../common/utils.js");
|
|
6
|
+
const constants_js_1 = require("./constants.js");
|
|
7
|
+
var common_1 = require("@streamflow/common");
|
|
8
|
+
Object.defineProperty(exports, "IChain", { enumerable: true, get: function () { return common_1.IChain; } });
|
|
9
|
+
Object.defineProperty(exports, "ICluster", { enumerable: true, get: function () { return common_1.ICluster; } });
|
|
10
|
+
Object.defineProperty(exports, "ContractError", { enumerable: true, get: function () { return common_1.ContractError; } });
|
|
11
|
+
class Contract {
|
|
12
|
+
constructor(stream) {
|
|
20
13
|
this.magic = stream.magic.toNumber();
|
|
21
14
|
this.version = stream.version.toNumber();
|
|
22
15
|
this.createdAt = stream.createdAt.toNumber();
|
|
23
16
|
this.withdrawnAmount = stream.withdrawnAmount;
|
|
24
17
|
this.canceledAt = stream.canceledAt.toNumber();
|
|
25
|
-
|
|
18
|
+
// for aligned contracts end time can be an invalid timeValue
|
|
19
|
+
this.end = (0, contractUtils_js_1.decodeEndTime)(stream.end);
|
|
26
20
|
this.lastWithdrawnAt = stream.lastWithdrawnAt.toNumber();
|
|
27
21
|
this.sender = stream.sender.toBase58();
|
|
28
22
|
this.senderTokens = stream.senderTokens.toBase58();
|
|
@@ -39,7 +33,7 @@ var Contract = /** @class */ (function () {
|
|
|
39
33
|
this.partnerFeeWithdrawn = stream.partnerFeeWithdrawn;
|
|
40
34
|
this.partnerFeePercent = stream.partnerFeePercent.toNumber();
|
|
41
35
|
this.partner = stream.partner.toBase58();
|
|
42
|
-
this.partnerTokens =
|
|
36
|
+
this.partnerTokens = stream.partnerTokens?.toBase58();
|
|
43
37
|
this.start = stream.start.toNumber();
|
|
44
38
|
this.depositedAmount = stream.depositedAmount;
|
|
45
39
|
this.period = stream.period.toNumber();
|
|
@@ -60,13 +54,32 @@ var Contract = /** @class */ (function () {
|
|
|
60
54
|
this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
|
|
61
55
|
this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
|
|
62
56
|
this.type = (0, contractUtils_js_1.buildStreamType)(this);
|
|
57
|
+
this.isAligned = false;
|
|
63
58
|
}
|
|
64
|
-
|
|
65
|
-
return (0, contractUtils_js_1.calculateUnlockedAmount)(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
59
|
+
unlocked(currentTimestamp) {
|
|
60
|
+
return (0, contractUtils_js_1.calculateUnlockedAmount)({
|
|
61
|
+
...this,
|
|
62
|
+
currentTimestamp,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
remaining(decimals) {
|
|
66
|
+
return (0, utils_js_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
72
69
|
exports.Contract = Contract;
|
|
70
|
+
class AlignedContract extends Contract {
|
|
71
|
+
constructor(stream, alignedProxy) {
|
|
72
|
+
super(stream);
|
|
73
|
+
this.minPrice = (0, utils_js_1.getNumberFromBN)(alignedProxy.minPrice, constants_js_1.ALIGNED_PRECISION_FACTOR_POW);
|
|
74
|
+
this.maxPrice = (0, utils_js_1.getNumberFromBN)(alignedProxy.maxPrice, constants_js_1.ALIGNED_PRECISION_FACTOR_POW);
|
|
75
|
+
this.minPercentage = (0, utils_js_1.getNumberFromBN)(alignedProxy.minPercentage, constants_js_1.ALIGNED_PRECISION_FACTOR_POW);
|
|
76
|
+
this.maxPercentage = (0, utils_js_1.getNumberFromBN)(alignedProxy.maxPercentage, constants_js_1.ALIGNED_PRECISION_FACTOR_POW);
|
|
77
|
+
this.oracleType = (Object.keys(alignedProxy.priceOracleType).find((key) => !!key) || "none");
|
|
78
|
+
this.tickSize = alignedProxy.tickSize.toNumber();
|
|
79
|
+
this.priceOracle = this.oracleType === "none" ? undefined : alignedProxy.priceOracle.toBase58();
|
|
80
|
+
this.sender = alignedProxy.sender.toBase58();
|
|
81
|
+
this.canceledAt = alignedProxy.streamCanceledTime.toNumber();
|
|
82
|
+
this.proxyAddress = stream.sender.toBase58();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.AlignedContract = AlignedContract;
|