@unifiedflow/unified-flow-sdk 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +38 -903
- package/dist/client.js +257 -52
- package/package.json +2 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,908 +1,43 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { PublicKey } from "@solana/web3.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export declare const
|
|
1
|
+
import * as anchor from "@coral-xyz/anchor";
|
|
2
|
+
import { PublicKey, Connection } from "@solana/web3.js";
|
|
3
|
+
import type { WalletSession } from "@solana/client";
|
|
4
|
+
import type { UnifiedFlow } from "./types";
|
|
5
|
+
export declare const CHAINLINK_PROGRAM_ID: anchor.web3.PublicKey;
|
|
6
|
+
export declare const SOL_USD_FEED: anchor.web3.PublicKey;
|
|
6
7
|
export interface MilestoneInput {
|
|
7
|
-
amount: BN;
|
|
8
|
+
amount: anchor.BN;
|
|
8
9
|
}
|
|
10
|
+
export type TxProgressPhase = "wallet_approval" | "sending" | "confirming";
|
|
9
11
|
export declare class UnifiedFlowClient {
|
|
10
|
-
readonly program
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
private readonly program;
|
|
13
|
+
private readonly wallet;
|
|
14
|
+
private readonly connection;
|
|
15
|
+
private readonly commitment;
|
|
16
|
+
private readonly kitSigner;
|
|
17
|
+
private readonly walletSignerMode;
|
|
18
|
+
constructor(program: anchor.Program<UnifiedFlow>, wallet: WalletSession, connection: Connection, commitment?: anchor.web3.Commitment);
|
|
15
19
|
getConfigPDA(): PublicKey;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"name": "stream";
|
|
40
|
-
"writable": true;
|
|
41
|
-
"pda": {
|
|
42
|
-
"seeds": [{
|
|
43
|
-
"kind": "const";
|
|
44
|
-
"value": [115, 116, 114, 101, 97, 109];
|
|
45
|
-
}, {
|
|
46
|
-
"kind": "account";
|
|
47
|
-
"path": "creator";
|
|
48
|
-
}, {
|
|
49
|
-
"kind": "account";
|
|
50
|
-
"path": "recipient";
|
|
51
|
-
}, {
|
|
52
|
-
"kind": "arg";
|
|
53
|
-
"path": "nonce";
|
|
54
|
-
}];
|
|
55
|
-
};
|
|
56
|
-
}, {
|
|
57
|
-
"name": "vault";
|
|
58
|
-
"writable": true;
|
|
59
|
-
"pda": {
|
|
60
|
-
"seeds": [{
|
|
61
|
-
"kind": "account";
|
|
62
|
-
"path": "stream";
|
|
63
|
-
}, {
|
|
64
|
-
"kind": "account";
|
|
65
|
-
"path": "tokenProgram";
|
|
66
|
-
}, {
|
|
67
|
-
"kind": "account";
|
|
68
|
-
"path": "mint";
|
|
69
|
-
}];
|
|
70
|
-
"program": {
|
|
71
|
-
"kind": "const";
|
|
72
|
-
"value": [140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89];
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
}, {
|
|
76
|
-
"name": "creatorTokenAccount";
|
|
77
|
-
"writable": true;
|
|
78
|
-
}, {
|
|
79
|
-
"name": "systemProgram";
|
|
80
|
-
"address": "11111111111111111111111111111111";
|
|
81
|
-
}, {
|
|
82
|
-
"name": "tokenProgram";
|
|
83
|
-
}, {
|
|
84
|
-
"name": "associatedTokenProgram";
|
|
85
|
-
"address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
86
|
-
}];
|
|
87
|
-
args: [{
|
|
88
|
-
"name": "amount";
|
|
89
|
-
"type": "u64";
|
|
90
|
-
}, {
|
|
91
|
-
"name": "startTs";
|
|
92
|
-
"type": "i64";
|
|
93
|
-
}, {
|
|
94
|
-
"name": "cliffTs";
|
|
95
|
-
"type": "i64";
|
|
96
|
-
}, {
|
|
97
|
-
"name": "endTs";
|
|
98
|
-
"type": "i64";
|
|
99
|
-
}, {
|
|
100
|
-
"name": "vestingType";
|
|
101
|
-
"type": "u8";
|
|
102
|
-
}, {
|
|
103
|
-
"name": "milestones";
|
|
104
|
-
"type": {
|
|
105
|
-
"vec": {
|
|
106
|
-
"defined": {
|
|
107
|
-
"name": "milestoneInput";
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
}, {
|
|
112
|
-
"name": "nonce";
|
|
113
|
-
"type": "u64";
|
|
114
|
-
}];
|
|
115
|
-
} & {
|
|
116
|
-
name: "createStream";
|
|
117
|
-
}, {
|
|
118
|
-
name: "creator";
|
|
119
|
-
writable: true;
|
|
120
|
-
signer: true;
|
|
121
|
-
} | {
|
|
122
|
-
name: "recipient";
|
|
123
|
-
} | {
|
|
124
|
-
name: "mint";
|
|
125
|
-
} | {
|
|
126
|
-
name: "config";
|
|
127
|
-
pda: {
|
|
128
|
-
"seeds": [{
|
|
129
|
-
"kind": "const";
|
|
130
|
-
"value": [99, 111, 110, 102, 105, 103];
|
|
131
|
-
}];
|
|
132
|
-
};
|
|
133
|
-
} | {
|
|
134
|
-
name: "stream";
|
|
135
|
-
writable: true;
|
|
136
|
-
pda: {
|
|
137
|
-
"seeds": [{
|
|
138
|
-
"kind": "const";
|
|
139
|
-
"value": [115, 116, 114, 101, 97, 109];
|
|
140
|
-
}, {
|
|
141
|
-
"kind": "account";
|
|
142
|
-
"path": "creator";
|
|
143
|
-
}, {
|
|
144
|
-
"kind": "account";
|
|
145
|
-
"path": "recipient";
|
|
146
|
-
}, {
|
|
147
|
-
"kind": "arg";
|
|
148
|
-
"path": "nonce";
|
|
149
|
-
}];
|
|
150
|
-
};
|
|
151
|
-
} | {
|
|
152
|
-
name: "vault";
|
|
153
|
-
writable: true;
|
|
154
|
-
pda: {
|
|
155
|
-
"seeds": [{
|
|
156
|
-
"kind": "account";
|
|
157
|
-
"path": "stream";
|
|
158
|
-
}, {
|
|
159
|
-
"kind": "account";
|
|
160
|
-
"path": "tokenProgram";
|
|
161
|
-
}, {
|
|
162
|
-
"kind": "account";
|
|
163
|
-
"path": "mint";
|
|
164
|
-
}];
|
|
165
|
-
"program": {
|
|
166
|
-
"kind": "const";
|
|
167
|
-
"value": [140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89];
|
|
168
|
-
};
|
|
169
|
-
};
|
|
170
|
-
} | {
|
|
171
|
-
name: "creatorTokenAccount";
|
|
172
|
-
writable: true;
|
|
173
|
-
} | {
|
|
174
|
-
name: "systemProgram";
|
|
175
|
-
address: "11111111111111111111111111111111";
|
|
176
|
-
} | {
|
|
177
|
-
name: "tokenProgram";
|
|
178
|
-
} | {
|
|
179
|
-
name: "associatedTokenProgram";
|
|
180
|
-
address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
181
|
-
}>>;
|
|
182
|
-
/**
|
|
183
|
-
* Withdraw unlocked/vested tokens from a stream
|
|
184
|
-
*/
|
|
185
|
-
withdraw(streamPDA: PublicKey, recipient: PublicKey, mint: PublicKey): Promise<import("@coral-xyz/anchor/dist/cjs/program/namespace/methods").MethodsBuilder<UnifiedFlow, {
|
|
186
|
-
name: "withdraw";
|
|
187
|
-
discriminator: [183, 18, 70, 156, 148, 109, 161, 34];
|
|
188
|
-
accounts: [{
|
|
189
|
-
"name": "recipient";
|
|
190
|
-
"writable": true;
|
|
191
|
-
"signer": true;
|
|
192
|
-
}, {
|
|
193
|
-
"name": "mint";
|
|
194
|
-
"relations": ["stream"];
|
|
195
|
-
}, {
|
|
196
|
-
"name": "config";
|
|
197
|
-
"pda": {
|
|
198
|
-
"seeds": [{
|
|
199
|
-
"kind": "const";
|
|
200
|
-
"value": [99, 111, 110, 102, 105, 103];
|
|
201
|
-
}];
|
|
202
|
-
};
|
|
203
|
-
}, {
|
|
204
|
-
"name": "stream";
|
|
205
|
-
"docs": ["Stream account"];
|
|
206
|
-
"writable": true;
|
|
207
|
-
"pda": {
|
|
208
|
-
"seeds": [{
|
|
209
|
-
"kind": "const";
|
|
210
|
-
"value": [115, 116, 114, 101, 97, 109];
|
|
211
|
-
}, {
|
|
212
|
-
"kind": "account";
|
|
213
|
-
"path": "stream.creator";
|
|
214
|
-
"account": "streamAccount";
|
|
215
|
-
}, {
|
|
216
|
-
"kind": "account";
|
|
217
|
-
"path": "stream.recipient";
|
|
218
|
-
"account": "streamAccount";
|
|
219
|
-
}, {
|
|
220
|
-
"kind": "account";
|
|
221
|
-
"path": "stream.nonce";
|
|
222
|
-
"account": "streamAccount";
|
|
223
|
-
}];
|
|
224
|
-
};
|
|
225
|
-
}, {
|
|
226
|
-
"name": "vault";
|
|
227
|
-
"docs": ["Vault token account (ATA owned by stream PDA)"];
|
|
228
|
-
"writable": true;
|
|
229
|
-
"pda": {
|
|
230
|
-
"seeds": [{
|
|
231
|
-
"kind": "account";
|
|
232
|
-
"path": "stream";
|
|
233
|
-
}, {
|
|
234
|
-
"kind": "account";
|
|
235
|
-
"path": "tokenProgram";
|
|
236
|
-
}, {
|
|
237
|
-
"kind": "account";
|
|
238
|
-
"path": "mint";
|
|
239
|
-
}];
|
|
240
|
-
"program": {
|
|
241
|
-
"kind": "const";
|
|
242
|
-
"value": [140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89];
|
|
243
|
-
};
|
|
244
|
-
};
|
|
245
|
-
}, {
|
|
246
|
-
"name": "recipientAta";
|
|
247
|
-
"docs": ["Token account recipient"];
|
|
248
|
-
"writable": true;
|
|
249
|
-
}, {
|
|
250
|
-
"name": "feeVault";
|
|
251
|
-
"docs": ["Recipient fee SOL"];
|
|
252
|
-
"writable": true;
|
|
253
|
-
"pda": {
|
|
254
|
-
"seeds": [{
|
|
255
|
-
"kind": "const";
|
|
256
|
-
"value": [102, 101, 101, 95, 118, 97, 117, 108, 116];
|
|
257
|
-
}];
|
|
258
|
-
};
|
|
259
|
-
}, {
|
|
260
|
-
"name": "chainlinkFeed";
|
|
261
|
-
}, {
|
|
262
|
-
"name": "tokenProgram";
|
|
263
|
-
}, {
|
|
264
|
-
"name": "systemProgram";
|
|
265
|
-
"address": "11111111111111111111111111111111";
|
|
266
|
-
}];
|
|
267
|
-
args: [];
|
|
268
|
-
} & {
|
|
269
|
-
name: "withdraw";
|
|
270
|
-
}, {
|
|
271
|
-
name: "recipient";
|
|
272
|
-
writable: true;
|
|
273
|
-
signer: true;
|
|
274
|
-
} | {
|
|
275
|
-
name: "mint";
|
|
276
|
-
relations: ["stream"];
|
|
277
|
-
} | {
|
|
278
|
-
name: "config";
|
|
279
|
-
pda: {
|
|
280
|
-
"seeds": [{
|
|
281
|
-
"kind": "const";
|
|
282
|
-
"value": [99, 111, 110, 102, 105, 103];
|
|
283
|
-
}];
|
|
284
|
-
};
|
|
285
|
-
} | {
|
|
286
|
-
name: "stream";
|
|
287
|
-
docs: ["Stream account"];
|
|
288
|
-
writable: true;
|
|
289
|
-
pda: {
|
|
290
|
-
"seeds": [{
|
|
291
|
-
"kind": "const";
|
|
292
|
-
"value": [115, 116, 114, 101, 97, 109];
|
|
293
|
-
}, {
|
|
294
|
-
"kind": "account";
|
|
295
|
-
"path": "stream.creator";
|
|
296
|
-
"account": "streamAccount";
|
|
297
|
-
}, {
|
|
298
|
-
"kind": "account";
|
|
299
|
-
"path": "stream.recipient";
|
|
300
|
-
"account": "streamAccount";
|
|
301
|
-
}, {
|
|
302
|
-
"kind": "account";
|
|
303
|
-
"path": "stream.nonce";
|
|
304
|
-
"account": "streamAccount";
|
|
305
|
-
}];
|
|
306
|
-
};
|
|
307
|
-
} | {
|
|
308
|
-
name: "vault";
|
|
309
|
-
docs: ["Vault token account (ATA owned by stream PDA)"];
|
|
310
|
-
writable: true;
|
|
311
|
-
pda: {
|
|
312
|
-
"seeds": [{
|
|
313
|
-
"kind": "account";
|
|
314
|
-
"path": "stream";
|
|
315
|
-
}, {
|
|
316
|
-
"kind": "account";
|
|
317
|
-
"path": "tokenProgram";
|
|
318
|
-
}, {
|
|
319
|
-
"kind": "account";
|
|
320
|
-
"path": "mint";
|
|
321
|
-
}];
|
|
322
|
-
"program": {
|
|
323
|
-
"kind": "const";
|
|
324
|
-
"value": [140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89];
|
|
325
|
-
};
|
|
326
|
-
};
|
|
327
|
-
} | {
|
|
328
|
-
name: "recipientAta";
|
|
329
|
-
docs: ["Token account recipient"];
|
|
330
|
-
writable: true;
|
|
331
|
-
} | {
|
|
332
|
-
name: "feeVault";
|
|
333
|
-
docs: ["Recipient fee SOL"];
|
|
334
|
-
writable: true;
|
|
335
|
-
pda: {
|
|
336
|
-
"seeds": [{
|
|
337
|
-
"kind": "const";
|
|
338
|
-
"value": [102, 101, 101, 95, 118, 97, 117, 108, 116];
|
|
339
|
-
}];
|
|
340
|
-
};
|
|
341
|
-
} | {
|
|
342
|
-
name: "chainlinkFeed";
|
|
343
|
-
} | {
|
|
344
|
-
name: "tokenProgram";
|
|
345
|
-
} | {
|
|
346
|
-
name: "systemProgram";
|
|
347
|
-
address: "11111111111111111111111111111111";
|
|
348
|
-
}>>;
|
|
349
|
-
/**
|
|
350
|
-
* Cancel an active stream and return remaining tokens to the creator
|
|
351
|
-
*/
|
|
352
|
-
cancel(streamPDA: PublicKey, creator: PublicKey, recipient: PublicKey, mint: PublicKey): Promise<import("@coral-xyz/anchor/dist/cjs/program/namespace/methods").MethodsBuilder<UnifiedFlow, {
|
|
353
|
-
name: "cancel";
|
|
354
|
-
discriminator: [232, 219, 223, 41, 219, 236, 220, 190];
|
|
355
|
-
accounts: [{
|
|
356
|
-
"name": "creator";
|
|
357
|
-
"writable": true;
|
|
358
|
-
"signer": true;
|
|
359
|
-
}, {
|
|
360
|
-
"name": "mint";
|
|
361
|
-
"relations": ["stream"];
|
|
362
|
-
}, {
|
|
363
|
-
"name": "config";
|
|
364
|
-
"pda": {
|
|
365
|
-
"seeds": [{
|
|
366
|
-
"kind": "const";
|
|
367
|
-
"value": [99, 111, 110, 102, 105, 103];
|
|
368
|
-
}];
|
|
369
|
-
};
|
|
370
|
-
}, {
|
|
371
|
-
"name": "stream";
|
|
372
|
-
"writable": true;
|
|
373
|
-
"pda": {
|
|
374
|
-
"seeds": [{
|
|
375
|
-
"kind": "const";
|
|
376
|
-
"value": [115, 116, 114, 101, 97, 109];
|
|
377
|
-
}, {
|
|
378
|
-
"kind": "account";
|
|
379
|
-
"path": "stream.creator";
|
|
380
|
-
"account": "streamAccount";
|
|
381
|
-
}, {
|
|
382
|
-
"kind": "account";
|
|
383
|
-
"path": "stream.recipient";
|
|
384
|
-
"account": "streamAccount";
|
|
385
|
-
}, {
|
|
386
|
-
"kind": "account";
|
|
387
|
-
"path": "stream.nonce";
|
|
388
|
-
"account": "streamAccount";
|
|
389
|
-
}];
|
|
390
|
-
};
|
|
391
|
-
}, {
|
|
392
|
-
"name": "vault";
|
|
393
|
-
"writable": true;
|
|
394
|
-
"pda": {
|
|
395
|
-
"seeds": [{
|
|
396
|
-
"kind": "account";
|
|
397
|
-
"path": "stream";
|
|
398
|
-
}, {
|
|
399
|
-
"kind": "account";
|
|
400
|
-
"path": "tokenProgram";
|
|
401
|
-
}, {
|
|
402
|
-
"kind": "account";
|
|
403
|
-
"path": "mint";
|
|
404
|
-
}];
|
|
405
|
-
"program": {
|
|
406
|
-
"kind": "const";
|
|
407
|
-
"value": [140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89];
|
|
408
|
-
};
|
|
409
|
-
};
|
|
410
|
-
}, {
|
|
411
|
-
"name": "creatorTokenAccount";
|
|
412
|
-
"writable": true;
|
|
413
|
-
}, {
|
|
414
|
-
"name": "recipientTokenAccount";
|
|
415
|
-
"writable": true;
|
|
416
|
-
}, {
|
|
417
|
-
"name": "tokenProgram";
|
|
418
|
-
}];
|
|
419
|
-
args: [];
|
|
420
|
-
} & {
|
|
421
|
-
name: "cancel";
|
|
422
|
-
}, {
|
|
423
|
-
name: "creator";
|
|
424
|
-
writable: true;
|
|
425
|
-
signer: true;
|
|
426
|
-
} | {
|
|
427
|
-
name: "mint";
|
|
428
|
-
relations: ["stream"];
|
|
429
|
-
} | {
|
|
430
|
-
name: "config";
|
|
431
|
-
pda: {
|
|
432
|
-
"seeds": [{
|
|
433
|
-
"kind": "const";
|
|
434
|
-
"value": [99, 111, 110, 102, 105, 103];
|
|
435
|
-
}];
|
|
436
|
-
};
|
|
437
|
-
} | {
|
|
438
|
-
name: "stream";
|
|
439
|
-
writable: true;
|
|
440
|
-
pda: {
|
|
441
|
-
"seeds": [{
|
|
442
|
-
"kind": "const";
|
|
443
|
-
"value": [115, 116, 114, 101, 97, 109];
|
|
444
|
-
}, {
|
|
445
|
-
"kind": "account";
|
|
446
|
-
"path": "stream.creator";
|
|
447
|
-
"account": "streamAccount";
|
|
448
|
-
}, {
|
|
449
|
-
"kind": "account";
|
|
450
|
-
"path": "stream.recipient";
|
|
451
|
-
"account": "streamAccount";
|
|
452
|
-
}, {
|
|
453
|
-
"kind": "account";
|
|
454
|
-
"path": "stream.nonce";
|
|
455
|
-
"account": "streamAccount";
|
|
456
|
-
}];
|
|
457
|
-
};
|
|
458
|
-
} | {
|
|
459
|
-
name: "vault";
|
|
460
|
-
writable: true;
|
|
461
|
-
pda: {
|
|
462
|
-
"seeds": [{
|
|
463
|
-
"kind": "account";
|
|
464
|
-
"path": "stream";
|
|
465
|
-
}, {
|
|
466
|
-
"kind": "account";
|
|
467
|
-
"path": "tokenProgram";
|
|
468
|
-
}, {
|
|
469
|
-
"kind": "account";
|
|
470
|
-
"path": "mint";
|
|
471
|
-
}];
|
|
472
|
-
"program": {
|
|
473
|
-
"kind": "const";
|
|
474
|
-
"value": [140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89];
|
|
475
|
-
};
|
|
476
|
-
};
|
|
477
|
-
} | {
|
|
478
|
-
name: "creatorTokenAccount";
|
|
479
|
-
writable: true;
|
|
480
|
-
} | {
|
|
481
|
-
name: "recipientTokenAccount";
|
|
482
|
-
writable: true;
|
|
483
|
-
} | {
|
|
484
|
-
name: "tokenProgram";
|
|
485
|
-
}>>;
|
|
486
|
-
/**
|
|
487
|
-
* Unlock a specific milestone
|
|
488
|
-
*/
|
|
489
|
-
unlockMilestone(streamPDA: PublicKey, creator: PublicKey, milestoneIndex: number): Promise<import("@coral-xyz/anchor/dist/cjs/program/namespace/methods").MethodsBuilder<UnifiedFlow, {
|
|
490
|
-
name: "unlockMilestone";
|
|
491
|
-
discriminator: [131, 196, 6, 134, 153, 130, 248, 238];
|
|
492
|
-
accounts: [{
|
|
493
|
-
"name": "creator";
|
|
494
|
-
"writable": true;
|
|
495
|
-
"signer": true;
|
|
496
|
-
"relations": ["stream"];
|
|
497
|
-
}, {
|
|
498
|
-
"name": "stream";
|
|
499
|
-
"writable": true;
|
|
500
|
-
"pda": {
|
|
501
|
-
"seeds": [{
|
|
502
|
-
"kind": "const";
|
|
503
|
-
"value": [115, 116, 114, 101, 97, 109];
|
|
504
|
-
}, {
|
|
505
|
-
"kind": "account";
|
|
506
|
-
"path": "stream.creator";
|
|
507
|
-
"account": "streamAccount";
|
|
508
|
-
}, {
|
|
509
|
-
"kind": "account";
|
|
510
|
-
"path": "stream.recipient";
|
|
511
|
-
"account": "streamAccount";
|
|
512
|
-
}, {
|
|
513
|
-
"kind": "account";
|
|
514
|
-
"path": "stream.nonce";
|
|
515
|
-
"account": "streamAccount";
|
|
516
|
-
}];
|
|
517
|
-
};
|
|
518
|
-
}, {
|
|
519
|
-
"name": "milestone";
|
|
520
|
-
"writable": true;
|
|
521
|
-
}, {
|
|
522
|
-
"name": "systemProgram";
|
|
523
|
-
"address": "11111111111111111111111111111111";
|
|
524
|
-
}];
|
|
525
|
-
args: [];
|
|
526
|
-
} & {
|
|
527
|
-
name: "unlockMilestone";
|
|
528
|
-
}, {
|
|
529
|
-
name: "creator";
|
|
530
|
-
writable: true;
|
|
531
|
-
signer: true;
|
|
532
|
-
relations: ["stream"];
|
|
533
|
-
} | {
|
|
534
|
-
name: "stream";
|
|
535
|
-
writable: true;
|
|
536
|
-
pda: {
|
|
537
|
-
"seeds": [{
|
|
538
|
-
"kind": "const";
|
|
539
|
-
"value": [115, 116, 114, 101, 97, 109];
|
|
540
|
-
}, {
|
|
541
|
-
"kind": "account";
|
|
542
|
-
"path": "stream.creator";
|
|
543
|
-
"account": "streamAccount";
|
|
544
|
-
}, {
|
|
545
|
-
"kind": "account";
|
|
546
|
-
"path": "stream.recipient";
|
|
547
|
-
"account": "streamAccount";
|
|
548
|
-
}, {
|
|
549
|
-
"kind": "account";
|
|
550
|
-
"path": "stream.nonce";
|
|
551
|
-
"account": "streamAccount";
|
|
552
|
-
}];
|
|
553
|
-
};
|
|
554
|
-
} | {
|
|
555
|
-
name: "milestone";
|
|
556
|
-
writable: true;
|
|
557
|
-
} | {
|
|
558
|
-
name: "systemProgram";
|
|
559
|
-
address: "11111111111111111111111111111111";
|
|
560
|
-
}>>;
|
|
561
|
-
/**
|
|
562
|
-
* Edit a milestone's amount (increase or decrease)
|
|
563
|
-
*/
|
|
564
|
-
editMilestone(streamPDA: PublicKey, creator: PublicKey, mint: PublicKey, milestoneIndex: number, newAmount: BN): Promise<import("@coral-xyz/anchor/dist/cjs/program/namespace/methods").MethodsBuilder<UnifiedFlow, {
|
|
565
|
-
name: "editMilestone";
|
|
566
|
-
discriminator: [123, 218, 165, 226, 209, 227, 8, 166];
|
|
567
|
-
accounts: [{
|
|
568
|
-
"name": "creator";
|
|
569
|
-
"writable": true;
|
|
570
|
-
"signer": true;
|
|
571
|
-
"relations": ["stream"];
|
|
572
|
-
}, {
|
|
573
|
-
"name": "stream";
|
|
574
|
-
"writable": true;
|
|
575
|
-
"pda": {
|
|
576
|
-
"seeds": [{
|
|
577
|
-
"kind": "const";
|
|
578
|
-
"value": [115, 116, 114, 101, 97, 109];
|
|
579
|
-
}, {
|
|
580
|
-
"kind": "account";
|
|
581
|
-
"path": "stream.creator";
|
|
582
|
-
"account": "streamAccount";
|
|
583
|
-
}, {
|
|
584
|
-
"kind": "account";
|
|
585
|
-
"path": "stream.recipient";
|
|
586
|
-
"account": "streamAccount";
|
|
587
|
-
}, {
|
|
588
|
-
"kind": "account";
|
|
589
|
-
"path": "stream.nonce";
|
|
590
|
-
"account": "streamAccount";
|
|
591
|
-
}];
|
|
592
|
-
};
|
|
593
|
-
}, {
|
|
594
|
-
"name": "milestone";
|
|
595
|
-
"writable": true;
|
|
596
|
-
}, {
|
|
597
|
-
"name": "mint";
|
|
598
|
-
"relations": ["stream"];
|
|
599
|
-
}, {
|
|
600
|
-
"name": "vault";
|
|
601
|
-
"writable": true;
|
|
602
|
-
"pda": {
|
|
603
|
-
"seeds": [{
|
|
604
|
-
"kind": "account";
|
|
605
|
-
"path": "stream";
|
|
606
|
-
}, {
|
|
607
|
-
"kind": "account";
|
|
608
|
-
"path": "tokenProgram";
|
|
609
|
-
}, {
|
|
610
|
-
"kind": "account";
|
|
611
|
-
"path": "mint";
|
|
612
|
-
}];
|
|
613
|
-
"program": {
|
|
614
|
-
"kind": "const";
|
|
615
|
-
"value": [140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89];
|
|
616
|
-
};
|
|
617
|
-
};
|
|
618
|
-
}, {
|
|
619
|
-
"name": "creatorTokenAccount";
|
|
620
|
-
"writable": true;
|
|
621
|
-
}, {
|
|
622
|
-
"name": "tokenProgram";
|
|
623
|
-
}];
|
|
624
|
-
args: [{
|
|
625
|
-
"name": "newAmount";
|
|
626
|
-
"type": "u64";
|
|
627
|
-
}];
|
|
628
|
-
} & {
|
|
629
|
-
name: "editMilestone";
|
|
630
|
-
}, {
|
|
631
|
-
name: "creator";
|
|
632
|
-
writable: true;
|
|
633
|
-
signer: true;
|
|
634
|
-
relations: ["stream"];
|
|
635
|
-
} | {
|
|
636
|
-
name: "stream";
|
|
637
|
-
writable: true;
|
|
638
|
-
pda: {
|
|
639
|
-
"seeds": [{
|
|
640
|
-
"kind": "const";
|
|
641
|
-
"value": [115, 116, 114, 101, 97, 109];
|
|
642
|
-
}, {
|
|
643
|
-
"kind": "account";
|
|
644
|
-
"path": "stream.creator";
|
|
645
|
-
"account": "streamAccount";
|
|
646
|
-
}, {
|
|
647
|
-
"kind": "account";
|
|
648
|
-
"path": "stream.recipient";
|
|
649
|
-
"account": "streamAccount";
|
|
650
|
-
}, {
|
|
651
|
-
"kind": "account";
|
|
652
|
-
"path": "stream.nonce";
|
|
653
|
-
"account": "streamAccount";
|
|
654
|
-
}];
|
|
655
|
-
};
|
|
656
|
-
} | {
|
|
657
|
-
name: "milestone";
|
|
658
|
-
writable: true;
|
|
659
|
-
} | {
|
|
660
|
-
name: "mint";
|
|
661
|
-
relations: ["stream"];
|
|
662
|
-
} | {
|
|
663
|
-
name: "vault";
|
|
664
|
-
writable: true;
|
|
665
|
-
pda: {
|
|
666
|
-
"seeds": [{
|
|
667
|
-
"kind": "account";
|
|
668
|
-
"path": "stream";
|
|
669
|
-
}, {
|
|
670
|
-
"kind": "account";
|
|
671
|
-
"path": "tokenProgram";
|
|
672
|
-
}, {
|
|
673
|
-
"kind": "account";
|
|
674
|
-
"path": "mint";
|
|
675
|
-
}];
|
|
676
|
-
"program": {
|
|
677
|
-
"kind": "const";
|
|
678
|
-
"value": [140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89];
|
|
679
|
-
};
|
|
680
|
-
};
|
|
681
|
-
} | {
|
|
682
|
-
name: "creatorTokenAccount";
|
|
683
|
-
writable: true;
|
|
684
|
-
} | {
|
|
685
|
-
name: "tokenProgram";
|
|
686
|
-
}>>;
|
|
687
|
-
/**
|
|
688
|
-
* Edit the cliff timestamp of a cliff vesting stream
|
|
689
|
-
*/
|
|
690
|
-
editCliff(streamPDA: PublicKey, creator: PublicKey, newCliffTs: BN): Promise<import("@coral-xyz/anchor/dist/cjs/program/namespace/methods").MethodsBuilder<UnifiedFlow, {
|
|
691
|
-
name: "editCliff";
|
|
692
|
-
discriminator: [41, 203, 122, 7, 21, 225, 162, 98];
|
|
693
|
-
accounts: [{
|
|
694
|
-
"name": "creator";
|
|
695
|
-
"writable": true;
|
|
696
|
-
"signer": true;
|
|
697
|
-
"relations": ["stream"];
|
|
698
|
-
}, {
|
|
699
|
-
"name": "config";
|
|
700
|
-
"pda": {
|
|
701
|
-
"seeds": [{
|
|
702
|
-
"kind": "const";
|
|
703
|
-
"value": [99, 111, 110, 102, 105, 103];
|
|
704
|
-
}];
|
|
705
|
-
};
|
|
706
|
-
}, {
|
|
707
|
-
"name": "stream";
|
|
708
|
-
"writable": true;
|
|
709
|
-
"pda": {
|
|
710
|
-
"seeds": [{
|
|
711
|
-
"kind": "const";
|
|
712
|
-
"value": [115, 116, 114, 101, 97, 109];
|
|
713
|
-
}, {
|
|
714
|
-
"kind": "account";
|
|
715
|
-
"path": "stream.creator";
|
|
716
|
-
"account": "streamAccount";
|
|
717
|
-
}, {
|
|
718
|
-
"kind": "account";
|
|
719
|
-
"path": "stream.recipient";
|
|
720
|
-
"account": "streamAccount";
|
|
721
|
-
}, {
|
|
722
|
-
"kind": "account";
|
|
723
|
-
"path": "stream.nonce";
|
|
724
|
-
"account": "streamAccount";
|
|
725
|
-
}];
|
|
726
|
-
};
|
|
727
|
-
}];
|
|
728
|
-
args: [{
|
|
729
|
-
"name": "newCliffTs";
|
|
730
|
-
"type": "i64";
|
|
731
|
-
}];
|
|
732
|
-
} & {
|
|
733
|
-
name: "editCliff";
|
|
734
|
-
}, {
|
|
735
|
-
name: "creator";
|
|
736
|
-
writable: true;
|
|
737
|
-
signer: true;
|
|
738
|
-
relations: ["stream"];
|
|
739
|
-
} | {
|
|
740
|
-
name: "config";
|
|
741
|
-
pda: {
|
|
742
|
-
"seeds": [{
|
|
743
|
-
"kind": "const";
|
|
744
|
-
"value": [99, 111, 110, 102, 105, 103];
|
|
745
|
-
}];
|
|
746
|
-
};
|
|
747
|
-
} | {
|
|
748
|
-
name: "stream";
|
|
749
|
-
writable: true;
|
|
750
|
-
pda: {
|
|
751
|
-
"seeds": [{
|
|
752
|
-
"kind": "const";
|
|
753
|
-
"value": [115, 116, 114, 101, 97, 109];
|
|
754
|
-
}, {
|
|
755
|
-
"kind": "account";
|
|
756
|
-
"path": "stream.creator";
|
|
757
|
-
"account": "streamAccount";
|
|
758
|
-
}, {
|
|
759
|
-
"kind": "account";
|
|
760
|
-
"path": "stream.recipient";
|
|
761
|
-
"account": "streamAccount";
|
|
762
|
-
}, {
|
|
763
|
-
"kind": "account";
|
|
764
|
-
"path": "stream.nonce";
|
|
765
|
-
"account": "streamAccount";
|
|
766
|
-
}];
|
|
767
|
-
};
|
|
768
|
-
}>>;
|
|
769
|
-
/**
|
|
770
|
-
* Edit a linear stream's end timestamp and/or top up tokens
|
|
771
|
-
*/
|
|
772
|
-
editLinear(streamPDA: PublicKey, creator: PublicKey, mint: PublicKey, newEndTs: BN, topupAmount: BN): Promise<import("@coral-xyz/anchor/dist/cjs/program/namespace/methods").MethodsBuilder<UnifiedFlow, {
|
|
773
|
-
name: "editLinear";
|
|
774
|
-
discriminator: [255, 42, 53, 36, 79, 96, 83, 223];
|
|
775
|
-
accounts: [{
|
|
776
|
-
"name": "creator";
|
|
777
|
-
"writable": true;
|
|
778
|
-
"signer": true;
|
|
779
|
-
"relations": ["stream"];
|
|
780
|
-
}, {
|
|
781
|
-
"name": "mint";
|
|
782
|
-
"relations": ["stream"];
|
|
783
|
-
}, {
|
|
784
|
-
"name": "config";
|
|
785
|
-
"pda": {
|
|
786
|
-
"seeds": [{
|
|
787
|
-
"kind": "const";
|
|
788
|
-
"value": [99, 111, 110, 102, 105, 103];
|
|
789
|
-
}];
|
|
790
|
-
};
|
|
791
|
-
}, {
|
|
792
|
-
"name": "stream";
|
|
793
|
-
"writable": true;
|
|
794
|
-
"pda": {
|
|
795
|
-
"seeds": [{
|
|
796
|
-
"kind": "const";
|
|
797
|
-
"value": [115, 116, 114, 101, 97, 109];
|
|
798
|
-
}, {
|
|
799
|
-
"kind": "account";
|
|
800
|
-
"path": "stream.creator";
|
|
801
|
-
"account": "streamAccount";
|
|
802
|
-
}, {
|
|
803
|
-
"kind": "account";
|
|
804
|
-
"path": "stream.recipient";
|
|
805
|
-
"account": "streamAccount";
|
|
806
|
-
}, {
|
|
807
|
-
"kind": "account";
|
|
808
|
-
"path": "stream.nonce";
|
|
809
|
-
"account": "streamAccount";
|
|
810
|
-
}];
|
|
811
|
-
};
|
|
812
|
-
}, {
|
|
813
|
-
"name": "vault";
|
|
814
|
-
"writable": true;
|
|
815
|
-
"pda": {
|
|
816
|
-
"seeds": [{
|
|
817
|
-
"kind": "account";
|
|
818
|
-
"path": "stream";
|
|
819
|
-
}, {
|
|
820
|
-
"kind": "account";
|
|
821
|
-
"path": "tokenProgram";
|
|
822
|
-
}, {
|
|
823
|
-
"kind": "account";
|
|
824
|
-
"path": "mint";
|
|
825
|
-
}];
|
|
826
|
-
"program": {
|
|
827
|
-
"kind": "const";
|
|
828
|
-
"value": [140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89];
|
|
829
|
-
};
|
|
830
|
-
};
|
|
831
|
-
}, {
|
|
832
|
-
"name": "creatorTokenAccount";
|
|
833
|
-
"writable": true;
|
|
834
|
-
}, {
|
|
835
|
-
"name": "tokenProgram";
|
|
836
|
-
}];
|
|
837
|
-
args: [{
|
|
838
|
-
"name": "newEndTs";
|
|
839
|
-
"type": "i64";
|
|
840
|
-
}, {
|
|
841
|
-
"name": "topupAmount";
|
|
842
|
-
"type": "u64";
|
|
843
|
-
}];
|
|
844
|
-
} & {
|
|
845
|
-
name: "editLinear";
|
|
846
|
-
}, {
|
|
847
|
-
name: "creator";
|
|
848
|
-
writable: true;
|
|
849
|
-
signer: true;
|
|
850
|
-
relations: ["stream"];
|
|
851
|
-
} | {
|
|
852
|
-
name: "mint";
|
|
853
|
-
relations: ["stream"];
|
|
854
|
-
} | {
|
|
855
|
-
name: "config";
|
|
856
|
-
pda: {
|
|
857
|
-
"seeds": [{
|
|
858
|
-
"kind": "const";
|
|
859
|
-
"value": [99, 111, 110, 102, 105, 103];
|
|
860
|
-
}];
|
|
861
|
-
};
|
|
862
|
-
} | {
|
|
863
|
-
name: "stream";
|
|
864
|
-
writable: true;
|
|
865
|
-
pda: {
|
|
866
|
-
"seeds": [{
|
|
867
|
-
"kind": "const";
|
|
868
|
-
"value": [115, 116, 114, 101, 97, 109];
|
|
869
|
-
}, {
|
|
870
|
-
"kind": "account";
|
|
871
|
-
"path": "stream.creator";
|
|
872
|
-
"account": "streamAccount";
|
|
873
|
-
}, {
|
|
874
|
-
"kind": "account";
|
|
875
|
-
"path": "stream.recipient";
|
|
876
|
-
"account": "streamAccount";
|
|
877
|
-
}, {
|
|
878
|
-
"kind": "account";
|
|
879
|
-
"path": "stream.nonce";
|
|
880
|
-
"account": "streamAccount";
|
|
881
|
-
}];
|
|
882
|
-
};
|
|
883
|
-
} | {
|
|
884
|
-
name: "vault";
|
|
885
|
-
writable: true;
|
|
886
|
-
pda: {
|
|
887
|
-
"seeds": [{
|
|
888
|
-
"kind": "account";
|
|
889
|
-
"path": "stream";
|
|
890
|
-
}, {
|
|
891
|
-
"kind": "account";
|
|
892
|
-
"path": "tokenProgram";
|
|
893
|
-
}, {
|
|
894
|
-
"kind": "account";
|
|
895
|
-
"path": "mint";
|
|
896
|
-
}];
|
|
897
|
-
"program": {
|
|
898
|
-
"kind": "const";
|
|
899
|
-
"value": [140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89];
|
|
900
|
-
};
|
|
901
|
-
};
|
|
902
|
-
} | {
|
|
903
|
-
name: "creatorTokenAccount";
|
|
904
|
-
writable: true;
|
|
905
|
-
} | {
|
|
906
|
-
name: "tokenProgram";
|
|
907
|
-
}>>;
|
|
20
|
+
createStream(recipient: PublicKey, mint: PublicKey, amount: anchor.BN, startTs: anchor.BN, cliffTs: anchor.BN, endTs: anchor.BN, vestingType: number, milestones: MilestoneInput[], nonce: anchor.BN, onStatus?: (phase: TxProgressPhase) => void): Promise<{
|
|
21
|
+
signature: string;
|
|
22
|
+
}>;
|
|
23
|
+
withdraw(streamPDA: PublicKey, onStatus?: (phase: TxProgressPhase) => void): Promise<{
|
|
24
|
+
signature: string;
|
|
25
|
+
}>;
|
|
26
|
+
cancel(streamPDA: PublicKey, onStatus?: (phase: TxProgressPhase) => void): Promise<{
|
|
27
|
+
signature: string;
|
|
28
|
+
}>;
|
|
29
|
+
unlockMilestone(streamPDA: PublicKey, milestoneIndex: number, onStatus?: (phase: TxProgressPhase) => void): Promise<{
|
|
30
|
+
signature: string;
|
|
31
|
+
}>;
|
|
32
|
+
editMilestone(streamPDA: PublicKey, mint: PublicKey, milestoneIndex: number, newAmount: anchor.BN, onStatus?: (phase: TxProgressPhase) => void): Promise<{
|
|
33
|
+
signature: string;
|
|
34
|
+
}>;
|
|
35
|
+
editCliff(streamPDA: PublicKey, newCliffTs: anchor.BN, onStatus?: (phase: TxProgressPhase) => void): Promise<{
|
|
36
|
+
signature: string;
|
|
37
|
+
}>;
|
|
38
|
+
editLinear(streamPDA: PublicKey, mint: PublicKey, newEndTs: anchor.BN, topupAmount: anchor.BN, onStatus?: (phase: TxProgressPhase) => void): Promise<{
|
|
39
|
+
signature: string;
|
|
40
|
+
}>;
|
|
41
|
+
private _toKitInstruction;
|
|
42
|
+
private _buildTxMessage;
|
|
908
43
|
}
|
package/dist/client.js
CHANGED
|
@@ -3,28 +3,82 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.UnifiedFlowClient = exports.SOL_USD_FEED = exports.CHAINLINK_PROGRAM_ID = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
const spl_token_1 = require("@solana/spl-token");
|
|
6
|
+
const kit_1 = require("@solana/kit");
|
|
7
|
+
const client_1 = require("@solana/client");
|
|
8
|
+
const buffer_1 = require("buffer");
|
|
6
9
|
const pda_1 = require("./pda");
|
|
10
|
+
// ─── Constants ────────────────────────────────────────────────────────────────
|
|
7
11
|
exports.CHAINLINK_PROGRAM_ID = new web3_js_1.PublicKey("HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny");
|
|
8
12
|
exports.SOL_USD_FEED = new web3_js_1.PublicKey("99B2bTijsU6f1GCT73HmdR7HCFFjGMBcPZY6jZ96ynrR");
|
|
13
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
14
|
+
function getAnchorWallet(session) {
|
|
15
|
+
return {
|
|
16
|
+
publicKey: new web3_js_1.PublicKey(session.account.address.toString()),
|
|
17
|
+
signTransaction: async (transaction) => {
|
|
18
|
+
if (session.signTransaction) {
|
|
19
|
+
return (await session.signTransaction(transaction));
|
|
20
|
+
}
|
|
21
|
+
return transaction;
|
|
22
|
+
},
|
|
23
|
+
signAllTransactions: async (transactions) => {
|
|
24
|
+
if (session.signTransaction) {
|
|
25
|
+
return (await Promise.all(transactions.map((tx) => session.signTransaction(tx))));
|
|
26
|
+
}
|
|
27
|
+
return transactions;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Build, sign, and send a kit transaction message.
|
|
33
|
+
* Mirrors the walletSignerMode pattern from withdraw.ts.
|
|
34
|
+
*/
|
|
35
|
+
async function signAndSend(transactionMessage, walletSignerMode, connection, commitment = "confirmed") {
|
|
36
|
+
if (walletSignerMode === "send") {
|
|
37
|
+
const sentSignature = await (0, kit_1.signAndSendTransactionMessageWithSigners)(transactionMessage);
|
|
38
|
+
return sentSignature.toString();
|
|
39
|
+
}
|
|
40
|
+
const signedTransaction = await (0, kit_1.signTransactionMessageWithSigners)(transactionMessage);
|
|
41
|
+
const encodedTransaction = (0, client_1.transactionToBase64)(signedTransaction);
|
|
42
|
+
const rawTransaction = buffer_1.Buffer.from(encodedTransaction, "base64");
|
|
43
|
+
const versionedTransaction = web3_js_1.VersionedTransaction.deserialize(rawTransaction);
|
|
44
|
+
const simulation = await connection.simulateTransaction(versionedTransaction, {
|
|
45
|
+
commitment,
|
|
46
|
+
sigVerify: false,
|
|
47
|
+
replaceRecentBlockhash: false,
|
|
48
|
+
});
|
|
49
|
+
if (simulation.value.err) {
|
|
50
|
+
const logs = simulation.value.logs ?? [];
|
|
51
|
+
throw new Error(["Transaction simulation failed.", ...logs.slice(-6)].filter(Boolean).join("\n"));
|
|
52
|
+
}
|
|
53
|
+
return connection.sendRawTransaction(rawTransaction, {
|
|
54
|
+
skipPreflight: true,
|
|
55
|
+
maxRetries: 3,
|
|
56
|
+
preflightCommitment: commitment,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
// ─── Client ───────────────────────────────────────────────────────────────────
|
|
9
60
|
class UnifiedFlowClient {
|
|
10
|
-
constructor(program) {
|
|
61
|
+
constructor(program, wallet, connection, commitment = "confirmed") {
|
|
11
62
|
this.program = program;
|
|
63
|
+
this.wallet = wallet;
|
|
64
|
+
this.connection = connection;
|
|
65
|
+
this.commitment = commitment;
|
|
66
|
+
const { signer, mode } = (0, client_1.createWalletTransactionSigner)(wallet);
|
|
67
|
+
this.kitSigner = signer;
|
|
68
|
+
this.walletSignerMode = mode;
|
|
12
69
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Helper to derive the config PDA
|
|
15
|
-
*/
|
|
16
70
|
getConfigPDA() {
|
|
17
71
|
return (0, pda_1.getConfigPDA)(this.program.programId)[0];
|
|
18
72
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
73
|
+
// ─── createStream ───────────────────────────────────────────────────────────
|
|
74
|
+
async createStream(recipient, mint, amount, startTs, cliffTs, endTs, vestingType, milestones, nonce, onStatus) {
|
|
75
|
+
onStatus?.("wallet_approval");
|
|
76
|
+
const creator = new web3_js_1.PublicKey(this.wallet.account.address.toString());
|
|
23
77
|
const config = this.getConfigPDA();
|
|
24
78
|
const stream = (0, pda_1.getStreamPDA)(creator, recipient, nonce, this.program.programId)[0];
|
|
25
79
|
const vault = (0, pda_1.getVaultATA)(mint, stream);
|
|
26
80
|
const creatorTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, creator, true);
|
|
27
|
-
|
|
81
|
+
let methodBuilder = this.program.methods
|
|
28
82
|
.createStream(amount, startTs, cliffTs, endTs, vestingType, milestones, nonce)
|
|
29
83
|
.accounts({
|
|
30
84
|
creator,
|
|
@@ -33,105 +87,256 @@ class UnifiedFlowClient {
|
|
|
33
87
|
creatorTokenAccount,
|
|
34
88
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
35
89
|
});
|
|
36
|
-
if (vestingType === 2 && milestones.length > 0) {
|
|
90
|
+
if (vestingType === 2 && milestones.length > 0) {
|
|
37
91
|
const remainingAccounts = milestones.map((_, i) => ({
|
|
38
92
|
pubkey: (0, pda_1.getMilestonePDA)(stream, i, this.program.programId)[0],
|
|
39
93
|
isWritable: true,
|
|
40
94
|
isSigner: false,
|
|
41
95
|
}));
|
|
42
|
-
|
|
96
|
+
methodBuilder = methodBuilder.remainingAccounts(remainingAccounts);
|
|
43
97
|
}
|
|
44
|
-
|
|
98
|
+
const anchorIx = await methodBuilder.instruction();
|
|
99
|
+
const { blockhash, lastValidBlockHeight } = await this.connection.getLatestBlockhash(this.commitment);
|
|
100
|
+
const kitIx = this._toKitInstruction(anchorIx, [
|
|
101
|
+
{ address: creator.toBase58(), role: kit_1.AccountRole.WRITABLE_SIGNER, signer: this.kitSigner },
|
|
102
|
+
{ address: recipient.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
103
|
+
{ address: mint.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
104
|
+
{ address: config.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
105
|
+
{ address: stream.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
106
|
+
{ address: vault.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
107
|
+
{ address: creatorTokenAccount.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
108
|
+
{ address: spl_token_1.TOKEN_PROGRAM_ID.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
109
|
+
{ address: web3_js_1.SystemProgram.programId.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
110
|
+
{ address: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
111
|
+
]);
|
|
112
|
+
const txMsg = this._buildTxMessage(kitIx, blockhash, lastValidBlockHeight);
|
|
113
|
+
onStatus?.("sending");
|
|
114
|
+
const signature = await signAndSend(txMsg, this.walletSignerMode, this.connection, this.commitment);
|
|
115
|
+
onStatus?.("confirming");
|
|
116
|
+
await this.connection.confirmTransaction({ blockhash, lastValidBlockHeight, signature }, this.commitment);
|
|
117
|
+
return { signature };
|
|
45
118
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
119
|
+
// ─── withdraw ───────────────────────────────────────────────────────────────
|
|
120
|
+
async withdraw(streamPDA, onStatus) {
|
|
121
|
+
onStatus?.("wallet_approval");
|
|
122
|
+
const recipient = new web3_js_1.PublicKey(this.wallet.account.address.toString());
|
|
50
123
|
const config = this.getConfigPDA();
|
|
51
|
-
const vault = (0, pda_1.getVaultATA)(mint, streamPDA);
|
|
52
|
-
const recipientAta = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, recipient, true);
|
|
53
124
|
const feeVault = (0, pda_1.getFeeVaultPDA)(this.program.programId)[0];
|
|
54
|
-
|
|
125
|
+
// Fetch stream state to get mint + vault
|
|
126
|
+
const programAny = this.program;
|
|
127
|
+
const streamState = await programAny.account.streamAccount.fetch(streamPDA);
|
|
128
|
+
const mint = streamState.mint;
|
|
129
|
+
const vault = streamState.vault;
|
|
130
|
+
const recipientAta = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, recipient, true);
|
|
131
|
+
const anchorIx = await this.program.methods
|
|
55
132
|
.withdraw()
|
|
56
133
|
.accounts({
|
|
57
134
|
recipient,
|
|
135
|
+
mint,
|
|
136
|
+
config,
|
|
58
137
|
stream: streamPDA,
|
|
138
|
+
vault,
|
|
59
139
|
recipientAta,
|
|
140
|
+
feeReceiver: feeVault,
|
|
60
141
|
chainlinkFeed: exports.SOL_USD_FEED,
|
|
61
142
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
62
|
-
|
|
143
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
144
|
+
})
|
|
145
|
+
.instruction();
|
|
146
|
+
const { blockhash, lastValidBlockHeight } = await this.connection.getLatestBlockhash(this.commitment);
|
|
147
|
+
const kitIx = this._toKitInstruction(anchorIx, [
|
|
148
|
+
{ address: recipient.toBase58(), role: kit_1.AccountRole.WRITABLE_SIGNER, signer: this.kitSigner },
|
|
149
|
+
{ address: mint.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
150
|
+
{ address: config.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
151
|
+
{ address: streamPDA.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
152
|
+
{ address: vault.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
153
|
+
{ address: recipientAta.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
154
|
+
{ address: feeVault.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
155
|
+
{ address: exports.SOL_USD_FEED.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
156
|
+
{ address: spl_token_1.TOKEN_PROGRAM_ID.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
157
|
+
{ address: web3_js_1.SystemProgram.programId.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
158
|
+
]);
|
|
159
|
+
const txMsg = this._buildTxMessage(kitIx, blockhash, lastValidBlockHeight);
|
|
160
|
+
onStatus?.("sending");
|
|
161
|
+
const signature = await signAndSend(txMsg, this.walletSignerMode, this.connection, this.commitment);
|
|
162
|
+
onStatus?.("confirming");
|
|
163
|
+
await this.connection.confirmTransaction({ blockhash, lastValidBlockHeight, signature }, this.commitment);
|
|
164
|
+
return { signature };
|
|
63
165
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
const
|
|
166
|
+
// ─── cancel ─────────────────────────────────────────────────────────────────
|
|
167
|
+
async cancel(streamPDA, onStatus) {
|
|
168
|
+
onStatus?.("wallet_approval");
|
|
169
|
+
const creator = new web3_js_1.PublicKey(this.wallet.account.address.toString());
|
|
170
|
+
const programAny = this.program;
|
|
171
|
+
const streamState = await programAny.account.streamAccount.fetch(streamPDA);
|
|
172
|
+
const mint = streamState.mint;
|
|
173
|
+
const recipient = streamState.recipient;
|
|
70
174
|
const creatorTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, creator, true);
|
|
71
175
|
const recipientTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, recipient, true);
|
|
72
|
-
|
|
176
|
+
const config = this.getConfigPDA();
|
|
177
|
+
const vault = (0, pda_1.getVaultATA)(mint, streamPDA);
|
|
178
|
+
const anchorIx = await this.program.methods
|
|
73
179
|
.cancel()
|
|
74
180
|
.accounts({
|
|
75
181
|
creator,
|
|
76
182
|
stream: streamPDA,
|
|
183
|
+
config,
|
|
184
|
+
vault,
|
|
77
185
|
creatorTokenAccount,
|
|
78
186
|
recipientTokenAccount,
|
|
79
187
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
80
|
-
})
|
|
188
|
+
})
|
|
189
|
+
.instruction();
|
|
190
|
+
const { blockhash, lastValidBlockHeight } = await this.connection.getLatestBlockhash(this.commitment);
|
|
191
|
+
const kitIx = this._toKitInstruction(anchorIx, [
|
|
192
|
+
{ address: creator.toBase58(), role: kit_1.AccountRole.WRITABLE_SIGNER, signer: this.kitSigner },
|
|
193
|
+
{ address: streamPDA.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
194
|
+
{ address: config.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
195
|
+
{ address: vault.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
196
|
+
{ address: creatorTokenAccount.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
197
|
+
{ address: recipientTokenAccount.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
198
|
+
{ address: spl_token_1.TOKEN_PROGRAM_ID.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
199
|
+
]);
|
|
200
|
+
const txMsg = this._buildTxMessage(kitIx, blockhash, lastValidBlockHeight);
|
|
201
|
+
onStatus?.("sending");
|
|
202
|
+
const signature = await signAndSend(txMsg, this.walletSignerMode, this.connection, this.commitment);
|
|
203
|
+
onStatus?.("confirming");
|
|
204
|
+
await this.connection.confirmTransaction({ blockhash, lastValidBlockHeight, signature }, this.commitment);
|
|
205
|
+
return { signature };
|
|
81
206
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
207
|
+
// ─── unlockMilestone ────────────────────────────────────────────────────────
|
|
208
|
+
async unlockMilestone(streamPDA, milestoneIndex, onStatus) {
|
|
209
|
+
onStatus?.("wallet_approval");
|
|
210
|
+
const creator = new web3_js_1.PublicKey(this.wallet.account.address.toString());
|
|
86
211
|
const milestonePDA = (0, pda_1.getMilestonePDA)(streamPDA, milestoneIndex, this.program.programId)[0];
|
|
87
|
-
|
|
212
|
+
const anchorIx = await this.program.methods
|
|
88
213
|
.unlockMilestone()
|
|
89
214
|
.accounts({
|
|
215
|
+
creator,
|
|
90
216
|
stream: streamPDA,
|
|
91
217
|
milestone: milestonePDA,
|
|
92
|
-
})
|
|
218
|
+
})
|
|
219
|
+
.instruction();
|
|
220
|
+
const { blockhash, lastValidBlockHeight } = await this.connection.getLatestBlockhash(this.commitment);
|
|
221
|
+
const kitIx = this._toKitInstruction(anchorIx, [
|
|
222
|
+
{ address: creator.toBase58(), role: kit_1.AccountRole.WRITABLE_SIGNER, signer: this.kitSigner },
|
|
223
|
+
{ address: streamPDA.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
224
|
+
{ address: milestonePDA.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
225
|
+
]);
|
|
226
|
+
const txMsg = this._buildTxMessage(kitIx, blockhash, lastValidBlockHeight);
|
|
227
|
+
onStatus?.("sending");
|
|
228
|
+
const signature = await signAndSend(txMsg, this.walletSignerMode, this.connection, this.commitment);
|
|
229
|
+
onStatus?.("confirming");
|
|
230
|
+
await this.connection.confirmTransaction({ blockhash, lastValidBlockHeight, signature }, this.commitment);
|
|
231
|
+
return { signature };
|
|
93
232
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
233
|
+
// ─── editMilestone ──────────────────────────────────────────────────────────
|
|
234
|
+
async editMilestone(streamPDA, mint, milestoneIndex, newAmount, onStatus) {
|
|
235
|
+
onStatus?.("wallet_approval");
|
|
236
|
+
const creator = new web3_js_1.PublicKey(this.wallet.account.address.toString());
|
|
98
237
|
const milestonePDA = (0, pda_1.getMilestonePDA)(streamPDA, milestoneIndex, this.program.programId)[0];
|
|
99
238
|
const vault = (0, pda_1.getVaultATA)(mint, streamPDA);
|
|
100
239
|
const creatorTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, creator, true);
|
|
101
|
-
|
|
240
|
+
const anchorIx = await this.program.methods
|
|
102
241
|
.editMilestone(newAmount)
|
|
103
242
|
.accounts({
|
|
243
|
+
creator,
|
|
104
244
|
stream: streamPDA,
|
|
105
245
|
milestone: milestonePDA,
|
|
246
|
+
vault,
|
|
106
247
|
creatorTokenAccount,
|
|
107
248
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
108
|
-
})
|
|
249
|
+
})
|
|
250
|
+
.instruction();
|
|
251
|
+
const { blockhash, lastValidBlockHeight } = await this.connection.getLatestBlockhash(this.commitment);
|
|
252
|
+
const kitIx = this._toKitInstruction(anchorIx, [
|
|
253
|
+
{ address: creator.toBase58(), role: kit_1.AccountRole.WRITABLE_SIGNER, signer: this.kitSigner },
|
|
254
|
+
{ address: streamPDA.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
255
|
+
{ address: milestonePDA.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
256
|
+
{ address: vault.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
257
|
+
{ address: creatorTokenAccount.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
258
|
+
{ address: spl_token_1.TOKEN_PROGRAM_ID.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
259
|
+
]);
|
|
260
|
+
const txMsg = this._buildTxMessage(kitIx, blockhash, lastValidBlockHeight);
|
|
261
|
+
onStatus?.("sending");
|
|
262
|
+
const signature = await signAndSend(txMsg, this.walletSignerMode, this.connection, this.commitment);
|
|
263
|
+
onStatus?.("confirming");
|
|
264
|
+
await this.connection.confirmTransaction({ blockhash, lastValidBlockHeight, signature }, this.commitment);
|
|
265
|
+
return { signature };
|
|
109
266
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
267
|
+
// ─── editCliff ──────────────────────────────────────────────────────────────
|
|
268
|
+
async editCliff(streamPDA, newCliffTs, onStatus) {
|
|
269
|
+
onStatus?.("wallet_approval");
|
|
270
|
+
const creator = new web3_js_1.PublicKey(this.wallet.account.address.toString());
|
|
114
271
|
const config = this.getConfigPDA();
|
|
115
|
-
|
|
272
|
+
const anchorIx = await this.program.methods
|
|
116
273
|
.editCliff(newCliffTs)
|
|
117
274
|
.accounts({
|
|
275
|
+
creator,
|
|
118
276
|
stream: streamPDA,
|
|
119
|
-
|
|
277
|
+
config,
|
|
278
|
+
})
|
|
279
|
+
.instruction();
|
|
280
|
+
const { blockhash, lastValidBlockHeight } = await this.connection.getLatestBlockhash(this.commitment);
|
|
281
|
+
const kitIx = this._toKitInstruction(anchorIx, [
|
|
282
|
+
{ address: creator.toBase58(), role: kit_1.AccountRole.WRITABLE_SIGNER, signer: this.kitSigner },
|
|
283
|
+
{ address: streamPDA.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
284
|
+
{ address: config.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
285
|
+
]);
|
|
286
|
+
const txMsg = this._buildTxMessage(kitIx, blockhash, lastValidBlockHeight);
|
|
287
|
+
onStatus?.("sending");
|
|
288
|
+
const signature = await signAndSend(txMsg, this.walletSignerMode, this.connection, this.commitment);
|
|
289
|
+
onStatus?.("confirming");
|
|
290
|
+
await this.connection.confirmTransaction({ blockhash, lastValidBlockHeight, signature }, this.commitment);
|
|
291
|
+
return { signature };
|
|
120
292
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
293
|
+
// ─── editLinear ─────────────────────────────────────────────────────────────
|
|
294
|
+
async editLinear(streamPDA, mint, newEndTs, topupAmount, onStatus) {
|
|
295
|
+
onStatus?.("wallet_approval");
|
|
296
|
+
const creator = new web3_js_1.PublicKey(this.wallet.account.address.toString());
|
|
125
297
|
const config = this.getConfigPDA();
|
|
126
298
|
const vault = (0, pda_1.getVaultATA)(mint, streamPDA);
|
|
127
299
|
const creatorTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, creator, true);
|
|
128
|
-
|
|
300
|
+
const anchorIx = await this.program.methods
|
|
129
301
|
.editLinear(newEndTs, topupAmount)
|
|
130
302
|
.accounts({
|
|
303
|
+
creator,
|
|
131
304
|
stream: streamPDA,
|
|
305
|
+
config,
|
|
306
|
+
vault,
|
|
132
307
|
creatorTokenAccount,
|
|
133
308
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
134
|
-
})
|
|
309
|
+
})
|
|
310
|
+
.instruction();
|
|
311
|
+
const { blockhash, lastValidBlockHeight } = await this.connection.getLatestBlockhash(this.commitment);
|
|
312
|
+
const kitIx = this._toKitInstruction(anchorIx, [
|
|
313
|
+
{ address: creator.toBase58(), role: kit_1.AccountRole.WRITABLE_SIGNER, signer: this.kitSigner },
|
|
314
|
+
{ address: streamPDA.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
315
|
+
{ address: config.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
316
|
+
{ address: vault.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
317
|
+
{ address: creatorTokenAccount.toBase58(), role: kit_1.AccountRole.WRITABLE },
|
|
318
|
+
{ address: spl_token_1.TOKEN_PROGRAM_ID.toBase58(), role: kit_1.AccountRole.READONLY },
|
|
319
|
+
]);
|
|
320
|
+
const txMsg = this._buildTxMessage(kitIx, blockhash, lastValidBlockHeight);
|
|
321
|
+
onStatus?.("sending");
|
|
322
|
+
const signature = await signAndSend(txMsg, this.walletSignerMode, this.connection, this.commitment);
|
|
323
|
+
onStatus?.("confirming");
|
|
324
|
+
await this.connection.confirmTransaction({ blockhash, lastValidBlockHeight, signature }, this.commitment);
|
|
325
|
+
return { signature };
|
|
326
|
+
}
|
|
327
|
+
// ─── Private helpers ─────────────────────────────────────────────────────────
|
|
328
|
+
_toKitInstruction(anchorIx, accounts) {
|
|
329
|
+
return {
|
|
330
|
+
programAddress: anchorIx.programId.toBase58(),
|
|
331
|
+
accounts,
|
|
332
|
+
data: anchorIx.data,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
_buildTxMessage(kitIx, blockhash, lastValidBlockHeight) {
|
|
336
|
+
let txMsg = (0, kit_1.setTransactionMessageFeePayerSigner)(this.kitSigner, (0, kit_1.createTransactionMessage)({ version: 0 }));
|
|
337
|
+
txMsg = (0, kit_1.appendTransactionMessageInstruction)(kitIx, txMsg);
|
|
338
|
+
txMsg = (0, kit_1.setTransactionMessageLifetimeUsingBlockhash)({ blockhash: blockhash, lastValidBlockHeight: BigInt(lastValidBlockHeight) }, txMsg);
|
|
339
|
+
return txMsg;
|
|
135
340
|
}
|
|
136
341
|
}
|
|
137
342
|
exports.UnifiedFlowClient = UnifiedFlowClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unifiedflow/unified-flow-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "SDK for the Unified Flow program",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@coral-xyz/anchor": "^0.32.1",
|
|
16
|
+
"@solana/client": "^1.7.0",
|
|
16
17
|
"@solana/spl-token": "^0.4.0",
|
|
17
18
|
"@solana/web3.js": "^1.90.0"
|
|
18
19
|
},
|