@agent-fuel/sdk 0.1.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,3361 @@
1
+ 'use strict';
2
+
3
+ var anchor = require('@coral-xyz/anchor');
4
+ var web3_js = require('@solana/web3.js');
5
+
6
+ // src/client.ts
7
+ var TOKEN_PROGRAM_ID = new web3_js.PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
8
+ var ASSOCIATED_TOKEN_PROGRAM_ID = new web3_js.PublicKey(
9
+ "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
10
+ );
11
+ var SLOTS_PER_HOUR = 9e3;
12
+ function getAssociatedTokenAddress(mint, owner) {
13
+ const [ata] = web3_js.PublicKey.findProgramAddressSync(
14
+ [owner.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mint.toBuffer()],
15
+ ASSOCIATED_TOKEN_PROGRAM_ID
16
+ );
17
+ return ata;
18
+ }
19
+ function createAssociatedTokenAccountIdempotentInstruction(payer, ata, owner, mint) {
20
+ return new web3_js.TransactionInstruction({
21
+ programId: ASSOCIATED_TOKEN_PROGRAM_ID,
22
+ keys: [
23
+ { pubkey: payer, isSigner: true, isWritable: true },
24
+ { pubkey: ata, isSigner: false, isWritable: true },
25
+ { pubkey: owner, isSigner: false, isWritable: false },
26
+ { pubkey: mint, isSigner: false, isWritable: false },
27
+ { pubkey: web3_js.SystemProgram.programId, isSigner: false, isWritable: false },
28
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }
29
+ ],
30
+ data: Buffer.from([1])
31
+ });
32
+ }
33
+ function bnToNum(bn) {
34
+ return bn.toNumber();
35
+ }
36
+ function nameFromBytes(bytes) {
37
+ const buf = Buffer.from(bytes);
38
+ const end = buf.indexOf(0);
39
+ return (end === -1 ? buf : buf.subarray(0, end)).toString("utf8");
40
+ }
41
+ function categoryFromRaw(raw) {
42
+ if ("dataFeed" in raw) return "DataFeed";
43
+ if ("compute" in raw) return "Compute";
44
+ if ("swap" in raw) return "Swap";
45
+ if ("rpc" in raw) return "Rpc";
46
+ return "Other";
47
+ }
48
+ function decodeCreditVault(pubkey, raw) {
49
+ const total_deposited = bnToNum(raw.totalDeposited);
50
+ const total_withdrawn = bnToNum(raw.totalWithdrawn);
51
+ const total_spent = bnToNum(raw.totalSpent);
52
+ const total_claimed = bnToNum(raw.totalClaimed);
53
+ return {
54
+ pubkey,
55
+ owner: raw.owner,
56
+ agent: raw.agent,
57
+ usdc_mint: raw.usdcMint,
58
+ vault_token_account: raw.vaultTokenAccount,
59
+ total_deposited,
60
+ total_withdrawn,
61
+ total_spent,
62
+ total_claimed,
63
+ balance: total_deposited - total_withdrawn - total_spent + total_claimed,
64
+ frozen: raw.frozen,
65
+ created_slot: bnToNum(raw.createdSlot),
66
+ last_active_slot: bnToNum(raw.lastActiveSlot)
67
+ };
68
+ }
69
+ var DEFAULT_PUBKEY = web3_js.PublicKey.default.toBase58();
70
+ function decodeSpendPolicy(pubkey, raw) {
71
+ return {
72
+ pubkey,
73
+ vault: raw.vault,
74
+ whitelist: raw.whitelist.filter((pk) => pk.toBase58() !== DEFAULT_PUBKEY),
75
+ per_tx_limit_usdc: bnToNum(raw.perTxLimitUsdc),
76
+ hourly_limit_usdc: bnToNum(raw.hourlyLimitUsdc),
77
+ lifetime_limit_usdc: bnToNum(raw.lifetimeLimitUsdc),
78
+ hourly_window_start_slot: bnToNum(raw.hourlyWindowStartSlot),
79
+ hourly_window_spent_usdc: bnToNum(raw.hourlyWindowSpentUsdc),
80
+ allow_post_pay: raw.allowPostPay
81
+ };
82
+ }
83
+ function decodeServiceRegistry(pubkey, raw) {
84
+ return {
85
+ pubkey,
86
+ authority: raw.authority,
87
+ name: nameFromBytes(raw.name),
88
+ category: categoryFromRaw(raw.category),
89
+ total_agents_served: bnToNum(raw.totalAgentsServed),
90
+ total_volume_received_usdc: bnToNum(raw.totalVolumeReceivedUsdc),
91
+ active: raw.active,
92
+ first_active_slot: bnToNum(raw.firstActiveSlot),
93
+ last_active_slot: bnToNum(raw.lastActiveSlot)
94
+ };
95
+ }
96
+
97
+ // src/errors.ts
98
+ var AgentFuelError = class extends Error {
99
+ constructor(message) {
100
+ super(message);
101
+ this.name = "AgentFuelError";
102
+ }
103
+ };
104
+ var OwnerNotConfiguredError = class extends AgentFuelError {
105
+ constructor() {
106
+ super("vault owner is not configured: pass `owner` to `new AgentFuel({...})` or to the method");
107
+ this.name = "OwnerNotConfiguredError";
108
+ }
109
+ };
110
+ var AccountNotFoundError = class extends AgentFuelError {
111
+ account;
112
+ constructor(account) {
113
+ super(`account not found: ${account}`);
114
+ this.name = "AccountNotFoundError";
115
+ this.account = account;
116
+ }
117
+ };
118
+ var HttpError = class extends AgentFuelError {
119
+ status;
120
+ url;
121
+ body;
122
+ constructor(status, url, body) {
123
+ super(`HTTP ${status} from ${url}`);
124
+ this.name = "HttpError";
125
+ this.status = status;
126
+ this.url = url;
127
+ this.body = body;
128
+ }
129
+ };
130
+ var SpendPolicyError = class extends AgentFuelError {
131
+ constructor(message) {
132
+ super(message);
133
+ this.name = "SpendPolicyError";
134
+ }
135
+ };
136
+ var VaultFrozenError = class extends SpendPolicyError {
137
+ constructor() {
138
+ super("vault is frozen");
139
+ this.name = "VaultFrozenError";
140
+ }
141
+ };
142
+ var ZeroAmountError = class extends SpendPolicyError {
143
+ constructor() {
144
+ super("amount must be > 0");
145
+ this.name = "ZeroAmountError";
146
+ }
147
+ };
148
+ var PerTxLimitExceededError = class extends SpendPolicyError {
149
+ limit;
150
+ amount;
151
+ constructor(amount, limit) {
152
+ super(`per-tx limit exceeded: ${amount} > ${limit}`);
153
+ this.name = "PerTxLimitExceededError";
154
+ this.amount = amount;
155
+ this.limit = limit;
156
+ }
157
+ };
158
+ var HourlyLimitExceededError = class extends SpendPolicyError {
159
+ limit;
160
+ windowSpent;
161
+ amount;
162
+ constructor(amount, windowSpent, limit) {
163
+ super(`hourly limit exceeded: ${windowSpent} + ${amount} > ${limit}`);
164
+ this.name = "HourlyLimitExceededError";
165
+ this.amount = amount;
166
+ this.windowSpent = windowSpent;
167
+ this.limit = limit;
168
+ }
169
+ };
170
+ var LifetimeLimitExceededError = class extends SpendPolicyError {
171
+ limit;
172
+ totalSpent;
173
+ amount;
174
+ constructor(amount, totalSpent, limit) {
175
+ super(`lifetime limit exceeded: ${totalSpent} + ${amount} > ${limit}`);
176
+ this.name = "LifetimeLimitExceededError";
177
+ this.amount = amount;
178
+ this.totalSpent = totalSpent;
179
+ this.limit = limit;
180
+ }
181
+ };
182
+ var NotWhitelistedError = class extends SpendPolicyError {
183
+ service;
184
+ constructor(service) {
185
+ super(`service ${service} is not in the vault's whitelist`);
186
+ this.name = "NotWhitelistedError";
187
+ this.service = service;
188
+ }
189
+ };
190
+
191
+ // src/guardrails.ts
192
+ function guardSpend(args) {
193
+ const { vault, policy, service, amountUsdc, currentSlot } = args;
194
+ if (vault.frozen) throw new VaultFrozenError();
195
+ if (amountUsdc <= 0) throw new ZeroAmountError();
196
+ if (policy.whitelist.length > 0) {
197
+ const allowed = policy.whitelist.some((pk) => pk.equals(service));
198
+ if (!allowed) throw new NotWhitelistedError(service.toBase58());
199
+ }
200
+ if (policy.per_tx_limit_usdc > 0 && amountUsdc > policy.per_tx_limit_usdc) {
201
+ throw new PerTxLimitExceededError(amountUsdc, policy.per_tx_limit_usdc);
202
+ }
203
+ if (policy.hourly_limit_usdc > 0) {
204
+ const windowElapsed = currentSlot - policy.hourly_window_start_slot >= SLOTS_PER_HOUR;
205
+ const windowSpent = windowElapsed ? 0 : policy.hourly_window_spent_usdc;
206
+ const newWindowTotal = windowSpent + amountUsdc;
207
+ if (newWindowTotal > policy.hourly_limit_usdc) {
208
+ throw new HourlyLimitExceededError(amountUsdc, windowSpent, policy.hourly_limit_usdc);
209
+ }
210
+ }
211
+ if (policy.lifetime_limit_usdc > 0) {
212
+ const newTotalSpent = vault.total_spent + amountUsdc;
213
+ if (newTotalSpent > policy.lifetime_limit_usdc) {
214
+ throw new LifetimeLimitExceededError(amountUsdc, vault.total_spent, policy.lifetime_limit_usdc);
215
+ }
216
+ }
217
+ }
218
+
219
+ // src/live.ts
220
+ var cachedCtor = null;
221
+ async function getWebSocketCtor() {
222
+ if (cachedCtor) return cachedCtor;
223
+ const globalCtor = globalThis.WebSocket;
224
+ if (globalCtor) {
225
+ cachedCtor = globalCtor;
226
+ return globalCtor;
227
+ }
228
+ cachedCtor = (async () => {
229
+ const mod = await import('ws');
230
+ return mod.WebSocket;
231
+ })();
232
+ return cachedCtor;
233
+ }
234
+ var WS_OPEN = 1;
235
+ var MAX_BACKOFF_MS = 3e4;
236
+ function subscribe(url, opts) {
237
+ let socket = null;
238
+ let alive = true;
239
+ let attempts = 0;
240
+ let reconnectTimer = null;
241
+ let currentStatus = "connecting";
242
+ function setStatus(next) {
243
+ currentStatus = next;
244
+ opts.onStatus?.(next);
245
+ }
246
+ async function connect() {
247
+ if (!alive) return;
248
+ setStatus(attempts === 0 ? "connecting" : "reconnecting");
249
+ const WS = await getWebSocketCtor();
250
+ if (!alive) return;
251
+ socket = new WS(url);
252
+ socket.addEventListener("open", () => {
253
+ attempts = 0;
254
+ setStatus("open");
255
+ });
256
+ socket.addEventListener("message", (ev) => {
257
+ if (typeof ev.data !== "string" || ev.data.length === 0) return;
258
+ try {
259
+ const parsed = JSON.parse(ev.data);
260
+ if (parsed.type === "event") opts.onFrame(parsed);
261
+ } catch {
262
+ }
263
+ });
264
+ socket.addEventListener("close", () => {
265
+ if (!alive) return;
266
+ attempts += 1;
267
+ const delay = Math.min(MAX_BACKOFF_MS, 1e3 * 2 ** (attempts - 1));
268
+ setStatus("reconnecting");
269
+ reconnectTimer = setTimeout(() => {
270
+ void connect();
271
+ }, delay);
272
+ });
273
+ socket.addEventListener("error", () => {
274
+ });
275
+ }
276
+ void connect();
277
+ return {
278
+ close() {
279
+ alive = false;
280
+ if (reconnectTimer !== null) clearTimeout(reconnectTimer);
281
+ if (socket && socket.readyState === WS_OPEN) {
282
+ socket.close(1e3, "client close");
283
+ }
284
+ socket = null;
285
+ setStatus("closed");
286
+ },
287
+ get status() {
288
+ return currentStatus;
289
+ }
290
+ };
291
+ }
292
+ function wsUrl(apiBase, path) {
293
+ if (apiBase.startsWith("https://")) return apiBase.replace(/^https/, "wss") + path;
294
+ if (apiBase.startsWith("http://")) return apiBase.replace(/^http/, "ws") + path;
295
+ return apiBase + path;
296
+ }
297
+
298
+ // src/idl/reputation.json
299
+ var reputation_default = {
300
+ address: "4GjB4xdm1VTPVM6KSiEEfJpD4u7BfY1qDx77StiFShvQ",
301
+ metadata: {
302
+ name: "reputation",
303
+ version: "0.1.0",
304
+ spec: "0.1.0",
305
+ description: "Agent Fuel \u2014 On-chain reputation primitive for AI agents on Solana",
306
+ repository: "https://github.com/TODO/agent_fuel"
307
+ },
308
+ instructions: [
309
+ {
310
+ name: "append_response",
311
+ discriminator: [
312
+ 162,
313
+ 210,
314
+ 186,
315
+ 50,
316
+ 180,
317
+ 4,
318
+ 47,
319
+ 104
320
+ ],
321
+ accounts: [
322
+ {
323
+ name: "responder",
324
+ writable: true,
325
+ signer: true
326
+ },
327
+ {
328
+ name: "agent_profile",
329
+ writable: true,
330
+ pda: {
331
+ seeds: [
332
+ {
333
+ kind: "const",
334
+ value: [
335
+ 97,
336
+ 103,
337
+ 101,
338
+ 110,
339
+ 116
340
+ ]
341
+ },
342
+ {
343
+ kind: "account",
344
+ path: "agent_profile.authority",
345
+ account: "AgentProfile"
346
+ }
347
+ ]
348
+ },
349
+ relations: [
350
+ "feedback_record"
351
+ ]
352
+ },
353
+ {
354
+ name: "feedback_record",
355
+ writable: true,
356
+ pda: {
357
+ seeds: [
358
+ {
359
+ kind: "const",
360
+ value: [
361
+ 102,
362
+ 101,
363
+ 101,
364
+ 100,
365
+ 98,
366
+ 97,
367
+ 99,
368
+ 107
369
+ ]
370
+ },
371
+ {
372
+ kind: "arg",
373
+ path: "payment_receipt_hash"
374
+ }
375
+ ]
376
+ }
377
+ },
378
+ {
379
+ name: "system_program",
380
+ address: "11111111111111111111111111111111"
381
+ }
382
+ ],
383
+ args: [
384
+ {
385
+ name: "payment_receipt_hash",
386
+ type: {
387
+ array: [
388
+ "u8",
389
+ 32
390
+ ]
391
+ }
392
+ },
393
+ {
394
+ name: "response_uri",
395
+ type: {
396
+ array: [
397
+ "u8",
398
+ 128
399
+ ]
400
+ }
401
+ },
402
+ {
403
+ name: "response_hash",
404
+ type: {
405
+ array: [
406
+ "u8",
407
+ 32
408
+ ]
409
+ }
410
+ }
411
+ ]
412
+ },
413
+ {
414
+ name: "compute_score",
415
+ discriminator: [
416
+ 161,
417
+ 101,
418
+ 4,
419
+ 93,
420
+ 120,
421
+ 62,
422
+ 41,
423
+ 20
424
+ ],
425
+ accounts: [
426
+ {
427
+ name: "caller",
428
+ writable: true,
429
+ signer: true
430
+ },
431
+ {
432
+ name: "agent_profile",
433
+ writable: true,
434
+ pda: {
435
+ seeds: [
436
+ {
437
+ kind: "const",
438
+ value: [
439
+ 97,
440
+ 103,
441
+ 101,
442
+ 110,
443
+ 116
444
+ ]
445
+ },
446
+ {
447
+ kind: "account",
448
+ path: "agent_profile.authority",
449
+ account: "AgentProfile"
450
+ }
451
+ ]
452
+ }
453
+ }
454
+ ],
455
+ args: []
456
+ },
457
+ {
458
+ name: "give_feedback",
459
+ discriminator: [
460
+ 145,
461
+ 136,
462
+ 123,
463
+ 3,
464
+ 215,
465
+ 165,
466
+ 98,
467
+ 41
468
+ ],
469
+ accounts: [
470
+ {
471
+ name: "service",
472
+ writable: true,
473
+ signer: true
474
+ },
475
+ {
476
+ name: "agent_profile",
477
+ writable: true,
478
+ pda: {
479
+ seeds: [
480
+ {
481
+ kind: "const",
482
+ value: [
483
+ 97,
484
+ 103,
485
+ 101,
486
+ 110,
487
+ 116
488
+ ]
489
+ },
490
+ {
491
+ kind: "account",
492
+ path: "agent_profile.authority",
493
+ account: "AgentProfile"
494
+ }
495
+ ]
496
+ }
497
+ },
498
+ {
499
+ name: "service_registry",
500
+ writable: true,
501
+ pda: {
502
+ seeds: [
503
+ {
504
+ kind: "const",
505
+ value: [
506
+ 115,
507
+ 101,
508
+ 114,
509
+ 118,
510
+ 105,
511
+ 99,
512
+ 101
513
+ ]
514
+ },
515
+ {
516
+ kind: "account",
517
+ path: "service"
518
+ }
519
+ ]
520
+ }
521
+ },
522
+ {
523
+ name: "agent_service_link",
524
+ writable: true,
525
+ pda: {
526
+ seeds: [
527
+ {
528
+ kind: "const",
529
+ value: [
530
+ 108,
531
+ 105,
532
+ 110,
533
+ 107
534
+ ]
535
+ },
536
+ {
537
+ kind: "account",
538
+ path: "agent_profile"
539
+ },
540
+ {
541
+ kind: "account",
542
+ path: "service_registry"
543
+ }
544
+ ]
545
+ }
546
+ },
547
+ {
548
+ name: "receipt_used",
549
+ pda: {
550
+ seeds: [
551
+ {
552
+ kind: "const",
553
+ value: [
554
+ 114,
555
+ 101,
556
+ 99,
557
+ 101,
558
+ 105,
559
+ 112,
560
+ 116
561
+ ]
562
+ },
563
+ {
564
+ kind: "arg",
565
+ path: "payment_receipt_hash"
566
+ }
567
+ ]
568
+ }
569
+ },
570
+ {
571
+ name: "feedback_record",
572
+ writable: true,
573
+ pda: {
574
+ seeds: [
575
+ {
576
+ kind: "const",
577
+ value: [
578
+ 102,
579
+ 101,
580
+ 101,
581
+ 100,
582
+ 98,
583
+ 97,
584
+ 99,
585
+ 107
586
+ ]
587
+ },
588
+ {
589
+ kind: "arg",
590
+ path: "payment_receipt_hash"
591
+ }
592
+ ]
593
+ }
594
+ },
595
+ {
596
+ name: "system_program",
597
+ address: "11111111111111111111111111111111"
598
+ }
599
+ ],
600
+ args: [
601
+ {
602
+ name: "payment_receipt_hash",
603
+ type: {
604
+ array: [
605
+ "u8",
606
+ 32
607
+ ]
608
+ }
609
+ },
610
+ {
611
+ name: "value",
612
+ type: "i8"
613
+ },
614
+ {
615
+ name: "tags",
616
+ type: "u32"
617
+ },
618
+ {
619
+ name: "evidence_uri",
620
+ type: {
621
+ array: [
622
+ "u8",
623
+ 128
624
+ ]
625
+ }
626
+ },
627
+ {
628
+ name: "evidence_hash",
629
+ type: {
630
+ array: [
631
+ "u8",
632
+ 32
633
+ ]
634
+ }
635
+ }
636
+ ]
637
+ },
638
+ {
639
+ name: "initialize_agent",
640
+ discriminator: [
641
+ 212,
642
+ 81,
643
+ 156,
644
+ 211,
645
+ 212,
646
+ 110,
647
+ 21,
648
+ 28
649
+ ],
650
+ accounts: [
651
+ {
652
+ name: "owner",
653
+ writable: true,
654
+ signer: true
655
+ },
656
+ {
657
+ name: "agent",
658
+ signer: true
659
+ },
660
+ {
661
+ name: "agent_profile",
662
+ writable: true,
663
+ pda: {
664
+ seeds: [
665
+ {
666
+ kind: "const",
667
+ value: [
668
+ 97,
669
+ 103,
670
+ 101,
671
+ 110,
672
+ 116
673
+ ]
674
+ },
675
+ {
676
+ kind: "account",
677
+ path: "agent"
678
+ }
679
+ ]
680
+ }
681
+ },
682
+ {
683
+ name: "system_program",
684
+ address: "11111111111111111111111111111111"
685
+ }
686
+ ],
687
+ args: [
688
+ {
689
+ name: "agent_uri",
690
+ type: {
691
+ array: [
692
+ "u8",
693
+ 128
694
+ ]
695
+ }
696
+ },
697
+ {
698
+ name: "external_agent_id",
699
+ type: "u64"
700
+ }
701
+ ]
702
+ },
703
+ {
704
+ name: "record_payment",
705
+ discriminator: [
706
+ 226,
707
+ 154,
708
+ 10,
709
+ 27,
710
+ 9,
711
+ 14,
712
+ 148,
713
+ 137
714
+ ],
715
+ accounts: [
716
+ {
717
+ name: "service",
718
+ writable: true,
719
+ signer: true
720
+ },
721
+ {
722
+ name: "agent_profile",
723
+ writable: true,
724
+ pda: {
725
+ seeds: [
726
+ {
727
+ kind: "const",
728
+ value: [
729
+ 97,
730
+ 103,
731
+ 101,
732
+ 110,
733
+ 116
734
+ ]
735
+ },
736
+ {
737
+ kind: "account",
738
+ path: "agent_profile.authority",
739
+ account: "AgentProfile"
740
+ }
741
+ ]
742
+ }
743
+ },
744
+ {
745
+ name: "service_registry",
746
+ writable: true,
747
+ pda: {
748
+ seeds: [
749
+ {
750
+ kind: "const",
751
+ value: [
752
+ 115,
753
+ 101,
754
+ 114,
755
+ 118,
756
+ 105,
757
+ 99,
758
+ 101
759
+ ]
760
+ },
761
+ {
762
+ kind: "account",
763
+ path: "service"
764
+ }
765
+ ]
766
+ }
767
+ },
768
+ {
769
+ name: "agent_service_link",
770
+ writable: true,
771
+ pda: {
772
+ seeds: [
773
+ {
774
+ kind: "const",
775
+ value: [
776
+ 108,
777
+ 105,
778
+ 110,
779
+ 107
780
+ ]
781
+ },
782
+ {
783
+ kind: "account",
784
+ path: "agent_profile"
785
+ },
786
+ {
787
+ kind: "account",
788
+ path: "service_registry"
789
+ }
790
+ ]
791
+ }
792
+ },
793
+ {
794
+ name: "receipt_used",
795
+ writable: true,
796
+ pda: {
797
+ seeds: [
798
+ {
799
+ kind: "const",
800
+ value: [
801
+ 114,
802
+ 101,
803
+ 99,
804
+ 101,
805
+ 105,
806
+ 112,
807
+ 116
808
+ ]
809
+ },
810
+ {
811
+ kind: "arg",
812
+ path: "payment_receipt_hash"
813
+ }
814
+ ]
815
+ }
816
+ },
817
+ {
818
+ name: "system_program",
819
+ address: "11111111111111111111111111111111"
820
+ }
821
+ ],
822
+ args: [
823
+ {
824
+ name: "amount_usdc",
825
+ type: "u64"
826
+ },
827
+ {
828
+ name: "payment_receipt_hash",
829
+ type: {
830
+ array: [
831
+ "u8",
832
+ 32
833
+ ]
834
+ }
835
+ }
836
+ ]
837
+ },
838
+ {
839
+ name: "register_service",
840
+ discriminator: [
841
+ 11,
842
+ 133,
843
+ 158,
844
+ 232,
845
+ 193,
846
+ 19,
847
+ 229,
848
+ 73
849
+ ],
850
+ accounts: [
851
+ {
852
+ name: "service",
853
+ writable: true,
854
+ signer: true
855
+ },
856
+ {
857
+ name: "service_registry",
858
+ writable: true,
859
+ pda: {
860
+ seeds: [
861
+ {
862
+ kind: "const",
863
+ value: [
864
+ 115,
865
+ 101,
866
+ 114,
867
+ 118,
868
+ 105,
869
+ 99,
870
+ 101
871
+ ]
872
+ },
873
+ {
874
+ kind: "account",
875
+ path: "service"
876
+ }
877
+ ]
878
+ }
879
+ },
880
+ {
881
+ name: "system_program",
882
+ address: "11111111111111111111111111111111"
883
+ }
884
+ ],
885
+ args: [
886
+ {
887
+ name: "name",
888
+ type: {
889
+ array: [
890
+ "u8",
891
+ 32
892
+ ]
893
+ }
894
+ },
895
+ {
896
+ name: "category",
897
+ type: {
898
+ defined: {
899
+ name: "ServiceCategory"
900
+ }
901
+ }
902
+ }
903
+ ]
904
+ },
905
+ {
906
+ name: "revoke_feedback",
907
+ discriminator: [
908
+ 211,
909
+ 37,
910
+ 230,
911
+ 82,
912
+ 118,
913
+ 216,
914
+ 137,
915
+ 206
916
+ ],
917
+ accounts: [
918
+ {
919
+ name: "service",
920
+ writable: true,
921
+ signer: true
922
+ },
923
+ {
924
+ name: "agent_profile",
925
+ writable: true,
926
+ pda: {
927
+ seeds: [
928
+ {
929
+ kind: "const",
930
+ value: [
931
+ 97,
932
+ 103,
933
+ 101,
934
+ 110,
935
+ 116
936
+ ]
937
+ },
938
+ {
939
+ kind: "account",
940
+ path: "agent_profile.authority",
941
+ account: "AgentProfile"
942
+ }
943
+ ]
944
+ },
945
+ relations: [
946
+ "feedback_record"
947
+ ]
948
+ },
949
+ {
950
+ name: "service_registry",
951
+ writable: true,
952
+ pda: {
953
+ seeds: [
954
+ {
955
+ kind: "const",
956
+ value: [
957
+ 115,
958
+ 101,
959
+ 114,
960
+ 118,
961
+ 105,
962
+ 99,
963
+ 101
964
+ ]
965
+ },
966
+ {
967
+ kind: "account",
968
+ path: "service"
969
+ }
970
+ ]
971
+ },
972
+ relations: [
973
+ "feedback_record"
974
+ ]
975
+ },
976
+ {
977
+ name: "feedback_record",
978
+ writable: true,
979
+ pda: {
980
+ seeds: [
981
+ {
982
+ kind: "const",
983
+ value: [
984
+ 102,
985
+ 101,
986
+ 101,
987
+ 100,
988
+ 98,
989
+ 97,
990
+ 99,
991
+ 107
992
+ ]
993
+ },
994
+ {
995
+ kind: "arg",
996
+ path: "payment_receipt_hash"
997
+ }
998
+ ]
999
+ }
1000
+ },
1001
+ {
1002
+ name: "system_program",
1003
+ address: "11111111111111111111111111111111"
1004
+ }
1005
+ ],
1006
+ args: [
1007
+ {
1008
+ name: "payment_receipt_hash",
1009
+ type: {
1010
+ array: [
1011
+ "u8",
1012
+ 32
1013
+ ]
1014
+ }
1015
+ }
1016
+ ]
1017
+ }
1018
+ ],
1019
+ accounts: [
1020
+ {
1021
+ name: "AgentProfile",
1022
+ discriminator: [
1023
+ 60,
1024
+ 227,
1025
+ 42,
1026
+ 24,
1027
+ 0,
1028
+ 87,
1029
+ 86,
1030
+ 205
1031
+ ]
1032
+ },
1033
+ {
1034
+ name: "AgentServiceLink",
1035
+ discriminator: [
1036
+ 123,
1037
+ 74,
1038
+ 215,
1039
+ 240,
1040
+ 42,
1041
+ 88,
1042
+ 217,
1043
+ 216
1044
+ ]
1045
+ },
1046
+ {
1047
+ name: "FeedbackRecord",
1048
+ discriminator: [
1049
+ 15,
1050
+ 45,
1051
+ 246,
1052
+ 217,
1053
+ 63,
1054
+ 251,
1055
+ 69,
1056
+ 100
1057
+ ]
1058
+ },
1059
+ {
1060
+ name: "ReceiptUsed",
1061
+ discriminator: [
1062
+ 143,
1063
+ 21,
1064
+ 251,
1065
+ 75,
1066
+ 166,
1067
+ 7,
1068
+ 163,
1069
+ 137
1070
+ ]
1071
+ },
1072
+ {
1073
+ name: "ServiceRegistry",
1074
+ discriminator: [
1075
+ 105,
1076
+ 133,
1077
+ 96,
1078
+ 79,
1079
+ 207,
1080
+ 176,
1081
+ 202,
1082
+ 71
1083
+ ]
1084
+ }
1085
+ ],
1086
+ events: [
1087
+ {
1088
+ name: "AgentInitialized",
1089
+ discriminator: [
1090
+ 124,
1091
+ 252,
1092
+ 85,
1093
+ 27,
1094
+ 146,
1095
+ 101,
1096
+ 64,
1097
+ 160
1098
+ ]
1099
+ },
1100
+ {
1101
+ name: "FeedbackGiven",
1102
+ discriminator: [
1103
+ 64,
1104
+ 65,
1105
+ 2,
1106
+ 152,
1107
+ 174,
1108
+ 215,
1109
+ 156,
1110
+ 194
1111
+ ]
1112
+ },
1113
+ {
1114
+ name: "FeedbackRevoked",
1115
+ discriminator: [
1116
+ 205,
1117
+ 16,
1118
+ 31,
1119
+ 94,
1120
+ 54,
1121
+ 101,
1122
+ 16,
1123
+ 199
1124
+ ]
1125
+ },
1126
+ {
1127
+ name: "PaymentRecorded",
1128
+ discriminator: [
1129
+ 214,
1130
+ 3,
1131
+ 212,
1132
+ 116,
1133
+ 135,
1134
+ 35,
1135
+ 104,
1136
+ 98
1137
+ ]
1138
+ },
1139
+ {
1140
+ name: "ResponseAppended",
1141
+ discriminator: [
1142
+ 168,
1143
+ 169,
1144
+ 214,
1145
+ 193,
1146
+ 171,
1147
+ 1,
1148
+ 232,
1149
+ 123
1150
+ ]
1151
+ },
1152
+ {
1153
+ name: "ScoreComputed",
1154
+ discriminator: [
1155
+ 52,
1156
+ 76,
1157
+ 80,
1158
+ 33,
1159
+ 2,
1160
+ 43,
1161
+ 75,
1162
+ 109
1163
+ ]
1164
+ },
1165
+ {
1166
+ name: "ServiceRegistered",
1167
+ discriminator: [
1168
+ 25,
1169
+ 219,
1170
+ 76,
1171
+ 223,
1172
+ 57,
1173
+ 191,
1174
+ 117,
1175
+ 38
1176
+ ]
1177
+ }
1178
+ ],
1179
+ errors: [
1180
+ {
1181
+ code: 6e3,
1182
+ name: "Overflow",
1183
+ msg: "Counter or amount overflow"
1184
+ },
1185
+ {
1186
+ code: 6001,
1187
+ name: "ServiceInactive",
1188
+ msg: "Service is not active"
1189
+ },
1190
+ {
1191
+ code: 6002,
1192
+ name: "ZeroAmount",
1193
+ msg: "Payment amount must be greater than zero"
1194
+ },
1195
+ {
1196
+ code: 6003,
1197
+ name: "SelfRating",
1198
+ msg: "A service may not rate itself or the agent owner"
1199
+ },
1200
+ {
1201
+ code: 6004,
1202
+ name: "ReceiptMismatch",
1203
+ msg: "Receipt does not belong to this (agent, service) pair"
1204
+ },
1205
+ {
1206
+ code: 6005,
1207
+ name: "InvalidFeedbackValue",
1208
+ msg: "Feedback value is outside the allowed range"
1209
+ },
1210
+ {
1211
+ code: 6006,
1212
+ name: "UnauthorizedResponder",
1213
+ msg: "Responder must be the agent or its owner"
1214
+ },
1215
+ {
1216
+ code: 6007,
1217
+ name: "AlreadyHasResponse",
1218
+ msg: "Feedback already has a response"
1219
+ },
1220
+ {
1221
+ code: 6008,
1222
+ name: "AlreadyRevoked",
1223
+ msg: "Feedback has already been revoked"
1224
+ },
1225
+ {
1226
+ code: 6009,
1227
+ name: "FeedbackRateLimited",
1228
+ msg: "Feedback rate limit not yet expired for this (service, agent) pair"
1229
+ }
1230
+ ],
1231
+ types: [
1232
+ {
1233
+ name: "AgentInitialized",
1234
+ type: {
1235
+ kind: "struct",
1236
+ fields: [
1237
+ {
1238
+ name: "agent",
1239
+ type: "pubkey"
1240
+ },
1241
+ {
1242
+ name: "owner",
1243
+ type: "pubkey"
1244
+ },
1245
+ {
1246
+ name: "init_slot",
1247
+ type: "u64"
1248
+ }
1249
+ ]
1250
+ }
1251
+ },
1252
+ {
1253
+ name: "AgentProfile",
1254
+ type: {
1255
+ kind: "struct",
1256
+ fields: [
1257
+ {
1258
+ name: "authority",
1259
+ type: "pubkey"
1260
+ },
1261
+ {
1262
+ name: "owner",
1263
+ type: "pubkey"
1264
+ },
1265
+ {
1266
+ name: "agent_uri",
1267
+ type: {
1268
+ array: [
1269
+ "u8",
1270
+ 128
1271
+ ]
1272
+ }
1273
+ },
1274
+ {
1275
+ name: "external_agent_id",
1276
+ type: "u64"
1277
+ },
1278
+ {
1279
+ name: "total_transactions",
1280
+ type: "u64"
1281
+ },
1282
+ {
1283
+ name: "total_volume_usdc",
1284
+ type: "u64"
1285
+ },
1286
+ {
1287
+ name: "consecutive_success",
1288
+ type: "u32"
1289
+ },
1290
+ {
1291
+ name: "total_feedback_count",
1292
+ type: "u32"
1293
+ },
1294
+ {
1295
+ name: "active_negative_feedback_count",
1296
+ type: "u32"
1297
+ },
1298
+ {
1299
+ name: "services_used",
1300
+ type: "u16"
1301
+ },
1302
+ {
1303
+ name: "first_active_slot",
1304
+ type: "u64"
1305
+ },
1306
+ {
1307
+ name: "last_active_slot",
1308
+ type: "u64"
1309
+ },
1310
+ {
1311
+ name: "reputation_score",
1312
+ type: "u16"
1313
+ },
1314
+ {
1315
+ name: "bump",
1316
+ type: "u8"
1317
+ },
1318
+ {
1319
+ name: "_padding",
1320
+ type: {
1321
+ array: [
1322
+ "u8",
1323
+ 64
1324
+ ]
1325
+ }
1326
+ }
1327
+ ]
1328
+ }
1329
+ },
1330
+ {
1331
+ name: "AgentServiceLink",
1332
+ type: {
1333
+ kind: "struct",
1334
+ fields: [
1335
+ {
1336
+ name: "agent",
1337
+ type: "pubkey"
1338
+ },
1339
+ {
1340
+ name: "service",
1341
+ type: "pubkey"
1342
+ },
1343
+ {
1344
+ name: "total_transactions",
1345
+ type: "u64"
1346
+ },
1347
+ {
1348
+ name: "total_volume_usdc",
1349
+ type: "u64"
1350
+ },
1351
+ {
1352
+ name: "first_payment_slot",
1353
+ type: "u64"
1354
+ },
1355
+ {
1356
+ name: "last_payment_slot",
1357
+ type: "u64"
1358
+ },
1359
+ {
1360
+ name: "last_feedback_slot",
1361
+ type: "u64"
1362
+ },
1363
+ {
1364
+ name: "has_received_feedback",
1365
+ type: "bool"
1366
+ },
1367
+ {
1368
+ name: "bump",
1369
+ type: "u8"
1370
+ },
1371
+ {
1372
+ name: "_padding",
1373
+ type: {
1374
+ array: [
1375
+ "u8",
1376
+ 64
1377
+ ]
1378
+ }
1379
+ }
1380
+ ]
1381
+ }
1382
+ },
1383
+ {
1384
+ name: "FeedbackGiven",
1385
+ type: {
1386
+ kind: "struct",
1387
+ fields: [
1388
+ {
1389
+ name: "agent",
1390
+ type: "pubkey"
1391
+ },
1392
+ {
1393
+ name: "service",
1394
+ type: "pubkey"
1395
+ },
1396
+ {
1397
+ name: "feedback",
1398
+ type: "pubkey"
1399
+ },
1400
+ {
1401
+ name: "payment_receipt_hash",
1402
+ type: {
1403
+ array: [
1404
+ "u8",
1405
+ 32
1406
+ ]
1407
+ }
1408
+ },
1409
+ {
1410
+ name: "value",
1411
+ type: "i8"
1412
+ },
1413
+ {
1414
+ name: "tags",
1415
+ type: "u32"
1416
+ },
1417
+ {
1418
+ name: "slot",
1419
+ type: "u64"
1420
+ }
1421
+ ]
1422
+ }
1423
+ },
1424
+ {
1425
+ name: "FeedbackRecord",
1426
+ type: {
1427
+ kind: "struct",
1428
+ fields: [
1429
+ {
1430
+ name: "agent_profile",
1431
+ type: "pubkey"
1432
+ },
1433
+ {
1434
+ name: "service_registry",
1435
+ type: "pubkey"
1436
+ },
1437
+ {
1438
+ name: "payment_receipt_hash",
1439
+ type: {
1440
+ array: [
1441
+ "u8",
1442
+ 32
1443
+ ]
1444
+ }
1445
+ },
1446
+ {
1447
+ name: "value",
1448
+ type: "i8"
1449
+ },
1450
+ {
1451
+ name: "tags",
1452
+ type: "u32"
1453
+ },
1454
+ {
1455
+ name: "evidence_uri",
1456
+ type: {
1457
+ array: [
1458
+ "u8",
1459
+ 128
1460
+ ]
1461
+ }
1462
+ },
1463
+ {
1464
+ name: "evidence_hash",
1465
+ type: {
1466
+ array: [
1467
+ "u8",
1468
+ 32
1469
+ ]
1470
+ }
1471
+ },
1472
+ {
1473
+ name: "response_uri",
1474
+ type: {
1475
+ array: [
1476
+ "u8",
1477
+ 128
1478
+ ]
1479
+ }
1480
+ },
1481
+ {
1482
+ name: "response_hash",
1483
+ type: {
1484
+ array: [
1485
+ "u8",
1486
+ 32
1487
+ ]
1488
+ }
1489
+ },
1490
+ {
1491
+ name: "has_response",
1492
+ type: "bool"
1493
+ },
1494
+ {
1495
+ name: "revoked",
1496
+ type: "bool"
1497
+ },
1498
+ {
1499
+ name: "created_slot",
1500
+ type: "u64"
1501
+ },
1502
+ {
1503
+ name: "last_modified_slot",
1504
+ type: "u64"
1505
+ },
1506
+ {
1507
+ name: "bump",
1508
+ type: "u8"
1509
+ },
1510
+ {
1511
+ name: "_padding",
1512
+ type: {
1513
+ array: [
1514
+ "u8",
1515
+ 64
1516
+ ]
1517
+ }
1518
+ }
1519
+ ]
1520
+ }
1521
+ },
1522
+ {
1523
+ name: "FeedbackRevoked",
1524
+ type: {
1525
+ kind: "struct",
1526
+ fields: [
1527
+ {
1528
+ name: "agent",
1529
+ type: "pubkey"
1530
+ },
1531
+ {
1532
+ name: "service",
1533
+ type: "pubkey"
1534
+ },
1535
+ {
1536
+ name: "feedback",
1537
+ type: "pubkey"
1538
+ },
1539
+ {
1540
+ name: "was_negative",
1541
+ type: "bool"
1542
+ },
1543
+ {
1544
+ name: "slot",
1545
+ type: "u64"
1546
+ }
1547
+ ]
1548
+ }
1549
+ },
1550
+ {
1551
+ name: "PaymentRecorded",
1552
+ type: {
1553
+ kind: "struct",
1554
+ fields: [
1555
+ {
1556
+ name: "agent",
1557
+ type: "pubkey"
1558
+ },
1559
+ {
1560
+ name: "service",
1561
+ type: "pubkey"
1562
+ },
1563
+ {
1564
+ name: "amount_usdc",
1565
+ type: "u64"
1566
+ },
1567
+ {
1568
+ name: "payment_receipt_hash",
1569
+ type: {
1570
+ array: [
1571
+ "u8",
1572
+ 32
1573
+ ]
1574
+ }
1575
+ },
1576
+ {
1577
+ name: "was_new_pair",
1578
+ type: "bool"
1579
+ },
1580
+ {
1581
+ name: "slot",
1582
+ type: "u64"
1583
+ }
1584
+ ]
1585
+ }
1586
+ },
1587
+ {
1588
+ name: "ReceiptUsed",
1589
+ type: {
1590
+ kind: "struct",
1591
+ fields: [
1592
+ {
1593
+ name: "receipt_hash",
1594
+ type: {
1595
+ array: [
1596
+ "u8",
1597
+ 32
1598
+ ]
1599
+ }
1600
+ },
1601
+ {
1602
+ name: "agent_service_link",
1603
+ type: "pubkey"
1604
+ },
1605
+ {
1606
+ name: "recorded_slot",
1607
+ type: "u64"
1608
+ },
1609
+ {
1610
+ name: "bump",
1611
+ type: "u8"
1612
+ },
1613
+ {
1614
+ name: "_padding",
1615
+ type: {
1616
+ array: [
1617
+ "u8",
1618
+ 32
1619
+ ]
1620
+ }
1621
+ }
1622
+ ]
1623
+ }
1624
+ },
1625
+ {
1626
+ name: "ResponseAppended",
1627
+ type: {
1628
+ kind: "struct",
1629
+ fields: [
1630
+ {
1631
+ name: "agent",
1632
+ type: "pubkey"
1633
+ },
1634
+ {
1635
+ name: "feedback",
1636
+ type: "pubkey"
1637
+ },
1638
+ {
1639
+ name: "responder",
1640
+ type: "pubkey"
1641
+ },
1642
+ {
1643
+ name: "slot",
1644
+ type: "u64"
1645
+ }
1646
+ ]
1647
+ }
1648
+ },
1649
+ {
1650
+ name: "ScoreComputed",
1651
+ type: {
1652
+ kind: "struct",
1653
+ fields: [
1654
+ {
1655
+ name: "agent",
1656
+ type: "pubkey"
1657
+ },
1658
+ {
1659
+ name: "score",
1660
+ type: "u16"
1661
+ },
1662
+ {
1663
+ name: "slot",
1664
+ type: "u64"
1665
+ }
1666
+ ]
1667
+ }
1668
+ },
1669
+ {
1670
+ name: "ServiceCategory",
1671
+ type: {
1672
+ kind: "enum",
1673
+ variants: [
1674
+ {
1675
+ name: "DataFeed"
1676
+ },
1677
+ {
1678
+ name: "Compute"
1679
+ },
1680
+ {
1681
+ name: "Swap"
1682
+ },
1683
+ {
1684
+ name: "Rpc"
1685
+ },
1686
+ {
1687
+ name: "Other"
1688
+ }
1689
+ ]
1690
+ }
1691
+ },
1692
+ {
1693
+ name: "ServiceRegistered",
1694
+ type: {
1695
+ kind: "struct",
1696
+ fields: [
1697
+ {
1698
+ name: "service",
1699
+ type: "pubkey"
1700
+ },
1701
+ {
1702
+ name: "name",
1703
+ type: {
1704
+ array: [
1705
+ "u8",
1706
+ 32
1707
+ ]
1708
+ }
1709
+ },
1710
+ {
1711
+ name: "category",
1712
+ type: {
1713
+ defined: {
1714
+ name: "ServiceCategory"
1715
+ }
1716
+ }
1717
+ },
1718
+ {
1719
+ name: "init_slot",
1720
+ type: "u64"
1721
+ }
1722
+ ]
1723
+ }
1724
+ },
1725
+ {
1726
+ name: "ServiceRegistry",
1727
+ type: {
1728
+ kind: "struct",
1729
+ fields: [
1730
+ {
1731
+ name: "authority",
1732
+ type: "pubkey"
1733
+ },
1734
+ {
1735
+ name: "name",
1736
+ type: {
1737
+ array: [
1738
+ "u8",
1739
+ 32
1740
+ ]
1741
+ }
1742
+ },
1743
+ {
1744
+ name: "category",
1745
+ type: {
1746
+ defined: {
1747
+ name: "ServiceCategory"
1748
+ }
1749
+ }
1750
+ },
1751
+ {
1752
+ name: "total_agents_served",
1753
+ type: "u64"
1754
+ },
1755
+ {
1756
+ name: "total_volume_received_usdc",
1757
+ type: "u64"
1758
+ },
1759
+ {
1760
+ name: "active",
1761
+ type: "bool"
1762
+ },
1763
+ {
1764
+ name: "first_active_slot",
1765
+ type: "u64"
1766
+ },
1767
+ {
1768
+ name: "last_active_slot",
1769
+ type: "u64"
1770
+ },
1771
+ {
1772
+ name: "bump",
1773
+ type: "u8"
1774
+ },
1775
+ {
1776
+ name: "_padding",
1777
+ type: {
1778
+ array: [
1779
+ "u8",
1780
+ 64
1781
+ ]
1782
+ }
1783
+ }
1784
+ ]
1785
+ }
1786
+ }
1787
+ ]
1788
+ };
1789
+
1790
+ // src/idl/credit-vault.json
1791
+ var credit_vault_default = {
1792
+ address: "EsykPsafhHUeN7jA9DGqBiGuBsTBaFynLDVVpE4jFXDg",
1793
+ metadata: {
1794
+ name: "credit_vault",
1795
+ version: "0.1.0",
1796
+ spec: "0.1.0",
1797
+ description: "Agent Fuel \u2014 Budget-bound USDC spending vault for AI agents on Solana",
1798
+ repository: "https://github.com/TODO/agent_fuel"
1799
+ },
1800
+ instructions: [
1801
+ {
1802
+ name: "claim",
1803
+ discriminator: [
1804
+ 62,
1805
+ 198,
1806
+ 214,
1807
+ 193,
1808
+ 213,
1809
+ 159,
1810
+ 108,
1811
+ 210
1812
+ ],
1813
+ accounts: [
1814
+ {
1815
+ name: "service",
1816
+ signer: true
1817
+ },
1818
+ {
1819
+ name: "vault",
1820
+ writable: true,
1821
+ pda: {
1822
+ seeds: [
1823
+ {
1824
+ kind: "const",
1825
+ value: [
1826
+ 118,
1827
+ 97,
1828
+ 117,
1829
+ 108,
1830
+ 116
1831
+ ]
1832
+ },
1833
+ {
1834
+ kind: "account",
1835
+ path: "vault.owner",
1836
+ account: "CreditVault"
1837
+ },
1838
+ {
1839
+ kind: "account",
1840
+ path: "vault.agent",
1841
+ account: "CreditVault"
1842
+ }
1843
+ ]
1844
+ }
1845
+ },
1846
+ {
1847
+ name: "policy",
1848
+ writable: true,
1849
+ pda: {
1850
+ seeds: [
1851
+ {
1852
+ kind: "const",
1853
+ value: [
1854
+ 112,
1855
+ 111,
1856
+ 108,
1857
+ 105,
1858
+ 99,
1859
+ 121
1860
+ ]
1861
+ },
1862
+ {
1863
+ kind: "account",
1864
+ path: "vault"
1865
+ }
1866
+ ]
1867
+ }
1868
+ },
1869
+ {
1870
+ name: "vault_token_account",
1871
+ writable: true
1872
+ },
1873
+ {
1874
+ name: "service_token_account",
1875
+ writable: true
1876
+ },
1877
+ {
1878
+ name: "token_program",
1879
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
1880
+ }
1881
+ ],
1882
+ args: [
1883
+ {
1884
+ name: "amount_usdc",
1885
+ type: "u64"
1886
+ }
1887
+ ]
1888
+ },
1889
+ {
1890
+ name: "create_vault",
1891
+ discriminator: [
1892
+ 29,
1893
+ 237,
1894
+ 247,
1895
+ 208,
1896
+ 193,
1897
+ 82,
1898
+ 54,
1899
+ 135
1900
+ ],
1901
+ accounts: [
1902
+ {
1903
+ name: "owner",
1904
+ writable: true,
1905
+ signer: true
1906
+ },
1907
+ {
1908
+ name: "agent",
1909
+ docs: [
1910
+ "account need not exist on chain; we never read or write its data."
1911
+ ]
1912
+ },
1913
+ {
1914
+ name: "usdc_mint"
1915
+ },
1916
+ {
1917
+ name: "vault",
1918
+ writable: true,
1919
+ pda: {
1920
+ seeds: [
1921
+ {
1922
+ kind: "const",
1923
+ value: [
1924
+ 118,
1925
+ 97,
1926
+ 117,
1927
+ 108,
1928
+ 116
1929
+ ]
1930
+ },
1931
+ {
1932
+ kind: "account",
1933
+ path: "owner"
1934
+ },
1935
+ {
1936
+ kind: "account",
1937
+ path: "agent"
1938
+ }
1939
+ ]
1940
+ }
1941
+ },
1942
+ {
1943
+ name: "policy",
1944
+ writable: true,
1945
+ pda: {
1946
+ seeds: [
1947
+ {
1948
+ kind: "const",
1949
+ value: [
1950
+ 112,
1951
+ 111,
1952
+ 108,
1953
+ 105,
1954
+ 99,
1955
+ 121
1956
+ ]
1957
+ },
1958
+ {
1959
+ kind: "account",
1960
+ path: "vault"
1961
+ }
1962
+ ]
1963
+ }
1964
+ },
1965
+ {
1966
+ name: "vault_token_account",
1967
+ writable: true,
1968
+ pda: {
1969
+ seeds: [
1970
+ {
1971
+ kind: "account",
1972
+ path: "vault"
1973
+ },
1974
+ {
1975
+ kind: "const",
1976
+ value: [
1977
+ 6,
1978
+ 221,
1979
+ 246,
1980
+ 225,
1981
+ 215,
1982
+ 101,
1983
+ 161,
1984
+ 147,
1985
+ 217,
1986
+ 203,
1987
+ 225,
1988
+ 70,
1989
+ 206,
1990
+ 235,
1991
+ 121,
1992
+ 172,
1993
+ 28,
1994
+ 180,
1995
+ 133,
1996
+ 237,
1997
+ 95,
1998
+ 91,
1999
+ 55,
2000
+ 145,
2001
+ 58,
2002
+ 140,
2003
+ 245,
2004
+ 133,
2005
+ 126,
2006
+ 255,
2007
+ 0,
2008
+ 169
2009
+ ]
2010
+ },
2011
+ {
2012
+ kind: "account",
2013
+ path: "usdc_mint"
2014
+ }
2015
+ ],
2016
+ program: {
2017
+ kind: "const",
2018
+ value: [
2019
+ 140,
2020
+ 151,
2021
+ 37,
2022
+ 143,
2023
+ 78,
2024
+ 36,
2025
+ 137,
2026
+ 241,
2027
+ 187,
2028
+ 61,
2029
+ 16,
2030
+ 41,
2031
+ 20,
2032
+ 142,
2033
+ 13,
2034
+ 131,
2035
+ 11,
2036
+ 90,
2037
+ 19,
2038
+ 153,
2039
+ 218,
2040
+ 255,
2041
+ 16,
2042
+ 132,
2043
+ 4,
2044
+ 142,
2045
+ 123,
2046
+ 216,
2047
+ 219,
2048
+ 233,
2049
+ 248,
2050
+ 89
2051
+ ]
2052
+ }
2053
+ }
2054
+ },
2055
+ {
2056
+ name: "token_program",
2057
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
2058
+ },
2059
+ {
2060
+ name: "associated_token_program",
2061
+ address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
2062
+ },
2063
+ {
2064
+ name: "system_program",
2065
+ address: "11111111111111111111111111111111"
2066
+ }
2067
+ ],
2068
+ args: [
2069
+ {
2070
+ name: "per_tx_limit_usdc",
2071
+ type: "u64"
2072
+ },
2073
+ {
2074
+ name: "hourly_limit_usdc",
2075
+ type: "u64"
2076
+ },
2077
+ {
2078
+ name: "lifetime_limit_usdc",
2079
+ type: "u64"
2080
+ },
2081
+ {
2082
+ name: "allow_post_pay",
2083
+ type: "bool"
2084
+ }
2085
+ ]
2086
+ },
2087
+ {
2088
+ name: "deposit",
2089
+ discriminator: [
2090
+ 242,
2091
+ 35,
2092
+ 198,
2093
+ 137,
2094
+ 82,
2095
+ 225,
2096
+ 242,
2097
+ 182
2098
+ ],
2099
+ accounts: [
2100
+ {
2101
+ name: "owner",
2102
+ writable: true,
2103
+ signer: true,
2104
+ relations: [
2105
+ "vault"
2106
+ ]
2107
+ },
2108
+ {
2109
+ name: "vault",
2110
+ writable: true,
2111
+ pda: {
2112
+ seeds: [
2113
+ {
2114
+ kind: "const",
2115
+ value: [
2116
+ 118,
2117
+ 97,
2118
+ 117,
2119
+ 108,
2120
+ 116
2121
+ ]
2122
+ },
2123
+ {
2124
+ kind: "account",
2125
+ path: "vault.owner",
2126
+ account: "CreditVault"
2127
+ },
2128
+ {
2129
+ kind: "account",
2130
+ path: "vault.agent",
2131
+ account: "CreditVault"
2132
+ }
2133
+ ]
2134
+ }
2135
+ },
2136
+ {
2137
+ name: "owner_token_account",
2138
+ writable: true
2139
+ },
2140
+ {
2141
+ name: "vault_token_account",
2142
+ writable: true
2143
+ },
2144
+ {
2145
+ name: "token_program",
2146
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
2147
+ }
2148
+ ],
2149
+ args: [
2150
+ {
2151
+ name: "amount_usdc",
2152
+ type: "u64"
2153
+ }
2154
+ ]
2155
+ },
2156
+ {
2157
+ name: "freeze_vault",
2158
+ discriminator: [
2159
+ 144,
2160
+ 211,
2161
+ 63,
2162
+ 236,
2163
+ 97,
2164
+ 31,
2165
+ 170,
2166
+ 175
2167
+ ],
2168
+ accounts: [
2169
+ {
2170
+ name: "owner",
2171
+ signer: true,
2172
+ relations: [
2173
+ "vault"
2174
+ ]
2175
+ },
2176
+ {
2177
+ name: "vault",
2178
+ writable: true,
2179
+ pda: {
2180
+ seeds: [
2181
+ {
2182
+ kind: "const",
2183
+ value: [
2184
+ 118,
2185
+ 97,
2186
+ 117,
2187
+ 108,
2188
+ 116
2189
+ ]
2190
+ },
2191
+ {
2192
+ kind: "account",
2193
+ path: "vault.owner",
2194
+ account: "CreditVault"
2195
+ },
2196
+ {
2197
+ kind: "account",
2198
+ path: "vault.agent",
2199
+ account: "CreditVault"
2200
+ }
2201
+ ]
2202
+ }
2203
+ }
2204
+ ],
2205
+ args: []
2206
+ },
2207
+ {
2208
+ name: "spend",
2209
+ discriminator: [
2210
+ 242,
2211
+ 205,
2212
+ 255,
2213
+ 87,
2214
+ 101,
2215
+ 217,
2216
+ 245,
2217
+ 57
2218
+ ],
2219
+ accounts: [
2220
+ {
2221
+ name: "agent",
2222
+ signer: true,
2223
+ relations: [
2224
+ "vault"
2225
+ ]
2226
+ },
2227
+ {
2228
+ name: "vault",
2229
+ writable: true,
2230
+ pda: {
2231
+ seeds: [
2232
+ {
2233
+ kind: "const",
2234
+ value: [
2235
+ 118,
2236
+ 97,
2237
+ 117,
2238
+ 108,
2239
+ 116
2240
+ ]
2241
+ },
2242
+ {
2243
+ kind: "account",
2244
+ path: "vault.owner",
2245
+ account: "CreditVault"
2246
+ },
2247
+ {
2248
+ kind: "account",
2249
+ path: "vault.agent",
2250
+ account: "CreditVault"
2251
+ }
2252
+ ]
2253
+ }
2254
+ },
2255
+ {
2256
+ name: "policy",
2257
+ writable: true,
2258
+ pda: {
2259
+ seeds: [
2260
+ {
2261
+ kind: "const",
2262
+ value: [
2263
+ 112,
2264
+ 111,
2265
+ 108,
2266
+ 105,
2267
+ 99,
2268
+ 121
2269
+ ]
2270
+ },
2271
+ {
2272
+ kind: "account",
2273
+ path: "vault"
2274
+ }
2275
+ ]
2276
+ }
2277
+ },
2278
+ {
2279
+ name: "vault_token_account",
2280
+ writable: true
2281
+ },
2282
+ {
2283
+ name: "service_token_account",
2284
+ writable: true
2285
+ },
2286
+ {
2287
+ name: "token_program",
2288
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
2289
+ }
2290
+ ],
2291
+ args: [
2292
+ {
2293
+ name: "amount_usdc",
2294
+ type: "u64"
2295
+ }
2296
+ ]
2297
+ },
2298
+ {
2299
+ name: "unfreeze_vault",
2300
+ discriminator: [
2301
+ 145,
2302
+ 244,
2303
+ 206,
2304
+ 234,
2305
+ 251,
2306
+ 250,
2307
+ 116,
2308
+ 183
2309
+ ],
2310
+ accounts: [
2311
+ {
2312
+ name: "owner",
2313
+ signer: true,
2314
+ relations: [
2315
+ "vault"
2316
+ ]
2317
+ },
2318
+ {
2319
+ name: "vault",
2320
+ writable: true,
2321
+ pda: {
2322
+ seeds: [
2323
+ {
2324
+ kind: "const",
2325
+ value: [
2326
+ 118,
2327
+ 97,
2328
+ 117,
2329
+ 108,
2330
+ 116
2331
+ ]
2332
+ },
2333
+ {
2334
+ kind: "account",
2335
+ path: "vault.owner",
2336
+ account: "CreditVault"
2337
+ },
2338
+ {
2339
+ kind: "account",
2340
+ path: "vault.agent",
2341
+ account: "CreditVault"
2342
+ }
2343
+ ]
2344
+ }
2345
+ }
2346
+ ],
2347
+ args: []
2348
+ },
2349
+ {
2350
+ name: "update_policy",
2351
+ discriminator: [
2352
+ 212,
2353
+ 245,
2354
+ 246,
2355
+ 7,
2356
+ 163,
2357
+ 151,
2358
+ 18,
2359
+ 57
2360
+ ],
2361
+ accounts: [
2362
+ {
2363
+ name: "owner",
2364
+ signer: true,
2365
+ relations: [
2366
+ "vault"
2367
+ ]
2368
+ },
2369
+ {
2370
+ name: "vault",
2371
+ pda: {
2372
+ seeds: [
2373
+ {
2374
+ kind: "const",
2375
+ value: [
2376
+ 118,
2377
+ 97,
2378
+ 117,
2379
+ 108,
2380
+ 116
2381
+ ]
2382
+ },
2383
+ {
2384
+ kind: "account",
2385
+ path: "vault.owner",
2386
+ account: "CreditVault"
2387
+ },
2388
+ {
2389
+ kind: "account",
2390
+ path: "vault.agent",
2391
+ account: "CreditVault"
2392
+ }
2393
+ ]
2394
+ }
2395
+ },
2396
+ {
2397
+ name: "policy",
2398
+ writable: true,
2399
+ pda: {
2400
+ seeds: [
2401
+ {
2402
+ kind: "const",
2403
+ value: [
2404
+ 112,
2405
+ 111,
2406
+ 108,
2407
+ 105,
2408
+ 99,
2409
+ 121
2410
+ ]
2411
+ },
2412
+ {
2413
+ kind: "account",
2414
+ path: "vault"
2415
+ }
2416
+ ]
2417
+ }
2418
+ }
2419
+ ],
2420
+ args: [
2421
+ {
2422
+ name: "new_per_tx_limit_usdc",
2423
+ type: "u64"
2424
+ },
2425
+ {
2426
+ name: "new_hourly_limit_usdc",
2427
+ type: "u64"
2428
+ },
2429
+ {
2430
+ name: "new_lifetime_limit_usdc",
2431
+ type: "u64"
2432
+ },
2433
+ {
2434
+ name: "new_allow_post_pay",
2435
+ type: "bool"
2436
+ },
2437
+ {
2438
+ name: "new_whitelist",
2439
+ type: {
2440
+ array: [
2441
+ "pubkey",
2442
+ 8
2443
+ ]
2444
+ }
2445
+ }
2446
+ ]
2447
+ },
2448
+ {
2449
+ name: "withdraw",
2450
+ discriminator: [
2451
+ 183,
2452
+ 18,
2453
+ 70,
2454
+ 156,
2455
+ 148,
2456
+ 109,
2457
+ 161,
2458
+ 34
2459
+ ],
2460
+ accounts: [
2461
+ {
2462
+ name: "owner",
2463
+ writable: true,
2464
+ signer: true,
2465
+ relations: [
2466
+ "vault"
2467
+ ]
2468
+ },
2469
+ {
2470
+ name: "vault",
2471
+ writable: true,
2472
+ pda: {
2473
+ seeds: [
2474
+ {
2475
+ kind: "const",
2476
+ value: [
2477
+ 118,
2478
+ 97,
2479
+ 117,
2480
+ 108,
2481
+ 116
2482
+ ]
2483
+ },
2484
+ {
2485
+ kind: "account",
2486
+ path: "vault.owner",
2487
+ account: "CreditVault"
2488
+ },
2489
+ {
2490
+ kind: "account",
2491
+ path: "vault.agent",
2492
+ account: "CreditVault"
2493
+ }
2494
+ ]
2495
+ }
2496
+ },
2497
+ {
2498
+ name: "vault_token_account",
2499
+ writable: true
2500
+ },
2501
+ {
2502
+ name: "owner_token_account",
2503
+ writable: true
2504
+ },
2505
+ {
2506
+ name: "token_program",
2507
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
2508
+ }
2509
+ ],
2510
+ args: [
2511
+ {
2512
+ name: "amount_usdc",
2513
+ type: "u64"
2514
+ }
2515
+ ]
2516
+ }
2517
+ ],
2518
+ accounts: [
2519
+ {
2520
+ name: "CreditVault",
2521
+ discriminator: [
2522
+ 143,
2523
+ 180,
2524
+ 135,
2525
+ 248,
2526
+ 84,
2527
+ 85,
2528
+ 183,
2529
+ 70
2530
+ ]
2531
+ },
2532
+ {
2533
+ name: "SpendPolicy",
2534
+ discriminator: [
2535
+ 139,
2536
+ 90,
2537
+ 209,
2538
+ 31,
2539
+ 205,
2540
+ 15,
2541
+ 68,
2542
+ 243
2543
+ ]
2544
+ }
2545
+ ],
2546
+ events: [
2547
+ {
2548
+ name: "Claimed",
2549
+ discriminator: [
2550
+ 217,
2551
+ 192,
2552
+ 123,
2553
+ 72,
2554
+ 108,
2555
+ 150,
2556
+ 248,
2557
+ 33
2558
+ ]
2559
+ },
2560
+ {
2561
+ name: "Deposited",
2562
+ discriminator: [
2563
+ 111,
2564
+ 141,
2565
+ 26,
2566
+ 45,
2567
+ 161,
2568
+ 35,
2569
+ 100,
2570
+ 57
2571
+ ]
2572
+ },
2573
+ {
2574
+ name: "PolicyUpdated",
2575
+ discriminator: [
2576
+ 225,
2577
+ 112,
2578
+ 112,
2579
+ 67,
2580
+ 95,
2581
+ 236,
2582
+ 245,
2583
+ 161
2584
+ ]
2585
+ },
2586
+ {
2587
+ name: "Spent",
2588
+ discriminator: [
2589
+ 43,
2590
+ 51,
2591
+ 164,
2592
+ 100,
2593
+ 191,
2594
+ 244,
2595
+ 174,
2596
+ 98
2597
+ ]
2598
+ },
2599
+ {
2600
+ name: "VaultCreated",
2601
+ discriminator: [
2602
+ 117,
2603
+ 25,
2604
+ 120,
2605
+ 254,
2606
+ 75,
2607
+ 236,
2608
+ 78,
2609
+ 115
2610
+ ]
2611
+ },
2612
+ {
2613
+ name: "VaultFrozen",
2614
+ discriminator: [
2615
+ 13,
2616
+ 199,
2617
+ 172,
2618
+ 111,
2619
+ 88,
2620
+ 10,
2621
+ 151,
2622
+ 247
2623
+ ]
2624
+ },
2625
+ {
2626
+ name: "VaultUnfrozen",
2627
+ discriminator: [
2628
+ 128,
2629
+ 194,
2630
+ 79,
2631
+ 155,
2632
+ 85,
2633
+ 31,
2634
+ 226,
2635
+ 170
2636
+ ]
2637
+ },
2638
+ {
2639
+ name: "Withdrawn",
2640
+ discriminator: [
2641
+ 20,
2642
+ 89,
2643
+ 223,
2644
+ 198,
2645
+ 194,
2646
+ 124,
2647
+ 219,
2648
+ 13
2649
+ ]
2650
+ }
2651
+ ],
2652
+ errors: [
2653
+ {
2654
+ code: 6e3,
2655
+ name: "Overflow",
2656
+ msg: "Counter or amount overflow"
2657
+ },
2658
+ {
2659
+ code: 6001,
2660
+ name: "ZeroAmount",
2661
+ msg: "Amount must be greater than zero"
2662
+ },
2663
+ {
2664
+ code: 6002,
2665
+ name: "Frozen",
2666
+ msg: "Vault is frozen"
2667
+ },
2668
+ {
2669
+ code: 6003,
2670
+ name: "NotWhitelisted",
2671
+ msg: "Service is not on the vault's whitelist"
2672
+ },
2673
+ {
2674
+ code: 6004,
2675
+ name: "PerTxLimitExceeded",
2676
+ msg: "Amount exceeds the per-transaction limit"
2677
+ },
2678
+ {
2679
+ code: 6005,
2680
+ name: "HourlyLimitExceeded",
2681
+ msg: "Amount exceeds the hourly rolling-window limit"
2682
+ },
2683
+ {
2684
+ code: 6006,
2685
+ name: "LifetimeLimitExceeded",
2686
+ msg: "Amount would exceed the lifetime spend ceiling"
2687
+ },
2688
+ {
2689
+ code: 6007,
2690
+ name: "AlreadyFrozen",
2691
+ msg: "Vault is already frozen"
2692
+ },
2693
+ {
2694
+ code: 6008,
2695
+ name: "NotFrozen",
2696
+ msg: "Vault is not frozen"
2697
+ },
2698
+ {
2699
+ code: 6009,
2700
+ name: "PostPayDisabled",
2701
+ msg: "Post-pay claims are disabled for this vault"
2702
+ }
2703
+ ],
2704
+ types: [
2705
+ {
2706
+ name: "Claimed",
2707
+ type: {
2708
+ kind: "struct",
2709
+ fields: [
2710
+ {
2711
+ name: "vault",
2712
+ type: "pubkey"
2713
+ },
2714
+ {
2715
+ name: "service",
2716
+ type: "pubkey"
2717
+ },
2718
+ {
2719
+ name: "amount_usdc",
2720
+ type: "u64"
2721
+ },
2722
+ {
2723
+ name: "new_total_spent",
2724
+ type: "u64"
2725
+ },
2726
+ {
2727
+ name: "new_total_claimed",
2728
+ type: "u64"
2729
+ },
2730
+ {
2731
+ name: "slot",
2732
+ type: "u64"
2733
+ }
2734
+ ]
2735
+ }
2736
+ },
2737
+ {
2738
+ name: "CreditVault",
2739
+ type: {
2740
+ kind: "struct",
2741
+ fields: [
2742
+ {
2743
+ name: "owner",
2744
+ type: "pubkey"
2745
+ },
2746
+ {
2747
+ name: "agent",
2748
+ type: "pubkey"
2749
+ },
2750
+ {
2751
+ name: "usdc_mint",
2752
+ type: "pubkey"
2753
+ },
2754
+ {
2755
+ name: "vault_token_account",
2756
+ type: "pubkey"
2757
+ },
2758
+ {
2759
+ name: "total_deposited",
2760
+ type: "u64"
2761
+ },
2762
+ {
2763
+ name: "total_withdrawn",
2764
+ type: "u64"
2765
+ },
2766
+ {
2767
+ name: "total_spent",
2768
+ type: "u64"
2769
+ },
2770
+ {
2771
+ name: "total_claimed",
2772
+ type: "u64"
2773
+ },
2774
+ {
2775
+ name: "frozen",
2776
+ type: "bool"
2777
+ },
2778
+ {
2779
+ name: "created_slot",
2780
+ type: "u64"
2781
+ },
2782
+ {
2783
+ name: "last_active_slot",
2784
+ type: "u64"
2785
+ },
2786
+ {
2787
+ name: "bump",
2788
+ type: "u8"
2789
+ },
2790
+ {
2791
+ name: "_padding",
2792
+ type: {
2793
+ array: [
2794
+ "u8",
2795
+ 64
2796
+ ]
2797
+ }
2798
+ }
2799
+ ]
2800
+ }
2801
+ },
2802
+ {
2803
+ name: "Deposited",
2804
+ type: {
2805
+ kind: "struct",
2806
+ fields: [
2807
+ {
2808
+ name: "vault",
2809
+ type: "pubkey"
2810
+ },
2811
+ {
2812
+ name: "owner",
2813
+ type: "pubkey"
2814
+ },
2815
+ {
2816
+ name: "amount_usdc",
2817
+ type: "u64"
2818
+ },
2819
+ {
2820
+ name: "new_total_deposited",
2821
+ type: "u64"
2822
+ },
2823
+ {
2824
+ name: "slot",
2825
+ type: "u64"
2826
+ }
2827
+ ]
2828
+ }
2829
+ },
2830
+ {
2831
+ name: "PolicyUpdated",
2832
+ type: {
2833
+ kind: "struct",
2834
+ fields: [
2835
+ {
2836
+ name: "vault",
2837
+ type: "pubkey"
2838
+ },
2839
+ {
2840
+ name: "owner",
2841
+ type: "pubkey"
2842
+ },
2843
+ {
2844
+ name: "per_tx_limit_usdc",
2845
+ type: "u64"
2846
+ },
2847
+ {
2848
+ name: "hourly_limit_usdc",
2849
+ type: "u64"
2850
+ },
2851
+ {
2852
+ name: "lifetime_limit_usdc",
2853
+ type: "u64"
2854
+ },
2855
+ {
2856
+ name: "allow_post_pay",
2857
+ type: "bool"
2858
+ },
2859
+ {
2860
+ name: "whitelist",
2861
+ type: {
2862
+ array: [
2863
+ "pubkey",
2864
+ 8
2865
+ ]
2866
+ }
2867
+ },
2868
+ {
2869
+ name: "slot",
2870
+ type: "u64"
2871
+ }
2872
+ ]
2873
+ }
2874
+ },
2875
+ {
2876
+ name: "SpendPolicy",
2877
+ type: {
2878
+ kind: "struct",
2879
+ fields: [
2880
+ {
2881
+ name: "vault",
2882
+ type: "pubkey"
2883
+ },
2884
+ {
2885
+ name: "whitelist",
2886
+ type: {
2887
+ array: [
2888
+ "pubkey",
2889
+ 8
2890
+ ]
2891
+ }
2892
+ },
2893
+ {
2894
+ name: "per_tx_limit_usdc",
2895
+ type: "u64"
2896
+ },
2897
+ {
2898
+ name: "hourly_limit_usdc",
2899
+ type: "u64"
2900
+ },
2901
+ {
2902
+ name: "lifetime_limit_usdc",
2903
+ type: "u64"
2904
+ },
2905
+ {
2906
+ name: "hourly_window_start_slot",
2907
+ type: "u64"
2908
+ },
2909
+ {
2910
+ name: "hourly_window_spent_usdc",
2911
+ type: "u64"
2912
+ },
2913
+ {
2914
+ name: "allow_post_pay",
2915
+ type: "bool"
2916
+ },
2917
+ {
2918
+ name: "bump",
2919
+ type: "u8"
2920
+ },
2921
+ {
2922
+ name: "_padding",
2923
+ type: {
2924
+ array: [
2925
+ "u8",
2926
+ 64
2927
+ ]
2928
+ }
2929
+ }
2930
+ ]
2931
+ }
2932
+ },
2933
+ {
2934
+ name: "Spent",
2935
+ type: {
2936
+ kind: "struct",
2937
+ fields: [
2938
+ {
2939
+ name: "vault",
2940
+ type: "pubkey"
2941
+ },
2942
+ {
2943
+ name: "agent",
2944
+ type: "pubkey"
2945
+ },
2946
+ {
2947
+ name: "service",
2948
+ type: "pubkey"
2949
+ },
2950
+ {
2951
+ name: "amount_usdc",
2952
+ type: "u64"
2953
+ },
2954
+ {
2955
+ name: "new_total_spent",
2956
+ type: "u64"
2957
+ },
2958
+ {
2959
+ name: "slot",
2960
+ type: "u64"
2961
+ }
2962
+ ]
2963
+ }
2964
+ },
2965
+ {
2966
+ name: "VaultCreated",
2967
+ type: {
2968
+ kind: "struct",
2969
+ fields: [
2970
+ {
2971
+ name: "vault",
2972
+ type: "pubkey"
2973
+ },
2974
+ {
2975
+ name: "owner",
2976
+ type: "pubkey"
2977
+ },
2978
+ {
2979
+ name: "agent",
2980
+ type: "pubkey"
2981
+ },
2982
+ {
2983
+ name: "usdc_mint",
2984
+ type: "pubkey"
2985
+ },
2986
+ {
2987
+ name: "vault_token_account",
2988
+ type: "pubkey"
2989
+ },
2990
+ {
2991
+ name: "slot",
2992
+ type: "u64"
2993
+ }
2994
+ ]
2995
+ }
2996
+ },
2997
+ {
2998
+ name: "VaultFrozen",
2999
+ type: {
3000
+ kind: "struct",
3001
+ fields: [
3002
+ {
3003
+ name: "vault",
3004
+ type: "pubkey"
3005
+ },
3006
+ {
3007
+ name: "owner",
3008
+ type: "pubkey"
3009
+ },
3010
+ {
3011
+ name: "slot",
3012
+ type: "u64"
3013
+ }
3014
+ ]
3015
+ }
3016
+ },
3017
+ {
3018
+ name: "VaultUnfrozen",
3019
+ type: {
3020
+ kind: "struct",
3021
+ fields: [
3022
+ {
3023
+ name: "vault",
3024
+ type: "pubkey"
3025
+ },
3026
+ {
3027
+ name: "owner",
3028
+ type: "pubkey"
3029
+ },
3030
+ {
3031
+ name: "slot",
3032
+ type: "u64"
3033
+ }
3034
+ ]
3035
+ }
3036
+ },
3037
+ {
3038
+ name: "Withdrawn",
3039
+ type: {
3040
+ kind: "struct",
3041
+ fields: [
3042
+ {
3043
+ name: "vault",
3044
+ type: "pubkey"
3045
+ },
3046
+ {
3047
+ name: "owner",
3048
+ type: "pubkey"
3049
+ },
3050
+ {
3051
+ name: "amount_usdc",
3052
+ type: "u64"
3053
+ },
3054
+ {
3055
+ name: "new_total_withdrawn",
3056
+ type: "u64"
3057
+ },
3058
+ {
3059
+ name: "slot",
3060
+ type: "u64"
3061
+ }
3062
+ ]
3063
+ }
3064
+ }
3065
+ ]
3066
+ };
3067
+
3068
+ // src/program-ids.ts
3069
+ var PROGRAM_IDS = {
3070
+ reputation: new web3_js.PublicKey(reputation_default.address),
3071
+ creditVault: new web3_js.PublicKey(credit_vault_default.address)
3072
+ };
3073
+
3074
+ // src/pda.ts
3075
+ function toPubkey(value) {
3076
+ return value instanceof web3_js.PublicKey ? value : new web3_js.PublicKey(value);
3077
+ }
3078
+ function vaultPda(owner, agent) {
3079
+ const [pda] = web3_js.PublicKey.findProgramAddressSync(
3080
+ [Buffer.from("vault"), toPubkey(owner).toBuffer(), toPubkey(agent).toBuffer()],
3081
+ PROGRAM_IDS.creditVault
3082
+ );
3083
+ return pda;
3084
+ }
3085
+ function policyPda(vault) {
3086
+ const [pda] = web3_js.PublicKey.findProgramAddressSync(
3087
+ [Buffer.from("policy"), toPubkey(vault).toBuffer()],
3088
+ PROGRAM_IDS.creditVault
3089
+ );
3090
+ return pda;
3091
+ }
3092
+ function serviceRegistryPda(serviceAuthority) {
3093
+ const [pda] = web3_js.PublicKey.findProgramAddressSync(
3094
+ [Buffer.from("service"), toPubkey(serviceAuthority).toBuffer()],
3095
+ PROGRAM_IDS.reputation
3096
+ );
3097
+ return pda;
3098
+ }
3099
+ function buildProvider(connection, keypair) {
3100
+ return new anchor.AnchorProvider(connection, new anchor.Wallet(keypair), anchor.AnchorProvider.defaultOptions());
3101
+ }
3102
+ function creditVaultProgram(provider) {
3103
+ return new anchor.Program(credit_vault_default, provider);
3104
+ }
3105
+ function reputationProgram(provider) {
3106
+ return new anchor.Program(reputation_default, provider);
3107
+ }
3108
+
3109
+ // src/client.ts
3110
+ var DEFAULT_API_BASE = "http://localhost:8080";
3111
+ var AgentFuel = class {
3112
+ agent;
3113
+ cluster;
3114
+ connection;
3115
+ apiBase;
3116
+ owner;
3117
+ _creditVault;
3118
+ _reputation;
3119
+ constructor(opts) {
3120
+ this.agent = opts.agent;
3121
+ this.cluster = opts.cluster;
3122
+ this.connection = typeof opts.rpc === "string" ? new web3_js.Connection(opts.rpc, "confirmed") : opts.rpc;
3123
+ this.apiBase = opts.apiBase ?? DEFAULT_API_BASE;
3124
+ this.owner = opts.owner ? toPubkey(opts.owner) : void 0;
3125
+ }
3126
+ get agentPubkey() {
3127
+ return this.agent.publicKey;
3128
+ }
3129
+ get creditVault() {
3130
+ if (!this._creditVault) {
3131
+ this._creditVault = creditVaultProgram(buildProvider(this.connection, this.agent));
3132
+ }
3133
+ return this._creditVault;
3134
+ }
3135
+ get reputation() {
3136
+ if (!this._reputation) {
3137
+ this._reputation = reputationProgram(buildProvider(this.connection, this.agent));
3138
+ }
3139
+ return this._reputation;
3140
+ }
3141
+ resolveOwner(override) {
3142
+ const value = override ?? this.owner;
3143
+ if (!value) throw new OwnerNotConfiguredError();
3144
+ return toPubkey(value);
3145
+ }
3146
+ async getScore(agent) {
3147
+ const target = agent ? toPubkey(agent) : this.agentPubkey;
3148
+ const agentStr = target.toBase58();
3149
+ const url = `${this.apiBase.replace(/\/$/, "")}/reputation/${agentStr}`;
3150
+ const res = await fetch(url);
3151
+ if (res.status === 404) throw new AccountNotFoundError(agentStr);
3152
+ if (!res.ok) throw new HttpError(res.status, url, await safeText(res));
3153
+ return await res.json();
3154
+ }
3155
+ async getVaultBalance(ref) {
3156
+ const owner = this.resolveOwner(ref?.owner);
3157
+ const agent = ref?.agent ? toPubkey(ref.agent) : this.agentPubkey;
3158
+ const pda = vaultPda(owner, agent);
3159
+ const raw = await this.creditVault.account.creditVault.fetchNullable(pda);
3160
+ if (!raw) throw new AccountNotFoundError(pda.toBase58());
3161
+ return decodeCreditVault(pda, raw);
3162
+ }
3163
+ async getPolicy(ref) {
3164
+ const owner = this.resolveOwner(ref?.owner);
3165
+ const agent = ref?.agent ? toPubkey(ref.agent) : this.agentPubkey;
3166
+ const vault = vaultPda(owner, agent);
3167
+ const pda = policyPda(vault);
3168
+ const raw = await this.creditVault.account.spendPolicy.fetchNullable(pda);
3169
+ if (!raw) throw new AccountNotFoundError(pda.toBase58());
3170
+ return decodeSpendPolicy(pda, raw);
3171
+ }
3172
+ async checkService(serviceAuthority) {
3173
+ const pda = serviceRegistryPda(serviceAuthority);
3174
+ const raw = await this.reputation.account.serviceRegistry.fetchNullable(pda);
3175
+ if (!raw) throw new AccountNotFoundError(pda.toBase58());
3176
+ return decodeServiceRegistry(pda, raw);
3177
+ }
3178
+ async spend(args) {
3179
+ const owner = this.resolveOwner(args.owner);
3180
+ const service = toPubkey(args.service);
3181
+ const amountUsdc = args.amountUsdc;
3182
+ const vault = await this.getVaultBalance({ owner, agent: this.agentPubkey });
3183
+ const policy = await this.getPolicy({ owner, agent: this.agentPubkey });
3184
+ const currentSlot = await this.connection.getSlot();
3185
+ guardSpend({ vault, policy, service, amountUsdc, currentSlot });
3186
+ const serviceTokenAccount = getAssociatedTokenAddress(vault.usdc_mint, service);
3187
+ const createAtaIx = createAssociatedTokenAccountIdempotentInstruction(
3188
+ this.agentPubkey,
3189
+ serviceTokenAccount,
3190
+ service,
3191
+ vault.usdc_mint
3192
+ );
3193
+ try {
3194
+ const signature = await this.creditVault.methods.spend(new anchor.BN(amountUsdc)).accounts({
3195
+ agent: this.agentPubkey,
3196
+ vault: vault.pubkey,
3197
+ policy: policy.pubkey,
3198
+ vaultTokenAccount: vault.vault_token_account,
3199
+ serviceTokenAccount,
3200
+ tokenProgram: TOKEN_PROGRAM_ID
3201
+ }).preInstructions([createAtaIx]).signers([this.agent]).rpc();
3202
+ return { signature };
3203
+ } catch (err) {
3204
+ throw mapSpendError(err, { service, amountUsdc, vault, policy });
3205
+ }
3206
+ }
3207
+ onEvent(callback, options) {
3208
+ const target = options?.agent ? toPubkey(options.agent) : this.agentPubkey;
3209
+ const url = wsUrl(this.apiBase, `/ws/agents/${target.toBase58()}`);
3210
+ const subOpts = {
3211
+ onFrame: callback
3212
+ };
3213
+ if (options?.onStatus) subOpts.onStatus = options.onStatus;
3214
+ return subscribe(url, subOpts);
3215
+ }
3216
+ };
3217
+ function mapSpendError(err, ctx) {
3218
+ if (!(err instanceof anchor.AnchorError)) return err;
3219
+ switch (err.error.errorCode.number) {
3220
+ case 6001:
3221
+ return new ZeroAmountError();
3222
+ case 6002:
3223
+ return new VaultFrozenError();
3224
+ case 6003:
3225
+ return new NotWhitelistedError(ctx.service.toBase58());
3226
+ case 6004:
3227
+ return new PerTxLimitExceededError(ctx.amountUsdc, ctx.policy.per_tx_limit_usdc);
3228
+ case 6005:
3229
+ return new HourlyLimitExceededError(
3230
+ ctx.amountUsdc,
3231
+ ctx.policy.hourly_window_spent_usdc,
3232
+ ctx.policy.hourly_limit_usdc
3233
+ );
3234
+ case 6006:
3235
+ return new LifetimeLimitExceededError(
3236
+ ctx.amountUsdc,
3237
+ ctx.vault.total_spent,
3238
+ ctx.policy.lifetime_limit_usdc
3239
+ );
3240
+ default:
3241
+ return err;
3242
+ }
3243
+ }
3244
+ async function safeText(res) {
3245
+ try {
3246
+ return await res.text();
3247
+ } catch {
3248
+ return void 0;
3249
+ }
3250
+ }
3251
+
3252
+ // src/x402.ts
3253
+ var HEADER = "X-Payment-Required";
3254
+ var PAYMENT_HEADER = "X-Payment";
3255
+ var PaymentParseError = class extends AgentFuelError {
3256
+ constructor(message) {
3257
+ super(message);
3258
+ this.name = "PaymentParseError";
3259
+ }
3260
+ };
3261
+ function paymentRequired(fuel, opts = {}) {
3262
+ const baseFetch = opts.fetch ?? ((input, init) => fetch(input, init));
3263
+ return async (input, init) => {
3264
+ const first = await baseFetch(input, init);
3265
+ if (first.status !== 402) return first;
3266
+ const req = await parseRequirement(first);
3267
+ if (opts.onPaymentRequired) await opts.onPaymentRequired(req);
3268
+ const { signature } = await fuel.spend({
3269
+ service: req.recipient,
3270
+ amountUsdc: req.amountUsdc
3271
+ });
3272
+ if (opts.onPaid) await opts.onPaid(signature, req);
3273
+ const headers = new Headers(init?.headers);
3274
+ headers.set(PAYMENT_HEADER, signature);
3275
+ return baseFetch(input, { ...init, headers });
3276
+ };
3277
+ }
3278
+ async function parseRequirement(res) {
3279
+ const header = res.headers.get(HEADER);
3280
+ if (header) return parseJson(header);
3281
+ let bodyText;
3282
+ try {
3283
+ bodyText = await res.clone().text();
3284
+ } catch {
3285
+ throw new PaymentParseError(`402 response has no ${HEADER} header and the body is unreadable`);
3286
+ }
3287
+ if (!bodyText.trim()) {
3288
+ throw new PaymentParseError(`402 response has no ${HEADER} header and an empty body`);
3289
+ }
3290
+ return parseJson(bodyText);
3291
+ }
3292
+ function parseJson(text) {
3293
+ let obj;
3294
+ try {
3295
+ obj = JSON.parse(text);
3296
+ } catch {
3297
+ throw new PaymentParseError(`payment payload is not valid JSON: ${truncate(text)}`);
3298
+ }
3299
+ if (typeof obj !== "object" || obj === null) {
3300
+ throw new PaymentParseError(`payment payload is not an object`);
3301
+ }
3302
+ const r = obj;
3303
+ const recipient = stringField(r, "recipient") ?? stringField(r, "payTo");
3304
+ if (!recipient) {
3305
+ throw new PaymentParseError(`payment payload missing 'recipient' or 'payTo'`);
3306
+ }
3307
+ const amount = numericField(r, "amountUsdc") ?? numericField(r, "maxAmountRequired");
3308
+ if (amount === null || amount <= 0) {
3309
+ throw new PaymentParseError(
3310
+ `payment payload missing positive 'amountUsdc' or 'maxAmountRequired'`
3311
+ );
3312
+ }
3313
+ const out = { recipient, amountUsdc: amount };
3314
+ const network = stringField(r, "network");
3315
+ if (network) out.network = network;
3316
+ const resource = stringField(r, "resource");
3317
+ if (resource) out.resource = resource;
3318
+ return out;
3319
+ }
3320
+ function stringField(r, key) {
3321
+ const v = r[key];
3322
+ return typeof v === "string" && v.length > 0 ? v : void 0;
3323
+ }
3324
+ function numericField(r, key) {
3325
+ const v = r[key];
3326
+ if (typeof v === "number" && Number.isFinite(v)) return v;
3327
+ if (typeof v === "string") {
3328
+ const n = Number(v);
3329
+ if (Number.isFinite(n)) return n;
3330
+ }
3331
+ return null;
3332
+ }
3333
+ function truncate(s) {
3334
+ return s.length > 80 ? `${s.slice(0, 80)}\u2026` : s;
3335
+ }
3336
+
3337
+ exports.ASSOCIATED_TOKEN_PROGRAM_ID = ASSOCIATED_TOKEN_PROGRAM_ID;
3338
+ exports.AccountNotFoundError = AccountNotFoundError;
3339
+ exports.AgentFuel = AgentFuel;
3340
+ exports.AgentFuelError = AgentFuelError;
3341
+ exports.HourlyLimitExceededError = HourlyLimitExceededError;
3342
+ exports.HttpError = HttpError;
3343
+ exports.LifetimeLimitExceededError = LifetimeLimitExceededError;
3344
+ exports.NotWhitelistedError = NotWhitelistedError;
3345
+ exports.OwnerNotConfiguredError = OwnerNotConfiguredError;
3346
+ exports.PROGRAM_IDS = PROGRAM_IDS;
3347
+ exports.PaymentParseError = PaymentParseError;
3348
+ exports.PerTxLimitExceededError = PerTxLimitExceededError;
3349
+ exports.SLOTS_PER_HOUR = SLOTS_PER_HOUR;
3350
+ exports.SpendPolicyError = SpendPolicyError;
3351
+ exports.TOKEN_PROGRAM_ID = TOKEN_PROGRAM_ID;
3352
+ exports.VaultFrozenError = VaultFrozenError;
3353
+ exports.ZeroAmountError = ZeroAmountError;
3354
+ exports.createAssociatedTokenAccountIdempotentInstruction = createAssociatedTokenAccountIdempotentInstruction;
3355
+ exports.getAssociatedTokenAddress = getAssociatedTokenAddress;
3356
+ exports.paymentRequired = paymentRequired;
3357
+ exports.policyPda = policyPda;
3358
+ exports.serviceRegistryPda = serviceRegistryPda;
3359
+ exports.vaultPda = vaultPda;
3360
+ //# sourceMappingURL=index.cjs.map
3361
+ //# sourceMappingURL=index.cjs.map