@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.
package/dist/index.cjs ADDED
@@ -0,0 +1,870 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ ACCOUNT_DISCRIMINATOR: () => ACCOUNT_DISCRIMINATOR,
24
+ AGENT_IDENTITY_SEED: () => AGENT_IDENTITY_SEED,
25
+ COMPANY_SEED: () => COMPANY_SEED,
26
+ COMPANY_STATUS: () => COMPANY_STATUS,
27
+ DAILY_ANCHOR_SEED: () => DAILY_ANCHOR_SEED,
28
+ DEPLOYMENT_SEED: () => DEPLOYMENT_SEED,
29
+ DEPLOYMENT_STATUS: () => DEPLOYMENT_STATUS,
30
+ INSTRUCTION_DISCRIMINATOR: () => INSTRUCTION_DISCRIMINATOR,
31
+ MAX_LOCALE_LEN: () => MAX_LOCALE_LEN,
32
+ MAX_METADATA_URI_LEN: () => MAX_METADATA_URI_LEN,
33
+ MAX_NAME_LEN: () => MAX_NAME_LEN,
34
+ MAX_REPUTATION_URI_LEN: () => MAX_REPUTATION_URI_LEN,
35
+ MAX_ROLE_LEN: () => MAX_ROLE_LEN,
36
+ OPERATIONS_KIND: () => OPERATIONS_KIND,
37
+ OPERATIONS_SEED: () => OPERATIONS_SEED,
38
+ POLICY_SEED: () => POLICY_SEED,
39
+ PROTOCOL_FEES_SEED: () => PROTOCOL_FEES_SEED,
40
+ REGISTRY_PROGRAM_ID: () => REGISTRY_PROGRAM_ID,
41
+ REGISTRY_PROGRAM_ID_BASE58: () => REGISTRY_PROGRAM_ID_BASE58,
42
+ SOL_PSEUDO_MINT: () => SOL_PSEUDO_MINT,
43
+ TREASURY_ACCOUNT_DISCRIMINATOR: () => TREASURY_ACCOUNT_DISCRIMINATOR,
44
+ TREASURY_INSTRUCTION_DISCRIMINATOR: () => TREASURY_INSTRUCTION_DISCRIMINATOR,
45
+ TREASURY_PROGRAM_ID: () => TREASURY_PROGRAM_ID,
46
+ TREASURY_PROGRAM_ID_BASE58: () => TREASURY_PROGRAM_ID_BASE58,
47
+ TREASURY_SEED: () => TREASURY_SEED,
48
+ buildCloseOperationsInstruction: () => buildCloseOperationsInstruction,
49
+ buildCommitDailyAnchorInstruction: () => buildCommitDailyAnchorInstruction,
50
+ buildCreateCompanyInstruction: () => buildCreateCompanyInstruction,
51
+ buildCreateDeploymentInstruction: () => buildCreateDeploymentInstruction,
52
+ buildDisburseDiscretionaryInstruction: () => buildDisburseDiscretionaryInstruction,
53
+ buildDisbursePrivilegedInstruction: () => buildDisbursePrivilegedInstruction,
54
+ buildDisburseRoutineInstruction: () => buildDisburseRoutineInstruction,
55
+ buildInitProtocolFeeAccountInstruction: () => buildInitProtocolFeeAccountInstruction,
56
+ buildRegisterAgentIdentityInstruction: () => buildRegisterAgentIdentityInstruction,
57
+ buildRegisterCompanyOperationsInstruction: () => buildRegisterCompanyOperationsInstruction,
58
+ buildRetireDeploymentInstruction: () => buildRetireDeploymentInstruction,
59
+ buildRevokeOperationsInstruction: () => buildRevokeOperationsInstruction,
60
+ buildSetPolicyInstruction: () => buildSetPolicyInstruction,
61
+ buildSetReceivingAddressInstruction: () => buildSetReceivingAddressInstruction,
62
+ buildUpdateAgentIdentityMetadataInstruction: () => buildUpdateAgentIdentityMetadataInstruction,
63
+ buildUpdateCompanyMetadataInstruction: () => buildUpdateCompanyMetadataInstruction,
64
+ buildUpdateCompanyStatusInstruction: () => buildUpdateCompanyStatusInstruction,
65
+ buildUpdateDeploymentMetadataInstruction: () => buildUpdateDeploymentMetadataInstruction,
66
+ buildUpdateDeploymentStatusInstruction: () => buildUpdateDeploymentStatusInstruction,
67
+ buildUpdateOperationsCapabilityInstruction: () => buildUpdateOperationsCapabilityInstruction,
68
+ deriveAgentIdentityPda: () => deriveAgentIdentityPda,
69
+ deriveCompanyPda: () => deriveCompanyPda,
70
+ deriveDailyAnchorPda: () => deriveDailyAnchorPda,
71
+ deriveDeploymentPda: () => deriveDeploymentPda,
72
+ deriveOperationsPda: () => deriveOperationsPda,
73
+ derivePolicyPda: () => derivePolicyPda,
74
+ deriveProtocolFeePda: () => deriveProtocolFeePda,
75
+ deriveTreasuryPda: () => deriveTreasuryPda,
76
+ u32LeBytes: () => u32LeBytes
77
+ });
78
+ module.exports = __toCommonJS(src_exports);
79
+
80
+ // src/constants.ts
81
+ var import_web3 = require("@solana/web3.js");
82
+ var REGISTRY_PROGRAM_ID_BASE58 = "occaTHMv5eYG5aZ85jimxTvHkBfsDCvndXC6J2k8kxr";
83
+ var REGISTRY_PROGRAM_ID = new import_web3.PublicKey(REGISTRY_PROGRAM_ID_BASE58);
84
+ var TREASURY_PROGRAM_ID_BASE58 = "occaxyVLnurdjedWCBPrvDCCto8wGYadtTZ3nAmcVzh";
85
+ var TREASURY_PROGRAM_ID = new import_web3.PublicKey(TREASURY_PROGRAM_ID_BASE58);
86
+ var COMPANY_SEED = Buffer.from("company");
87
+ var AGENT_IDENTITY_SEED = Buffer.from("agent_identity");
88
+ var DEPLOYMENT_SEED = Buffer.from("deployment");
89
+ var TREASURY_SEED = Buffer.from("treasury");
90
+ var POLICY_SEED = Buffer.from("policy");
91
+ var PROTOCOL_FEES_SEED = Buffer.from("protocol_fees");
92
+ var OPERATIONS_SEED = Buffer.from("operations");
93
+ var DAILY_ANCHOR_SEED = Buffer.from("daily_anchor");
94
+ var OPERATIONS_KIND = {
95
+ /** Disbursement Wallet — operator-held only, signs `disburse_routine`. */
96
+ Disbursement: 0,
97
+ /** Anchor Wallet — operator+OCCA shared, signs `commit_daily_anchor`. */
98
+ Anchor: 1
99
+ };
100
+ var SOL_PSEUDO_MINT = new import_web3.PublicKey(new Uint8Array(32));
101
+ var MAX_NAME_LEN = 64;
102
+ var MAX_LOCALE_LEN = 8;
103
+ var MAX_ROLE_LEN = 32;
104
+ var MAX_METADATA_URI_LEN = 200;
105
+ var MAX_REPUTATION_URI_LEN = 200;
106
+ var COMPANY_STATUS = {
107
+ Active: 0,
108
+ Paused: 1
109
+ };
110
+ var DEPLOYMENT_STATUS = {
111
+ Active: 0,
112
+ Paused: 1,
113
+ /** Terminal — retired deployments cannot be reactivated. */
114
+ Retired: 2
115
+ };
116
+ var ACCOUNT_DISCRIMINATOR = {
117
+ AgentIdentity: Buffer.from([11, 149, 31, 27, 186, 76, 241, 72]),
118
+ CompanyAccount: Buffer.from([37, 215, 171, 200, 8, 141, 69, 96]),
119
+ Deployment: Buffer.from([66, 90, 104, 89, 183, 130, 64, 178]),
120
+ DailyAnchorAccount: Buffer.from([218, 106, 107, 94, 194, 48, 111, 254])
121
+ };
122
+ var TREASURY_ACCOUNT_DISCRIMINATOR = {
123
+ TreasuryAccount: Buffer.from([204, 140, 18, 173, 90, 152, 134, 123]),
124
+ PolicyAccount: Buffer.from([218, 201, 183, 164, 156, 127, 81, 175]),
125
+ ProtocolFeeAccount: Buffer.from([5, 171, 24, 9, 150, 135, 135, 201]),
126
+ OperationsAccount: Buffer.from([185, 55, 148, 90, 151, 227, 104, 158])
127
+ };
128
+
129
+ // src/pda.ts
130
+ var import_web32 = require("@solana/web3.js");
131
+ function u32LeBytes(value) {
132
+ if (!Number.isInteger(value) || value < 0 || value > 4294967295) {
133
+ throw new RangeError(`u32 out of range: ${value}`);
134
+ }
135
+ const buf = Buffer.alloc(4);
136
+ buf.writeUInt32LE(value, 0);
137
+ return buf;
138
+ }
139
+ function deriveCompanyPda(owner, nonce, programId = REGISTRY_PROGRAM_ID) {
140
+ const [pda, bump] = import_web32.PublicKey.findProgramAddressSync(
141
+ [COMPANY_SEED, owner.toBuffer(), u32LeBytes(nonce)],
142
+ programId
143
+ );
144
+ return { pda, bump };
145
+ }
146
+ function deriveAgentIdentityPda(agentPubkey, programId = REGISTRY_PROGRAM_ID) {
147
+ const [pda, bump] = import_web32.PublicKey.findProgramAddressSync(
148
+ [AGENT_IDENTITY_SEED, agentPubkey.toBuffer()],
149
+ programId
150
+ );
151
+ return { pda, bump };
152
+ }
153
+ function deriveDeploymentPda(companyPda, deploymentIndex, programId = REGISTRY_PROGRAM_ID) {
154
+ const [pda, bump] = import_web32.PublicKey.findProgramAddressSync(
155
+ [DEPLOYMENT_SEED, companyPda.toBuffer(), u32LeBytes(deploymentIndex)],
156
+ programId
157
+ );
158
+ return { pda, bump };
159
+ }
160
+ function deriveTreasuryPda(companyPda, programId = TREASURY_PROGRAM_ID) {
161
+ const [pda, bump] = import_web32.PublicKey.findProgramAddressSync(
162
+ [TREASURY_SEED, companyPda.toBuffer()],
163
+ programId
164
+ );
165
+ return { pda, bump };
166
+ }
167
+ function derivePolicyPda(companyPda, programId = TREASURY_PROGRAM_ID) {
168
+ const [pda, bump] = import_web32.PublicKey.findProgramAddressSync(
169
+ [POLICY_SEED, companyPda.toBuffer()],
170
+ programId
171
+ );
172
+ return { pda, bump };
173
+ }
174
+ function deriveProtocolFeePda(programId = TREASURY_PROGRAM_ID) {
175
+ const [pda, bump] = import_web32.PublicKey.findProgramAddressSync(
176
+ [PROTOCOL_FEES_SEED],
177
+ programId
178
+ );
179
+ return { pda, bump };
180
+ }
181
+ function deriveOperationsPda(companyPda, kind, programId = TREASURY_PROGRAM_ID) {
182
+ const [pda, bump] = import_web32.PublicKey.findProgramAddressSync(
183
+ [OPERATIONS_SEED, companyPda.toBuffer(), Buffer.from([kind])],
184
+ programId
185
+ );
186
+ return { pda, bump };
187
+ }
188
+ function i64LeBytes(value) {
189
+ const buf = Buffer.alloc(8);
190
+ buf.writeBigInt64LE(value, 0);
191
+ return buf;
192
+ }
193
+ function deriveDailyAnchorPda(deploymentPda, dayUnix, programId = REGISTRY_PROGRAM_ID) {
194
+ const [pda, bump] = import_web32.PublicKey.findProgramAddressSync(
195
+ [DAILY_ANCHOR_SEED, deploymentPda.toBuffer(), i64LeBytes(dayUnix)],
196
+ programId
197
+ );
198
+ return { pda, bump };
199
+ }
200
+
201
+ // src/instructions.ts
202
+ var import_web33 = require("@solana/web3.js");
203
+ var INSTRUCTION_DISCRIMINATOR = {
204
+ createCompany: Buffer.from([36, 192, 217, 147, 233, 129, 198, 18]),
205
+ updateCompanyMetadata: Buffer.from([186, 229, 190, 16, 234, 141, 170, 89]),
206
+ updateCompanyStatus: Buffer.from([61, 6, 101, 120, 141, 13, 125, 75]),
207
+ registerAgentIdentity: Buffer.from([57, 31, 242, 205, 57, 129, 123, 35]),
208
+ updateAgentIdentityMetadata: Buffer.from([
209
+ 250,
210
+ 182,
211
+ 24,
212
+ 200,
213
+ 201,
214
+ 147,
215
+ 60,
216
+ 183
217
+ ]),
218
+ createDeployment: Buffer.from([55, 207, 186, 101, 21, 218, 102, 171]),
219
+ updateDeploymentMetadata: Buffer.from([100, 135, 41, 32, 16, 41, 29, 76]),
220
+ updateDeploymentStatus: Buffer.from([225, 195, 150, 254, 178, 203, 53, 147]),
221
+ retireDeployment: Buffer.from([45, 188, 162, 197, 136, 180, 202, 153]),
222
+ setReceivingAddress: Buffer.from([70, 63, 44, 87, 16, 6, 156, 200]),
223
+ commitDailyAnchor: Buffer.from([18, 7, 3, 65, 58, 148, 164, 0])
224
+ };
225
+ function encodeString(s) {
226
+ const utf8 = Buffer.from(s, "utf8");
227
+ const len = Buffer.alloc(4);
228
+ len.writeUInt32LE(utf8.length, 0);
229
+ return Buffer.concat([len, utf8]);
230
+ }
231
+ function encodePubkey(pk) {
232
+ return Buffer.from(pk.toBytes());
233
+ }
234
+ function encodeU8(n) {
235
+ if (!Number.isInteger(n) || n < 0 || n > 255) {
236
+ throw new RangeError(`u8 out of range: ${n}`);
237
+ }
238
+ return Buffer.from([n]);
239
+ }
240
+ function encodeMetadataHash(hash) {
241
+ if (hash.length !== 32) {
242
+ throw new RangeError(`metadata_hash must be 32 bytes, got ${hash.length}`);
243
+ }
244
+ return Buffer.from(hash);
245
+ }
246
+ function encodeOptionU32(value) {
247
+ if (value === null || value === void 0) {
248
+ return Buffer.from([0]);
249
+ }
250
+ return Buffer.concat([Buffer.from([1]), u32LeBytes(value)]);
251
+ }
252
+ function buildCreateCompanyInstruction(params) {
253
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
254
+ const { pda: companyPda, bump } = deriveCompanyPda(
255
+ params.owner,
256
+ params.nonce,
257
+ programId
258
+ );
259
+ const { pda: treasuryPda } = deriveTreasuryPda(companyPda);
260
+ const { pda: policyPda } = derivePolicyPda(companyPda);
261
+ const data = Buffer.concat([
262
+ INSTRUCTION_DISCRIMINATOR.createCompany,
263
+ u32LeBytes(params.nonce),
264
+ encodeString(params.name),
265
+ encodeString(params.locale),
266
+ encodeString(params.metadataUri),
267
+ encodeMetadataHash(params.metadataHash)
268
+ ]);
269
+ const instruction = new import_web33.TransactionInstruction({
270
+ programId,
271
+ // Order MUST match registry/lib.rs `CreateCompany` accounts struct:
272
+ // company, owner, payer, treasury, policy, treasury_program, system_program.
273
+ keys: [
274
+ { pubkey: companyPda, isSigner: false, isWritable: true },
275
+ { pubkey: params.owner, isSigner: true, isWritable: false },
276
+ { pubkey: params.payer, isSigner: true, isWritable: true },
277
+ { pubkey: treasuryPda, isSigner: false, isWritable: true },
278
+ { pubkey: policyPda, isSigner: false, isWritable: true },
279
+ { pubkey: TREASURY_PROGRAM_ID, isSigner: false, isWritable: false },
280
+ { pubkey: import_web33.SystemProgram.programId, isSigner: false, isWritable: false }
281
+ ],
282
+ data
283
+ });
284
+ return { instruction, companyPda, treasuryPda, policyPda, bump };
285
+ }
286
+ function buildUpdateCompanyMetadataInstruction(params) {
287
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
288
+ const data = Buffer.concat([
289
+ INSTRUCTION_DISCRIMINATOR.updateCompanyMetadata,
290
+ encodeString(params.name),
291
+ encodeString(params.locale),
292
+ encodeString(params.metadataUri),
293
+ encodeMetadataHash(params.metadataHash)
294
+ ]);
295
+ const instruction = new import_web33.TransactionInstruction({
296
+ programId,
297
+ keys: [
298
+ { pubkey: params.companyPda, isSigner: false, isWritable: true },
299
+ { pubkey: params.owner, isSigner: true, isWritable: false }
300
+ ],
301
+ data
302
+ });
303
+ return { instruction };
304
+ }
305
+ function buildUpdateCompanyStatusInstruction(params) {
306
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
307
+ const data = Buffer.concat([
308
+ INSTRUCTION_DISCRIMINATOR.updateCompanyStatus,
309
+ encodeU8(params.newStatus)
310
+ ]);
311
+ const instruction = new import_web33.TransactionInstruction({
312
+ programId,
313
+ keys: [
314
+ { pubkey: params.companyPda, isSigner: false, isWritable: true },
315
+ { pubkey: params.owner, isSigner: true, isWritable: false }
316
+ ],
317
+ data
318
+ });
319
+ return { instruction };
320
+ }
321
+ function buildRegisterAgentIdentityInstruction(params) {
322
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
323
+ const { pda: identityPda, bump } = deriveAgentIdentityPda(
324
+ params.agentPubkey,
325
+ programId
326
+ );
327
+ const data = Buffer.concat([
328
+ INSTRUCTION_DISCRIMINATOR.registerAgentIdentity,
329
+ encodePubkey(params.agentPubkey),
330
+ encodeString(params.name),
331
+ encodeString(params.metadataUri),
332
+ encodeMetadataHash(params.metadataHash)
333
+ ]);
334
+ const instruction = new import_web33.TransactionInstruction({
335
+ programId,
336
+ keys: [
337
+ { pubkey: identityPda, isSigner: false, isWritable: true },
338
+ { pubkey: params.owner, isSigner: true, isWritable: false },
339
+ { pubkey: params.payer, isSigner: true, isWritable: true },
340
+ { pubkey: import_web33.SystemProgram.programId, isSigner: false, isWritable: false }
341
+ ],
342
+ data
343
+ });
344
+ return { instruction, identityPda, bump };
345
+ }
346
+ function buildUpdateAgentIdentityMetadataInstruction(params) {
347
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
348
+ const data = Buffer.concat([
349
+ INSTRUCTION_DISCRIMINATOR.updateAgentIdentityMetadata,
350
+ encodeString(params.name),
351
+ encodeString(params.metadataUri),
352
+ encodeMetadataHash(params.metadataHash)
353
+ ]);
354
+ const instruction = new import_web33.TransactionInstruction({
355
+ programId,
356
+ keys: [
357
+ { pubkey: params.identityPda, isSigner: false, isWritable: true },
358
+ { pubkey: params.owner, isSigner: true, isWritable: false }
359
+ ],
360
+ data
361
+ });
362
+ return { instruction };
363
+ }
364
+ function buildCreateDeploymentInstruction(params) {
365
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
366
+ const { pda: deploymentPda, bump } = deriveDeploymentPda(
367
+ params.companyPda,
368
+ params.deploymentIndex,
369
+ programId
370
+ );
371
+ const data = Buffer.concat([
372
+ INSTRUCTION_DISCRIMINATOR.createDeployment,
373
+ u32LeBytes(params.deploymentIndex),
374
+ encodeString(params.role),
375
+ encodeOptionU32(params.parentDeploymentIndex),
376
+ encodePubkey(params.adapterId),
377
+ encodeString(params.metadataUri),
378
+ encodeMetadataHash(params.metadataHash)
379
+ ]);
380
+ const instruction = new import_web33.TransactionInstruction({
381
+ programId,
382
+ keys: [
383
+ // Order matches the on-chain `CreateDeployment` accounts struct.
384
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
385
+ { pubkey: params.identityPda, isSigner: false, isWritable: false },
386
+ { pubkey: params.owner, isSigner: true, isWritable: false },
387
+ { pubkey: deploymentPda, isSigner: false, isWritable: true },
388
+ { pubkey: params.payer, isSigner: true, isWritable: true },
389
+ { pubkey: import_web33.SystemProgram.programId, isSigner: false, isWritable: false }
390
+ ],
391
+ data
392
+ });
393
+ return { instruction, deploymentPda, bump };
394
+ }
395
+ function buildUpdateDeploymentMetadataInstruction(params) {
396
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
397
+ const data = Buffer.concat([
398
+ INSTRUCTION_DISCRIMINATOR.updateDeploymentMetadata,
399
+ encodeString(params.role),
400
+ encodeString(params.metadataUri),
401
+ encodeMetadataHash(params.metadataHash)
402
+ ]);
403
+ const instruction = new import_web33.TransactionInstruction({
404
+ programId,
405
+ keys: [
406
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: true },
407
+ { pubkey: params.owner, isSigner: true, isWritable: false }
408
+ ],
409
+ data
410
+ });
411
+ return { instruction };
412
+ }
413
+ function buildUpdateDeploymentStatusInstruction(params) {
414
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
415
+ const data = Buffer.concat([
416
+ INSTRUCTION_DISCRIMINATOR.updateDeploymentStatus,
417
+ encodeU8(params.newStatus)
418
+ ]);
419
+ const instruction = new import_web33.TransactionInstruction({
420
+ programId,
421
+ keys: [
422
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: true },
423
+ { pubkey: params.owner, isSigner: true, isWritable: false }
424
+ ],
425
+ data
426
+ });
427
+ return { instruction };
428
+ }
429
+ function buildRetireDeploymentInstruction(params) {
430
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
431
+ const instruction = new import_web33.TransactionInstruction({
432
+ programId,
433
+ keys: [
434
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: true },
435
+ { pubkey: params.owner, isSigner: true, isWritable: false }
436
+ ],
437
+ data: Buffer.from(INSTRUCTION_DISCRIMINATOR.retireDeployment)
438
+ });
439
+ return { instruction };
440
+ }
441
+ function buildSetReceivingAddressInstruction(params) {
442
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
443
+ const data = Buffer.concat([
444
+ INSTRUCTION_DISCRIMINATOR.setReceivingAddress,
445
+ encodePubkey(params.newReceivingAddress)
446
+ ]);
447
+ const instruction = new import_web33.TransactionInstruction({
448
+ programId,
449
+ keys: [
450
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: true },
451
+ { pubkey: params.owner, isSigner: true, isWritable: false }
452
+ ],
453
+ data
454
+ });
455
+ return { instruction };
456
+ }
457
+ var TREASURY_INSTRUCTION_DISCRIMINATOR = {
458
+ setPolicy: Buffer.from([40, 133, 12, 157, 235, 202, 2, 132]),
459
+ disburseDiscretionary: Buffer.from([102, 176, 14, 127, 210, 4, 96, 175]),
460
+ initProtocolFeeAccount: Buffer.from([214, 27, 184, 174, 155, 79, 141, 114]),
461
+ registerCompanyOperations: Buffer.from([212, 173, 142, 23, 28, 221, 55, 99]),
462
+ updateOperationsCapability: Buffer.from([21, 13, 197, 41, 92, 229, 142, 202]),
463
+ revokeOperations: Buffer.from([141, 196, 241, 103, 182, 146, 117, 183]),
464
+ closeOperations: Buffer.from([2, 52, 136, 225, 80, 230, 222, 120]),
465
+ disburseRoutine: Buffer.from([45, 152, 225, 130, 133, 73, 62, 202]),
466
+ disbursePrivileged: Buffer.from([173, 78, 248, 158, 76, 46, 88, 167])
467
+ };
468
+ function encodeU16(n) {
469
+ if (!Number.isInteger(n) || n < 0 || n > 65535) {
470
+ throw new RangeError(`u16 out of range: ${n}`);
471
+ }
472
+ const buf = Buffer.alloc(2);
473
+ buf.writeUInt16LE(n, 0);
474
+ return buf;
475
+ }
476
+ function encodeU64(n) {
477
+ if (n < 0n || n > 0xffffffffffffffffn) {
478
+ throw new RangeError(`u64 out of range: ${n}`);
479
+ }
480
+ const buf = Buffer.alloc(8);
481
+ buf.writeBigUInt64LE(n, 0);
482
+ return buf;
483
+ }
484
+ function encodeAssetBudget(b) {
485
+ return Buffer.concat([encodePubkey(b.mint), encodeU64(b.amount)]);
486
+ }
487
+ function encodeVec(items, encodeItem) {
488
+ return Buffer.concat([u32LeBytes(items.length), ...items.map(encodeItem)]);
489
+ }
490
+ function encodeOption(value, encodeSome) {
491
+ if (value === null || value === void 0) return Buffer.from([0]);
492
+ return Buffer.concat([Buffer.from([1]), encodeSome(value)]);
493
+ }
494
+ function buildSetPolicyInstruction(params) {
495
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
496
+ function encodeSecondarySigner(v) {
497
+ if (v === void 0) return Buffer.from([0]);
498
+ if (v === null) return Buffer.from([1, 0]);
499
+ return Buffer.concat([Buffer.from([1, 1]), encodePubkey(v)]);
500
+ }
501
+ const data = Buffer.concat([
502
+ TREASURY_INSTRUCTION_DISCRIMINATOR.setPolicy,
503
+ // 1. routine_budget_per_month: Option<Vec<AssetBudget>>
504
+ encodeOption(
505
+ params.routineBudgetPerMonth,
506
+ (v) => encodeVec(v, encodeAssetBudget)
507
+ ),
508
+ // 2. discretionary_budget_per_month: Option<Vec<AssetBudget>>
509
+ encodeOption(
510
+ params.discretionaryBudgetPerMonth,
511
+ (v) => encodeVec(v, encodeAssetBudget)
512
+ ),
513
+ // 3. privileged_threshold_lamports: Option<u64>
514
+ encodeOption(params.privilegedThresholdLamports, encodeU64),
515
+ // 4. privileged_threshold_per_token: Option<Vec<AssetBudget>>
516
+ encodeOption(
517
+ params.privilegedThresholdPerToken,
518
+ (v) => encodeVec(v, encodeAssetBudget)
519
+ ),
520
+ // 5. secondary_signer: Option<Option<Pubkey>>
521
+ encodeSecondarySigner(params.secondarySigner),
522
+ // 6. agent_operating_fee_bps: Option<u16>
523
+ encodeOption(params.agentOperatingFeeBps, encodeU16),
524
+ // 7. accepted_assets: Option<Vec<Pubkey>>
525
+ encodeOption(params.acceptedAssets, (v) => encodeVec(v, encodePubkey))
526
+ ]);
527
+ const instruction = new import_web33.TransactionInstruction({
528
+ programId,
529
+ // Order: company, controlling_authority, treasury, policy.
530
+ keys: [
531
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
532
+ {
533
+ pubkey: params.controllingAuthority,
534
+ isSigner: true,
535
+ isWritable: false
536
+ },
537
+ { pubkey: params.treasuryPda, isSigner: false, isWritable: true },
538
+ { pubkey: params.policyPda, isSigner: false, isWritable: true }
539
+ ],
540
+ data
541
+ });
542
+ return { instruction };
543
+ }
544
+ function buildDisburseDiscretionaryInstruction(params) {
545
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
546
+ const mint = params.mint ?? SOL_PSEUDO_MINT;
547
+ const { pda: protocolFeePda } = deriveProtocolFeePda();
548
+ const data = Buffer.concat([
549
+ TREASURY_INSTRUCTION_DISCRIMINATOR.disburseDiscretionary,
550
+ encodePubkey(mint),
551
+ encodeU64(params.amountLamports)
552
+ ]);
553
+ const instruction = new import_web33.TransactionInstruction({
554
+ programId,
555
+ // Order: company, controlling_authority, treasury, policy,
556
+ // deployment, destination, protocol_fee_account.
557
+ keys: [
558
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
559
+ {
560
+ pubkey: params.controllingAuthority,
561
+ isSigner: true,
562
+ isWritable: false
563
+ },
564
+ { pubkey: params.treasuryPda, isSigner: false, isWritable: true },
565
+ { pubkey: params.policyPda, isSigner: false, isWritable: true },
566
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: false },
567
+ { pubkey: params.destination, isSigner: false, isWritable: true },
568
+ { pubkey: protocolFeePda, isSigner: false, isWritable: true }
569
+ ],
570
+ data
571
+ });
572
+ return { instruction };
573
+ }
574
+ function encodeI64(n) {
575
+ const buf = Buffer.alloc(8);
576
+ buf.writeBigInt64LE(n, 0);
577
+ return buf;
578
+ }
579
+ function encodeBool(b) {
580
+ return Buffer.from([b ? 1 : 0]);
581
+ }
582
+ function encodeAction(disc) {
583
+ if (disc.length !== 8) {
584
+ throw new RangeError(`action_whitelist entry must be 8 bytes, got ${disc.length}`);
585
+ }
586
+ return Buffer.from(disc);
587
+ }
588
+ function buildInitProtocolFeeAccountInstruction(params) {
589
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
590
+ const programAccount = params.program ?? programId;
591
+ const { pda: protocolFeePda } = deriveProtocolFeePda(programId);
592
+ const data = Buffer.concat([
593
+ TREASURY_INSTRUCTION_DISCRIMINATOR.initProtocolFeeAccount,
594
+ encodePubkey(params.governance)
595
+ ]);
596
+ const instruction = new import_web33.TransactionInstruction({
597
+ programId,
598
+ keys: [
599
+ { pubkey: protocolFeePda, isSigner: false, isWritable: true },
600
+ { pubkey: params.authority, isSigner: true, isWritable: true },
601
+ { pubkey: programAccount, isSigner: false, isWritable: false },
602
+ { pubkey: params.programData, isSigner: false, isWritable: false },
603
+ { pubkey: import_web33.SystemProgram.programId, isSigner: false, isWritable: false }
604
+ ],
605
+ data
606
+ });
607
+ return { instruction };
608
+ }
609
+ function buildRegisterCompanyOperationsInstruction(params) {
610
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
611
+ const { pda: operationsPda } = deriveOperationsPda(
612
+ params.companyPda,
613
+ params.kind,
614
+ programId
615
+ );
616
+ const data = Buffer.concat([
617
+ TREASURY_INSTRUCTION_DISCRIMINATOR.registerCompanyOperations,
618
+ // kind: u8 enum byte
619
+ Buffer.from([params.kind]),
620
+ encodePubkey(params.signer),
621
+ encodeVec(params.actionWhitelist, encodeAction),
622
+ u32LeBytes(params.rateLimitPerPeriod),
623
+ encodeI64(params.expiryUnix)
624
+ ]);
625
+ const instruction = new import_web33.TransactionInstruction({
626
+ programId,
627
+ keys: [
628
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
629
+ {
630
+ pubkey: params.controllingAuthority,
631
+ isSigner: true,
632
+ isWritable: false
633
+ },
634
+ { pubkey: operationsPda, isSigner: false, isWritable: true },
635
+ { pubkey: params.payer, isSigner: true, isWritable: true },
636
+ { pubkey: import_web33.SystemProgram.programId, isSigner: false, isWritable: false }
637
+ ],
638
+ data
639
+ });
640
+ return { instruction };
641
+ }
642
+ function buildUpdateOperationsCapabilityInstruction(params) {
643
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
644
+ const { pda: operationsPda } = deriveOperationsPda(
645
+ params.companyPda,
646
+ params.kind,
647
+ programId
648
+ );
649
+ const argBody = Buffer.concat([
650
+ encodeOption(params.actionWhitelist, (v) => encodeVec(v, encodeAction)),
651
+ encodeOption(params.rateLimitPerPeriod, u32LeBytes),
652
+ encodeOption(params.expiryUnix, encodeI64)
653
+ ]);
654
+ const data = Buffer.concat([
655
+ TREASURY_INSTRUCTION_DISCRIMINATOR.updateOperationsCapability,
656
+ argBody
657
+ ]);
658
+ const instruction = new import_web33.TransactionInstruction({
659
+ programId,
660
+ keys: [
661
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
662
+ {
663
+ pubkey: params.controllingAuthority,
664
+ isSigner: true,
665
+ isWritable: false
666
+ },
667
+ { pubkey: operationsPda, isSigner: false, isWritable: true }
668
+ ],
669
+ data
670
+ });
671
+ return { instruction };
672
+ }
673
+ function buildRevokeOperationsInstruction(params) {
674
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
675
+ const { pda: operationsPda } = deriveOperationsPda(
676
+ params.companyPda,
677
+ params.kind,
678
+ programId
679
+ );
680
+ const data = Buffer.from(TREASURY_INSTRUCTION_DISCRIMINATOR.revokeOperations);
681
+ const instruction = new import_web33.TransactionInstruction({
682
+ programId,
683
+ keys: [
684
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
685
+ {
686
+ pubkey: params.controllingAuthority,
687
+ isSigner: true,
688
+ isWritable: false
689
+ },
690
+ { pubkey: operationsPda, isSigner: false, isWritable: true }
691
+ ],
692
+ data
693
+ });
694
+ return { instruction };
695
+ }
696
+ function buildCloseOperationsInstruction(params) {
697
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
698
+ const { pda: operationsPda } = deriveOperationsPda(
699
+ params.companyPda,
700
+ params.kind,
701
+ programId
702
+ );
703
+ const data = Buffer.from(TREASURY_INSTRUCTION_DISCRIMINATOR.closeOperations);
704
+ const instruction = new import_web33.TransactionInstruction({
705
+ programId,
706
+ keys: [
707
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
708
+ {
709
+ pubkey: params.controllingAuthority,
710
+ isSigner: true,
711
+ isWritable: true
712
+ },
713
+ { pubkey: operationsPda, isSigner: false, isWritable: true }
714
+ ],
715
+ data
716
+ });
717
+ return { instruction };
718
+ }
719
+ function buildDisburseRoutineInstruction(params) {
720
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
721
+ const mint = params.mint ?? SOL_PSEUDO_MINT;
722
+ const { pda: protocolFeePda } = deriveProtocolFeePda(programId);
723
+ const data = Buffer.concat([
724
+ TREASURY_INSTRUCTION_DISCRIMINATOR.disburseRoutine,
725
+ encodePubkey(mint),
726
+ encodeU64(params.amountLamports)
727
+ ]);
728
+ const instruction = new import_web33.TransactionInstruction({
729
+ programId,
730
+ // Order: company, treasury, policy, operations, operations_signer,
731
+ // deployment, destination, protocol_fee_account.
732
+ keys: [
733
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
734
+ { pubkey: params.treasuryPda, isSigner: false, isWritable: true },
735
+ { pubkey: params.policyPda, isSigner: false, isWritable: true },
736
+ { pubkey: params.operationsPda, isSigner: false, isWritable: true },
737
+ { pubkey: params.operationsSigner, isSigner: true, isWritable: false },
738
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: false },
739
+ { pubkey: params.destination, isSigner: false, isWritable: true },
740
+ { pubkey: protocolFeePda, isSigner: false, isWritable: true }
741
+ ],
742
+ data
743
+ });
744
+ return { instruction };
745
+ }
746
+ function buildDisbursePrivilegedInstruction(params) {
747
+ const programId = params.programId ?? TREASURY_PROGRAM_ID;
748
+ const mint = params.mint ?? SOL_PSEUDO_MINT;
749
+ const { pda: protocolFeePda } = deriveProtocolFeePda(programId);
750
+ const data = Buffer.concat([
751
+ TREASURY_INSTRUCTION_DISCRIMINATOR.disbursePrivileged,
752
+ encodePubkey(mint),
753
+ encodeU64(params.amountLamports),
754
+ encodeBool(params.isAgentDestination)
755
+ ]);
756
+ const instruction = new import_web33.TransactionInstruction({
757
+ programId,
758
+ // Order: company, controlling_authority, secondary_signer, treasury,
759
+ // policy, deployment, destination, protocol_fee_account.
760
+ keys: [
761
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
762
+ {
763
+ pubkey: params.controllingAuthority,
764
+ isSigner: true,
765
+ isWritable: false
766
+ },
767
+ { pubkey: params.secondarySigner, isSigner: true, isWritable: false },
768
+ { pubkey: params.treasuryPda, isSigner: false, isWritable: true },
769
+ { pubkey: params.policyPda, isSigner: false, isWritable: false },
770
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: false },
771
+ { pubkey: params.destination, isSigner: false, isWritable: true },
772
+ { pubkey: protocolFeePda, isSigner: false, isWritable: true }
773
+ ],
774
+ data
775
+ });
776
+ return { instruction };
777
+ }
778
+ function buildCommitDailyAnchorInstruction(params) {
779
+ const programId = params.programId ?? REGISTRY_PROGRAM_ID;
780
+ if (params.merkleRoot.length !== 32) {
781
+ throw new RangeError(
782
+ `merkleRoot must be 32 bytes, got ${params.merkleRoot.length}`
783
+ );
784
+ }
785
+ const { pda: dailyAnchorPda } = deriveDailyAnchorPda(
786
+ params.deploymentPda,
787
+ params.dayUnix,
788
+ programId
789
+ );
790
+ const data = Buffer.concat([
791
+ INSTRUCTION_DISCRIMINATOR.commitDailyAnchor,
792
+ encodeI64(params.dayUnix),
793
+ Buffer.from(params.merkleRoot),
794
+ u32LeBytes(params.taskCount)
795
+ ]);
796
+ const instruction = new import_web33.TransactionInstruction({
797
+ programId,
798
+ // Order: deployment, company, anchor_signer, operations, daily_anchor,
799
+ // payer, system_program.
800
+ keys: [
801
+ { pubkey: params.deploymentPda, isSigner: false, isWritable: false },
802
+ { pubkey: params.companyPda, isSigner: false, isWritable: false },
803
+ { pubkey: params.anchorSigner, isSigner: true, isWritable: false },
804
+ { pubkey: params.operationsPda, isSigner: false, isWritable: false },
805
+ { pubkey: dailyAnchorPda, isSigner: false, isWritable: true },
806
+ { pubkey: params.payer, isSigner: true, isWritable: true },
807
+ { pubkey: import_web33.SystemProgram.programId, isSigner: false, isWritable: false }
808
+ ],
809
+ data
810
+ });
811
+ return { instruction };
812
+ }
813
+ // Annotate the CommonJS export names for ESM import in node:
814
+ 0 && (module.exports = {
815
+ ACCOUNT_DISCRIMINATOR,
816
+ AGENT_IDENTITY_SEED,
817
+ COMPANY_SEED,
818
+ COMPANY_STATUS,
819
+ DAILY_ANCHOR_SEED,
820
+ DEPLOYMENT_SEED,
821
+ DEPLOYMENT_STATUS,
822
+ INSTRUCTION_DISCRIMINATOR,
823
+ MAX_LOCALE_LEN,
824
+ MAX_METADATA_URI_LEN,
825
+ MAX_NAME_LEN,
826
+ MAX_REPUTATION_URI_LEN,
827
+ MAX_ROLE_LEN,
828
+ OPERATIONS_KIND,
829
+ OPERATIONS_SEED,
830
+ POLICY_SEED,
831
+ PROTOCOL_FEES_SEED,
832
+ REGISTRY_PROGRAM_ID,
833
+ REGISTRY_PROGRAM_ID_BASE58,
834
+ SOL_PSEUDO_MINT,
835
+ TREASURY_ACCOUNT_DISCRIMINATOR,
836
+ TREASURY_INSTRUCTION_DISCRIMINATOR,
837
+ TREASURY_PROGRAM_ID,
838
+ TREASURY_PROGRAM_ID_BASE58,
839
+ TREASURY_SEED,
840
+ buildCloseOperationsInstruction,
841
+ buildCommitDailyAnchorInstruction,
842
+ buildCreateCompanyInstruction,
843
+ buildCreateDeploymentInstruction,
844
+ buildDisburseDiscretionaryInstruction,
845
+ buildDisbursePrivilegedInstruction,
846
+ buildDisburseRoutineInstruction,
847
+ buildInitProtocolFeeAccountInstruction,
848
+ buildRegisterAgentIdentityInstruction,
849
+ buildRegisterCompanyOperationsInstruction,
850
+ buildRetireDeploymentInstruction,
851
+ buildRevokeOperationsInstruction,
852
+ buildSetPolicyInstruction,
853
+ buildSetReceivingAddressInstruction,
854
+ buildUpdateAgentIdentityMetadataInstruction,
855
+ buildUpdateCompanyMetadataInstruction,
856
+ buildUpdateCompanyStatusInstruction,
857
+ buildUpdateDeploymentMetadataInstruction,
858
+ buildUpdateDeploymentStatusInstruction,
859
+ buildUpdateOperationsCapabilityInstruction,
860
+ deriveAgentIdentityPda,
861
+ deriveCompanyPda,
862
+ deriveDailyAnchorPda,
863
+ deriveDeploymentPda,
864
+ deriveOperationsPda,
865
+ derivePolicyPda,
866
+ deriveProtocolFeePda,
867
+ deriveTreasuryPda,
868
+ u32LeBytes
869
+ });
870
+ //# sourceMappingURL=index.cjs.map