@occa/sdk 0.4.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.
@@ -0,0 +1,658 @@
1
+ import {
2
+ deriveAgentIdentityPda,
3
+ deriveCompanyPda,
4
+ deriveDailyAnchorPda,
5
+ deriveDeploymentPda,
6
+ deriveOperationsPda,
7
+ derivePolicyPda,
8
+ deriveProtocolFeePda,
9
+ deriveTreasuryPda,
10
+ u32LeBytes
11
+ } from "./chunk-X6FBCGHU.js";
12
+ import {
13
+ REGISTRY_PROGRAM_ID,
14
+ SOL_PSEUDO_MINT,
15
+ TREASURY_PROGRAM_ID
16
+ } from "./chunk-YCSBYRSH.js";
17
+
18
+ // src/instructions.ts
19
+ import {
20
+ SystemProgram,
21
+ TransactionInstruction
22
+ } from "@solana/web3.js";
23
+ var INSTRUCTION_DISCRIMINATOR = {
24
+ createCompany: Buffer.from([36, 192, 217, 147, 233, 129, 198, 18]),
25
+ updateCompanyMetadata: Buffer.from([186, 229, 190, 16, 234, 141, 170, 89]),
26
+ updateCompanyStatus: Buffer.from([61, 6, 101, 120, 141, 13, 125, 75]),
27
+ registerAgentIdentity: Buffer.from([57, 31, 242, 205, 57, 129, 123, 35]),
28
+ updateAgentIdentityMetadata: Buffer.from([
29
+ 250,
30
+ 182,
31
+ 24,
32
+ 200,
33
+ 201,
34
+ 147,
35
+ 60,
36
+ 183
37
+ ]),
38
+ createDeployment: Buffer.from([55, 207, 186, 101, 21, 218, 102, 171]),
39
+ updateDeploymentMetadata: Buffer.from([100, 135, 41, 32, 16, 41, 29, 76]),
40
+ updateDeploymentStatus: Buffer.from([225, 195, 150, 254, 178, 203, 53, 147]),
41
+ retireDeployment: Buffer.from([45, 188, 162, 197, 136, 180, 202, 153]),
42
+ setReceivingAddress: Buffer.from([70, 63, 44, 87, 16, 6, 156, 200]),
43
+ commitDailyAnchor: Buffer.from([18, 7, 3, 65, 58, 148, 164, 0])
44
+ };
45
+ function encodeString(s) {
46
+ const utf8 = Buffer.from(s, "utf8");
47
+ const len = Buffer.alloc(4);
48
+ len.writeUInt32LE(utf8.length, 0);
49
+ return Buffer.concat([len, utf8]);
50
+ }
51
+ function encodePubkey(pk) {
52
+ return Buffer.from(pk.toBytes());
53
+ }
54
+ function encodeU8(n) {
55
+ if (!Number.isInteger(n) || n < 0 || n > 255) {
56
+ throw new RangeError(`u8 out of range: ${n}`);
57
+ }
58
+ return Buffer.from([n]);
59
+ }
60
+ function encodeMetadataHash(hash) {
61
+ if (hash.length !== 32) {
62
+ throw new RangeError(`metadata_hash must be 32 bytes, got ${hash.length}`);
63
+ }
64
+ return Buffer.from(hash);
65
+ }
66
+ function encodeOptionU32(value) {
67
+ if (value === null || value === void 0) {
68
+ return Buffer.from([0]);
69
+ }
70
+ return Buffer.concat([Buffer.from([1]), u32LeBytes(value)]);
71
+ }
72
+ function buildCreateCompanyInstruction(params) {
73
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
74
+ const { pda: companyPda, bump } = deriveCompanyPda(
75
+ params.owner,
76
+ params.nonce,
77
+ programId
78
+ );
79
+ const { pda: treasuryPda } = deriveTreasuryPda(companyPda);
80
+ const { pda: policyPda } = derivePolicyPda(companyPda);
81
+ const data = Buffer.concat([
82
+ INSTRUCTION_DISCRIMINATOR.createCompany,
83
+ u32LeBytes(params.nonce),
84
+ encodeString(params.name),
85
+ encodeString(params.locale),
86
+ encodeString(params.metadataUri),
87
+ encodeMetadataHash(params.metadataHash)
88
+ ]);
89
+ const instruction = new TransactionInstruction({
90
+ programId,
91
+ // Order MUST match registry/lib.rs `CreateCompany` accounts struct:
92
+ // company, owner, payer, treasury, policy, treasury_program, system_program.
93
+ keys: [
94
+ { pubkey: companyPda, isSigner: false, isWritable: true },
95
+ { pubkey: params.owner, isSigner: true, isWritable: false },
96
+ { pubkey: params.payer, isSigner: true, isWritable: true },
97
+ { pubkey: treasuryPda, isSigner: false, isWritable: true },
98
+ { pubkey: policyPda, isSigner: false, isWritable: true },
99
+ { pubkey: TREASURY_PROGRAM_ID, isSigner: false, isWritable: false },
100
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }
101
+ ],
102
+ data
103
+ });
104
+ return { instruction, companyPda, treasuryPda, policyPda, bump };
105
+ }
106
+ function buildUpdateCompanyMetadataInstruction(params) {
107
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
108
+ const data = Buffer.concat([
109
+ INSTRUCTION_DISCRIMINATOR.updateCompanyMetadata,
110
+ encodeString(params.name),
111
+ encodeString(params.locale),
112
+ encodeString(params.metadataUri),
113
+ encodeMetadataHash(params.metadataHash)
114
+ ]);
115
+ const instruction = new TransactionInstruction({
116
+ programId,
117
+ keys: [
118
+ { pubkey: params.companyPda, isSigner: false, isWritable: true },
119
+ { pubkey: params.owner, isSigner: true, isWritable: false }
120
+ ],
121
+ data
122
+ });
123
+ return { instruction };
124
+ }
125
+ function buildUpdateCompanyStatusInstruction(params) {
126
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
127
+ const data = Buffer.concat([
128
+ INSTRUCTION_DISCRIMINATOR.updateCompanyStatus,
129
+ encodeU8(params.newStatus)
130
+ ]);
131
+ const instruction = new TransactionInstruction({
132
+ programId,
133
+ keys: [
134
+ { pubkey: params.companyPda, isSigner: false, isWritable: true },
135
+ { pubkey: params.owner, isSigner: true, isWritable: false }
136
+ ],
137
+ data
138
+ });
139
+ return { instruction };
140
+ }
141
+ function buildRegisterAgentIdentityInstruction(params) {
142
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
143
+ const { pda: identityPda, bump } = deriveAgentIdentityPda(
144
+ params.agentPubkey,
145
+ programId
146
+ );
147
+ const data = Buffer.concat([
148
+ INSTRUCTION_DISCRIMINATOR.registerAgentIdentity,
149
+ encodePubkey(params.agentPubkey),
150
+ encodeString(params.name),
151
+ encodeString(params.metadataUri),
152
+ encodeMetadataHash(params.metadataHash)
153
+ ]);
154
+ const instruction = new TransactionInstruction({
155
+ programId,
156
+ keys: [
157
+ { pubkey: identityPda, isSigner: false, isWritable: true },
158
+ { pubkey: params.owner, isSigner: true, isWritable: false },
159
+ { pubkey: params.payer, isSigner: true, isWritable: true },
160
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }
161
+ ],
162
+ data
163
+ });
164
+ return { instruction, identityPda, bump };
165
+ }
166
+ function buildUpdateAgentIdentityMetadataInstruction(params) {
167
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
168
+ const data = Buffer.concat([
169
+ INSTRUCTION_DISCRIMINATOR.updateAgentIdentityMetadata,
170
+ encodeString(params.name),
171
+ encodeString(params.metadataUri),
172
+ encodeMetadataHash(params.metadataHash)
173
+ ]);
174
+ const instruction = new TransactionInstruction({
175
+ programId,
176
+ keys: [
177
+ { pubkey: params.identityPda, isSigner: false, isWritable: true },
178
+ { pubkey: params.owner, isSigner: true, isWritable: false }
179
+ ],
180
+ data
181
+ });
182
+ return { instruction };
183
+ }
184
+ function buildCreateDeploymentInstruction(params) {
185
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
186
+ const { pda: deploymentPda, bump } = deriveDeploymentPda(
187
+ params.companyPda,
188
+ params.deploymentIndex,
189
+ programId
190
+ );
191
+ const data = Buffer.concat([
192
+ INSTRUCTION_DISCRIMINATOR.createDeployment,
193
+ u32LeBytes(params.deploymentIndex),
194
+ encodeString(params.role),
195
+ encodeOptionU32(params.parentDeploymentIndex),
196
+ encodePubkey(params.adapterId),
197
+ encodeString(params.metadataUri),
198
+ encodeMetadataHash(params.metadataHash)
199
+ ]);
200
+ const instruction = new TransactionInstruction({
201
+ programId,
202
+ keys: [
203
+ // Order matches the on-chain `CreateDeployment` accounts struct.
204
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
205
+ { pubkey: params.identityPda, isSigner: false, isWritable: false },
206
+ { pubkey: params.owner, isSigner: true, isWritable: false },
207
+ { pubkey: deploymentPda, isSigner: false, isWritable: true },
208
+ { pubkey: params.payer, isSigner: true, isWritable: true },
209
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }
210
+ ],
211
+ data
212
+ });
213
+ return { instruction, deploymentPda, bump };
214
+ }
215
+ function buildUpdateDeploymentMetadataInstruction(params) {
216
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
217
+ const data = Buffer.concat([
218
+ INSTRUCTION_DISCRIMINATOR.updateDeploymentMetadata,
219
+ encodeString(params.role),
220
+ encodeString(params.metadataUri),
221
+ encodeMetadataHash(params.metadataHash)
222
+ ]);
223
+ const instruction = new TransactionInstruction({
224
+ programId,
225
+ keys: [
226
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: true },
227
+ { pubkey: params.owner, isSigner: true, isWritable: false }
228
+ ],
229
+ data
230
+ });
231
+ return { instruction };
232
+ }
233
+ function buildUpdateDeploymentStatusInstruction(params) {
234
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
235
+ const data = Buffer.concat([
236
+ INSTRUCTION_DISCRIMINATOR.updateDeploymentStatus,
237
+ encodeU8(params.newStatus)
238
+ ]);
239
+ const instruction = new TransactionInstruction({
240
+ programId,
241
+ keys: [
242
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: true },
243
+ { pubkey: params.owner, isSigner: true, isWritable: false }
244
+ ],
245
+ data
246
+ });
247
+ return { instruction };
248
+ }
249
+ function buildRetireDeploymentInstruction(params) {
250
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
251
+ const instruction = new TransactionInstruction({
252
+ programId,
253
+ keys: [
254
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: true },
255
+ { pubkey: params.owner, isSigner: true, isWritable: false }
256
+ ],
257
+ data: Buffer.from(INSTRUCTION_DISCRIMINATOR.retireDeployment)
258
+ });
259
+ return { instruction };
260
+ }
261
+ function buildSetReceivingAddressInstruction(params) {
262
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
263
+ const data = Buffer.concat([
264
+ INSTRUCTION_DISCRIMINATOR.setReceivingAddress,
265
+ encodePubkey(params.newReceivingAddress)
266
+ ]);
267
+ const instruction = new TransactionInstruction({
268
+ programId,
269
+ keys: [
270
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: true },
271
+ { pubkey: params.owner, isSigner: true, isWritable: false }
272
+ ],
273
+ data
274
+ });
275
+ return { instruction };
276
+ }
277
+ var TREASURY_INSTRUCTION_DISCRIMINATOR = {
278
+ setPolicy: Buffer.from([40, 133, 12, 157, 235, 202, 2, 132]),
279
+ disburseDiscretionary: Buffer.from([102, 176, 14, 127, 210, 4, 96, 175]),
280
+ initProtocolFeeAccount: Buffer.from([214, 27, 184, 174, 155, 79, 141, 114]),
281
+ registerCompanyOperations: Buffer.from([212, 173, 142, 23, 28, 221, 55, 99]),
282
+ updateOperationsCapability: Buffer.from([21, 13, 197, 41, 92, 229, 142, 202]),
283
+ revokeOperations: Buffer.from([141, 196, 241, 103, 182, 146, 117, 183]),
284
+ closeOperations: Buffer.from([2, 52, 136, 225, 80, 230, 222, 120]),
285
+ disburseRoutine: Buffer.from([45, 152, 225, 130, 133, 73, 62, 202]),
286
+ disbursePrivileged: Buffer.from([173, 78, 248, 158, 76, 46, 88, 167])
287
+ };
288
+ function encodeU16(n) {
289
+ if (!Number.isInteger(n) || n < 0 || n > 65535) {
290
+ throw new RangeError(`u16 out of range: ${n}`);
291
+ }
292
+ const buf = Buffer.alloc(2);
293
+ buf.writeUInt16LE(n, 0);
294
+ return buf;
295
+ }
296
+ function encodeU64(n) {
297
+ if (n < 0n || n > 0xffffffffffffffffn) {
298
+ throw new RangeError(`u64 out of range: ${n}`);
299
+ }
300
+ const buf = Buffer.alloc(8);
301
+ buf.writeBigUInt64LE(n, 0);
302
+ return buf;
303
+ }
304
+ function encodeAssetBudget(b) {
305
+ return Buffer.concat([encodePubkey(b.mint), encodeU64(b.amount)]);
306
+ }
307
+ function encodeVec(items, encodeItem) {
308
+ return Buffer.concat([u32LeBytes(items.length), ...items.map(encodeItem)]);
309
+ }
310
+ function encodeOption(value, encodeSome) {
311
+ if (value === null || value === void 0) return Buffer.from([0]);
312
+ return Buffer.concat([Buffer.from([1]), encodeSome(value)]);
313
+ }
314
+ function buildSetPolicyInstruction(params) {
315
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
316
+ function encodeSecondarySigner(v) {
317
+ if (v === void 0) return Buffer.from([0]);
318
+ if (v === null) return Buffer.from([1, 0]);
319
+ return Buffer.concat([Buffer.from([1, 1]), encodePubkey(v)]);
320
+ }
321
+ const data = Buffer.concat([
322
+ TREASURY_INSTRUCTION_DISCRIMINATOR.setPolicy,
323
+ // 1. routine_budget_per_month: Option<Vec<AssetBudget>>
324
+ encodeOption(
325
+ params.routineBudgetPerMonth,
326
+ (v) => encodeVec(v, encodeAssetBudget)
327
+ ),
328
+ // 2. discretionary_budget_per_month: Option<Vec<AssetBudget>>
329
+ encodeOption(
330
+ params.discretionaryBudgetPerMonth,
331
+ (v) => encodeVec(v, encodeAssetBudget)
332
+ ),
333
+ // 3. privileged_threshold_lamports: Option<u64>
334
+ encodeOption(params.privilegedThresholdLamports, encodeU64),
335
+ // 4. privileged_threshold_per_token: Option<Vec<AssetBudget>>
336
+ encodeOption(
337
+ params.privilegedThresholdPerToken,
338
+ (v) => encodeVec(v, encodeAssetBudget)
339
+ ),
340
+ // 5. secondary_signer: Option<Option<Pubkey>>
341
+ encodeSecondarySigner(params.secondarySigner),
342
+ // 6. agent_operating_fee_bps: Option<u16>
343
+ encodeOption(params.agentOperatingFeeBps, encodeU16),
344
+ // 7. accepted_assets: Option<Vec<Pubkey>>
345
+ encodeOption(params.acceptedAssets, (v) => encodeVec(v, encodePubkey))
346
+ ]);
347
+ const instruction = new TransactionInstruction({
348
+ programId,
349
+ // Order: company, controlling_authority, treasury, policy.
350
+ keys: [
351
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
352
+ {
353
+ pubkey: params.controllingAuthority,
354
+ isSigner: true,
355
+ isWritable: false
356
+ },
357
+ { pubkey: params.treasuryPda, isSigner: false, isWritable: true },
358
+ { pubkey: params.policyPda, isSigner: false, isWritable: true }
359
+ ],
360
+ data
361
+ });
362
+ return { instruction };
363
+ }
364
+ function buildDisburseDiscretionaryInstruction(params) {
365
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
366
+ const mint = params.mint ?? SOL_PSEUDO_MINT;
367
+ const { pda: protocolFeePda } = deriveProtocolFeePda();
368
+ const data = Buffer.concat([
369
+ TREASURY_INSTRUCTION_DISCRIMINATOR.disburseDiscretionary,
370
+ encodePubkey(mint),
371
+ encodeU64(params.amountLamports)
372
+ ]);
373
+ const instruction = new TransactionInstruction({
374
+ programId,
375
+ // Order: company, controlling_authority, treasury, policy,
376
+ // deployment, destination, protocol_fee_account.
377
+ keys: [
378
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
379
+ {
380
+ pubkey: params.controllingAuthority,
381
+ isSigner: true,
382
+ isWritable: false
383
+ },
384
+ { pubkey: params.treasuryPda, isSigner: false, isWritable: true },
385
+ { pubkey: params.policyPda, isSigner: false, isWritable: true },
386
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: false },
387
+ { pubkey: params.destination, isSigner: false, isWritable: true },
388
+ { pubkey: protocolFeePda, isSigner: false, isWritable: true }
389
+ ],
390
+ data
391
+ });
392
+ return { instruction };
393
+ }
394
+ function encodeI64(n) {
395
+ const buf = Buffer.alloc(8);
396
+ buf.writeBigInt64LE(n, 0);
397
+ return buf;
398
+ }
399
+ function encodeBool(b) {
400
+ return Buffer.from([b ? 1 : 0]);
401
+ }
402
+ function encodeAction(disc) {
403
+ if (disc.length !== 8) {
404
+ throw new RangeError(`action_whitelist entry must be 8 bytes, got ${disc.length}`);
405
+ }
406
+ return Buffer.from(disc);
407
+ }
408
+ function buildInitProtocolFeeAccountInstruction(params) {
409
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
410
+ const programAccount = params.program ?? programId;
411
+ const { pda: protocolFeePda } = deriveProtocolFeePda(programId);
412
+ const data = Buffer.concat([
413
+ TREASURY_INSTRUCTION_DISCRIMINATOR.initProtocolFeeAccount,
414
+ encodePubkey(params.governance)
415
+ ]);
416
+ const instruction = new TransactionInstruction({
417
+ programId,
418
+ keys: [
419
+ { pubkey: protocolFeePda, isSigner: false, isWritable: true },
420
+ { pubkey: params.authority, isSigner: true, isWritable: true },
421
+ { pubkey: programAccount, isSigner: false, isWritable: false },
422
+ { pubkey: params.programData, isSigner: false, isWritable: false },
423
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }
424
+ ],
425
+ data
426
+ });
427
+ return { instruction };
428
+ }
429
+ function buildRegisterCompanyOperationsInstruction(params) {
430
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
431
+ const { pda: operationsPda } = deriveOperationsPda(
432
+ params.companyPda,
433
+ params.kind,
434
+ programId
435
+ );
436
+ const data = Buffer.concat([
437
+ TREASURY_INSTRUCTION_DISCRIMINATOR.registerCompanyOperations,
438
+ // kind: u8 enum byte
439
+ Buffer.from([params.kind]),
440
+ encodePubkey(params.signer),
441
+ encodeVec(params.actionWhitelist, encodeAction),
442
+ u32LeBytes(params.rateLimitPerPeriod),
443
+ encodeI64(params.expiryUnix)
444
+ ]);
445
+ const instruction = new TransactionInstruction({
446
+ programId,
447
+ keys: [
448
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
449
+ {
450
+ pubkey: params.controllingAuthority,
451
+ isSigner: true,
452
+ isWritable: false
453
+ },
454
+ { pubkey: operationsPda, isSigner: false, isWritable: true },
455
+ { pubkey: params.payer, isSigner: true, isWritable: true },
456
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }
457
+ ],
458
+ data
459
+ });
460
+ return { instruction };
461
+ }
462
+ function buildUpdateOperationsCapabilityInstruction(params) {
463
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
464
+ const { pda: operationsPda } = deriveOperationsPda(
465
+ params.companyPda,
466
+ params.kind,
467
+ programId
468
+ );
469
+ const argBody = Buffer.concat([
470
+ encodeOption(params.actionWhitelist, (v) => encodeVec(v, encodeAction)),
471
+ encodeOption(params.rateLimitPerPeriod, u32LeBytes),
472
+ encodeOption(params.expiryUnix, encodeI64)
473
+ ]);
474
+ const data = Buffer.concat([
475
+ TREASURY_INSTRUCTION_DISCRIMINATOR.updateOperationsCapability,
476
+ argBody
477
+ ]);
478
+ const instruction = new TransactionInstruction({
479
+ programId,
480
+ keys: [
481
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
482
+ {
483
+ pubkey: params.controllingAuthority,
484
+ isSigner: true,
485
+ isWritable: false
486
+ },
487
+ { pubkey: operationsPda, isSigner: false, isWritable: true }
488
+ ],
489
+ data
490
+ });
491
+ return { instruction };
492
+ }
493
+ function buildRevokeOperationsInstruction(params) {
494
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
495
+ const { pda: operationsPda } = deriveOperationsPda(
496
+ params.companyPda,
497
+ params.kind,
498
+ programId
499
+ );
500
+ const data = Buffer.from(TREASURY_INSTRUCTION_DISCRIMINATOR.revokeOperations);
501
+ const instruction = new TransactionInstruction({
502
+ programId,
503
+ keys: [
504
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
505
+ {
506
+ pubkey: params.controllingAuthority,
507
+ isSigner: true,
508
+ isWritable: false
509
+ },
510
+ { pubkey: operationsPda, isSigner: false, isWritable: true }
511
+ ],
512
+ data
513
+ });
514
+ return { instruction };
515
+ }
516
+ function buildCloseOperationsInstruction(params) {
517
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
518
+ const { pda: operationsPda } = deriveOperationsPda(
519
+ params.companyPda,
520
+ params.kind,
521
+ programId
522
+ );
523
+ const data = Buffer.from(TREASURY_INSTRUCTION_DISCRIMINATOR.closeOperations);
524
+ const instruction = new TransactionInstruction({
525
+ programId,
526
+ keys: [
527
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
528
+ {
529
+ pubkey: params.controllingAuthority,
530
+ isSigner: true,
531
+ isWritable: true
532
+ },
533
+ { pubkey: operationsPda, isSigner: false, isWritable: true }
534
+ ],
535
+ data
536
+ });
537
+ return { instruction };
538
+ }
539
+ function buildDisburseRoutineInstruction(params) {
540
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
541
+ const mint = params.mint ?? SOL_PSEUDO_MINT;
542
+ const { pda: protocolFeePda } = deriveProtocolFeePda(programId);
543
+ const data = Buffer.concat([
544
+ TREASURY_INSTRUCTION_DISCRIMINATOR.disburseRoutine,
545
+ encodePubkey(mint),
546
+ encodeU64(params.amountLamports)
547
+ ]);
548
+ const instruction = new TransactionInstruction({
549
+ programId,
550
+ // Order: company, treasury, policy, operations, operations_signer,
551
+ // deployment, destination, protocol_fee_account.
552
+ keys: [
553
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
554
+ { pubkey: params.treasuryPda, isSigner: false, isWritable: true },
555
+ { pubkey: params.policyPda, isSigner: false, isWritable: true },
556
+ { pubkey: params.operationsPda, isSigner: false, isWritable: true },
557
+ { pubkey: params.operationsSigner, isSigner: true, isWritable: false },
558
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: false },
559
+ { pubkey: params.destination, isSigner: false, isWritable: true },
560
+ { pubkey: protocolFeePda, isSigner: false, isWritable: true }
561
+ ],
562
+ data
563
+ });
564
+ return { instruction };
565
+ }
566
+ function buildDisbursePrivilegedInstruction(params) {
567
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
568
+ const mint = params.mint ?? SOL_PSEUDO_MINT;
569
+ const { pda: protocolFeePda } = deriveProtocolFeePda(programId);
570
+ const data = Buffer.concat([
571
+ TREASURY_INSTRUCTION_DISCRIMINATOR.disbursePrivileged,
572
+ encodePubkey(mint),
573
+ encodeU64(params.amountLamports),
574
+ encodeBool(params.isAgentDestination)
575
+ ]);
576
+ const instruction = new TransactionInstruction({
577
+ programId,
578
+ // Order: company, controlling_authority, secondary_signer, treasury,
579
+ // policy, deployment, destination, protocol_fee_account.
580
+ keys: [
581
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
582
+ {
583
+ pubkey: params.controllingAuthority,
584
+ isSigner: true,
585
+ isWritable: false
586
+ },
587
+ { pubkey: params.secondarySigner, isSigner: true, isWritable: false },
588
+ { pubkey: params.treasuryPda, isSigner: false, isWritable: true },
589
+ { pubkey: params.policyPda, isSigner: false, isWritable: false },
590
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: false },
591
+ { pubkey: params.destination, isSigner: false, isWritable: true },
592
+ { pubkey: protocolFeePda, isSigner: false, isWritable: true }
593
+ ],
594
+ data
595
+ });
596
+ return { instruction };
597
+ }
598
+ function buildCommitDailyAnchorInstruction(params) {
599
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
600
+ if (params.merkleRoot.length !== 32) {
601
+ throw new RangeError(
602
+ `merkleRoot must be 32 bytes, got ${params.merkleRoot.length}`
603
+ );
604
+ }
605
+ const { pda: dailyAnchorPda } = deriveDailyAnchorPda(
606
+ params.deploymentPda,
607
+ params.dayUnix,
608
+ programId
609
+ );
610
+ const data = Buffer.concat([
611
+ INSTRUCTION_DISCRIMINATOR.commitDailyAnchor,
612
+ encodeI64(params.dayUnix),
613
+ Buffer.from(params.merkleRoot),
614
+ u32LeBytes(params.taskCount)
615
+ ]);
616
+ const instruction = new TransactionInstruction({
617
+ programId,
618
+ // Order: deployment, company, anchor_signer, operations, daily_anchor,
619
+ // payer, system_program.
620
+ keys: [
621
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: false },
622
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
623
+ { pubkey: params.anchorSigner, isSigner: true, isWritable: false },
624
+ { pubkey: params.operationsPda, isSigner: false, isWritable: false },
625
+ { pubkey: dailyAnchorPda, isSigner: false, isWritable: true },
626
+ { pubkey: params.payer, isSigner: true, isWritable: true },
627
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }
628
+ ],
629
+ data
630
+ });
631
+ return { instruction };
632
+ }
633
+
634
+ export {
635
+ INSTRUCTION_DISCRIMINATOR,
636
+ buildCreateCompanyInstruction,
637
+ buildUpdateCompanyMetadataInstruction,
638
+ buildUpdateCompanyStatusInstruction,
639
+ buildRegisterAgentIdentityInstruction,
640
+ buildUpdateAgentIdentityMetadataInstruction,
641
+ buildCreateDeploymentInstruction,
642
+ buildUpdateDeploymentMetadataInstruction,
643
+ buildUpdateDeploymentStatusInstruction,
644
+ buildRetireDeploymentInstruction,
645
+ buildSetReceivingAddressInstruction,
646
+ TREASURY_INSTRUCTION_DISCRIMINATOR,
647
+ buildSetPolicyInstruction,
648
+ buildDisburseDiscretionaryInstruction,
649
+ buildInitProtocolFeeAccountInstruction,
650
+ buildRegisterCompanyOperationsInstruction,
651
+ buildUpdateOperationsCapabilityInstruction,
652
+ buildRevokeOperationsInstruction,
653
+ buildCloseOperationsInstruction,
654
+ buildDisburseRoutineInstruction,
655
+ buildDisbursePrivilegedInstruction,
656
+ buildCommitDailyAnchorInstruction
657
+ };
658
+ //# sourceMappingURL=chunk-N7LNBSDD.js.map