@unifiedflow/unified-flow-sdk 1.0.0

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.js ADDED
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnifiedFlowClient = exports.SOL_USD_FEED = exports.CHAINLINK_PROGRAM_ID = void 0;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ const spl_token_1 = require("@solana/spl-token");
6
+ const pda_1 = require("./pda");
7
+ exports.CHAINLINK_PROGRAM_ID = new web3_js_1.PublicKey("HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny");
8
+ exports.SOL_USD_FEED = new web3_js_1.PublicKey("99B2bTijsU6f1GCT73HmdR7HCFFjGMBcPZY6jZ96ynrR");
9
+ class UnifiedFlowClient {
10
+ constructor(program) {
11
+ this.program = program;
12
+ }
13
+ /**
14
+ * Helper to derive the config PDA
15
+ */
16
+ getConfigPDA() {
17
+ return (0, pda_1.getConfigPDA)(this.program.programId)[0];
18
+ }
19
+ /**
20
+ * Create a new stream (Linear, Cliff, or Milestone)
21
+ */
22
+ async createStream(creator, recipient, mint, amount, startTs, cliffTs, endTs, vestingType, milestones, nonce) {
23
+ const config = this.getConfigPDA();
24
+ const stream = (0, pda_1.getStreamPDA)(creator, recipient, nonce, this.program.programId)[0];
25
+ const vault = (0, pda_1.getVaultATA)(mint, stream);
26
+ const creatorTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, creator, true);
27
+ const builder = this.program.methods
28
+ .createStream(amount, startTs, cliffTs, endTs, vestingType, milestones, nonce)
29
+ .accounts({
30
+ creator,
31
+ recipient,
32
+ mint,
33
+ creatorTokenAccount,
34
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
35
+ });
36
+ if (vestingType === 2 && milestones.length > 0) { // VESTING_TYPE_MILESTONE = 2
37
+ const remainingAccounts = milestones.map((_, i) => ({
38
+ pubkey: (0, pda_1.getMilestonePDA)(stream, i, this.program.programId)[0],
39
+ isWritable: true,
40
+ isSigner: false,
41
+ }));
42
+ builder.remainingAccounts(remainingAccounts);
43
+ }
44
+ return builder;
45
+ }
46
+ /**
47
+ * Withdraw unlocked/vested tokens from a stream
48
+ */
49
+ async withdraw(streamPDA, recipient, mint) {
50
+ 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
+ const feeVault = (0, pda_1.getFeeVaultPDA)(this.program.programId)[0];
54
+ return this.program.methods
55
+ .withdraw()
56
+ .accounts({
57
+ recipient,
58
+ stream: streamPDA,
59
+ recipientAta,
60
+ chainlinkFeed: exports.SOL_USD_FEED,
61
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
62
+ });
63
+ }
64
+ /**
65
+ * Cancel an active stream and return remaining tokens to the creator
66
+ */
67
+ async cancel(streamPDA, creator, recipient, mint) {
68
+ const config = this.getConfigPDA();
69
+ const vault = (0, pda_1.getVaultATA)(mint, streamPDA);
70
+ const creatorTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, creator, true);
71
+ const recipientTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, recipient, true);
72
+ return this.program.methods
73
+ .cancel()
74
+ .accounts({
75
+ creator,
76
+ stream: streamPDA,
77
+ creatorTokenAccount,
78
+ recipientTokenAccount,
79
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
80
+ });
81
+ }
82
+ /**
83
+ * Unlock a specific milestone
84
+ */
85
+ async unlockMilestone(streamPDA, creator, milestoneIndex) {
86
+ const milestonePDA = (0, pda_1.getMilestonePDA)(streamPDA, milestoneIndex, this.program.programId)[0];
87
+ return this.program.methods
88
+ .unlockMilestone()
89
+ .accounts({
90
+ stream: streamPDA,
91
+ milestone: milestonePDA,
92
+ });
93
+ }
94
+ /**
95
+ * Edit a milestone's amount (increase or decrease)
96
+ */
97
+ async editMilestone(streamPDA, creator, mint, milestoneIndex, newAmount) {
98
+ const milestonePDA = (0, pda_1.getMilestonePDA)(streamPDA, milestoneIndex, this.program.programId)[0];
99
+ const vault = (0, pda_1.getVaultATA)(mint, streamPDA);
100
+ const creatorTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, creator, true);
101
+ return this.program.methods
102
+ .editMilestone(newAmount)
103
+ .accounts({
104
+ stream: streamPDA,
105
+ milestone: milestonePDA,
106
+ creatorTokenAccount,
107
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
108
+ });
109
+ }
110
+ /**
111
+ * Edit the cliff timestamp of a cliff vesting stream
112
+ */
113
+ async editCliff(streamPDA, creator, newCliffTs) {
114
+ const config = this.getConfigPDA();
115
+ return this.program.methods
116
+ .editCliff(newCliffTs)
117
+ .accounts({
118
+ stream: streamPDA,
119
+ });
120
+ }
121
+ /**
122
+ * Edit a linear stream's end timestamp and/or top up tokens
123
+ */
124
+ async editLinear(streamPDA, creator, mint, newEndTs, topupAmount) {
125
+ const config = this.getConfigPDA();
126
+ const vault = (0, pda_1.getVaultATA)(mint, streamPDA);
127
+ const creatorTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, creator, true);
128
+ return this.program.methods
129
+ .editLinear(newEndTs, topupAmount)
130
+ .accounts({
131
+ stream: streamPDA,
132
+ creatorTokenAccount,
133
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
134
+ });
135
+ }
136
+ }
137
+ exports.UnifiedFlowClient = UnifiedFlowClient;
@@ -0,0 +1,5 @@
1
+ export * from "./types";
2
+ export * from "./pda";
3
+ export * from "./client";
4
+ import IDL from "./unified_flow.json";
5
+ export { IDL };
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.IDL = void 0;
21
+ __exportStar(require("./types"), exports);
22
+ __exportStar(require("./pda"), exports);
23
+ __exportStar(require("./client"), exports);
24
+ const unified_flow_json_1 = __importDefault(require("./unified_flow.json"));
25
+ exports.IDL = unified_flow_json_1.default;
package/dist/pda.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { BN } from "@coral-xyz/anchor";
3
+ export declare const UNIFIED_FLOW_PROGRAM_ID: PublicKey;
4
+ export declare function getConfigPDA(programId?: PublicKey): [PublicKey, number];
5
+ export declare function getFeeVaultPDA(programId?: PublicKey): [PublicKey, number];
6
+ export declare function getStreamPDA(creator: PublicKey, recipient: PublicKey, nonce: BN, programId?: PublicKey): [PublicKey, number];
7
+ export declare function getMilestonePDA(stream: PublicKey, index: number, programId?: PublicKey): [PublicKey, number];
8
+ export declare function getVaultATA(mint: PublicKey, stream: PublicKey): PublicKey;
package/dist/pda.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UNIFIED_FLOW_PROGRAM_ID = void 0;
4
+ exports.getConfigPDA = getConfigPDA;
5
+ exports.getFeeVaultPDA = getFeeVaultPDA;
6
+ exports.getStreamPDA = getStreamPDA;
7
+ exports.getMilestonePDA = getMilestonePDA;
8
+ exports.getVaultATA = getVaultATA;
9
+ const web3_js_1 = require("@solana/web3.js");
10
+ const spl_token_1 = require("@solana/spl-token");
11
+ exports.UNIFIED_FLOW_PROGRAM_ID = new web3_js_1.PublicKey("8M5yieUh7pxwUi1YBByDF82nqoorZwaKi8dBoMVpurFa");
12
+ function getConfigPDA(programId = exports.UNIFIED_FLOW_PROGRAM_ID) {
13
+ return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("config")], programId);
14
+ }
15
+ function getFeeVaultPDA(programId = exports.UNIFIED_FLOW_PROGRAM_ID) {
16
+ return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("fee_vault")], programId);
17
+ }
18
+ function getStreamPDA(creator, recipient, nonce, programId = exports.UNIFIED_FLOW_PROGRAM_ID) {
19
+ const nonceBuffer = Buffer.alloc(8);
20
+ nonceBuffer.writeBigUInt64LE(BigInt(nonce.toString()));
21
+ return web3_js_1.PublicKey.findProgramAddressSync([
22
+ Buffer.from("stream"),
23
+ creator.toBuffer(),
24
+ recipient.toBuffer(),
25
+ nonceBuffer,
26
+ ], programId);
27
+ }
28
+ function getMilestonePDA(stream, index, programId = exports.UNIFIED_FLOW_PROGRAM_ID) {
29
+ return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("milestone"), stream.toBuffer(), Buffer.from([index])], programId);
30
+ }
31
+ function getVaultATA(mint, stream) {
32
+ return (0, spl_token_1.getAssociatedTokenAddressSync)(mint, stream, true);
33
+ }