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