@unifiedflow/unified-flow-sdk 1.0.2 → 1.0.4
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 +196 -144
- package/dist/client.d.ts +38 -903
- package/dist/client.js +257 -52
- package/package.json +1 -1
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;
|