@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.
@@ -0,0 +1,193 @@
1
+ import { PublicKey, Keypair, Connection, TransactionInstruction } from '@solana/web3.js';
2
+
3
+ type Pubkeyish = PublicKey | string;
4
+ type CreditVaultAccount = {
5
+ pubkey: PublicKey;
6
+ owner: PublicKey;
7
+ agent: PublicKey;
8
+ usdc_mint: PublicKey;
9
+ vault_token_account: PublicKey;
10
+ total_deposited: number;
11
+ total_withdrawn: number;
12
+ total_spent: number;
13
+ total_claimed: number;
14
+ balance: number;
15
+ frozen: boolean;
16
+ created_slot: number;
17
+ last_active_slot: number;
18
+ };
19
+ type SpendPolicyAccount = {
20
+ pubkey: PublicKey;
21
+ vault: PublicKey;
22
+ whitelist: PublicKey[];
23
+ per_tx_limit_usdc: number;
24
+ hourly_limit_usdc: number;
25
+ lifetime_limit_usdc: number;
26
+ hourly_window_start_slot: number;
27
+ hourly_window_spent_usdc: number;
28
+ allow_post_pay: boolean;
29
+ };
30
+ type ServiceCategory = "DataFeed" | "Compute" | "Swap" | "Rpc" | "Other";
31
+ type ServiceRegistryAccount = {
32
+ pubkey: PublicKey;
33
+ authority: PublicKey;
34
+ name: string;
35
+ category: ServiceCategory;
36
+ total_agents_served: number;
37
+ total_volume_received_usdc: number;
38
+ active: boolean;
39
+ first_active_slot: number;
40
+ last_active_slot: number;
41
+ };
42
+ type LiveEventFrame = {
43
+ type: "event";
44
+ signature: string;
45
+ log_index: number;
46
+ slot: number;
47
+ program_id: string;
48
+ event_name: string;
49
+ payload: Record<string, unknown>;
50
+ };
51
+ type LiveStatus = "connecting" | "open" | "reconnecting" | "closed";
52
+ type Subscription = {
53
+ close(): void;
54
+ readonly status: LiveStatus;
55
+ };
56
+ type ReputationLookup = {
57
+ agent: string;
58
+ score: number | null;
59
+ total_transactions: number;
60
+ total_volume_usdc: number;
61
+ services_used: number;
62
+ consecutive_success: number;
63
+ total_feedback_count: number;
64
+ active_negative_feedback_count: number;
65
+ last_active_slot: number;
66
+ updated_at: string;
67
+ };
68
+
69
+ type Cluster = "mainnet-beta" | "devnet" | "testnet" | "localnet";
70
+ type AgentFuelOptions = {
71
+ agent: Keypair;
72
+ cluster: Cluster;
73
+ rpc: string | Connection;
74
+ owner?: Pubkeyish;
75
+ apiBase?: string;
76
+ };
77
+ type VaultRef = {
78
+ owner?: Pubkeyish;
79
+ agent?: Pubkeyish;
80
+ };
81
+ type SpendArgs = {
82
+ service: Pubkeyish;
83
+ amountUsdc: number;
84
+ owner?: Pubkeyish;
85
+ };
86
+ type SpendResult = {
87
+ signature: string;
88
+ };
89
+ type OnEventOptions = {
90
+ agent?: Pubkeyish;
91
+ onStatus?: (status: LiveStatus) => void;
92
+ };
93
+ declare class AgentFuel {
94
+ readonly agent: Keypair;
95
+ readonly cluster: Cluster;
96
+ readonly connection: Connection;
97
+ readonly apiBase: string;
98
+ readonly owner: PublicKey | undefined;
99
+ private _creditVault;
100
+ private _reputation;
101
+ constructor(opts: AgentFuelOptions);
102
+ get agentPubkey(): PublicKey;
103
+ private get creditVault();
104
+ private get reputation();
105
+ private resolveOwner;
106
+ getScore(agent?: Pubkeyish): Promise<ReputationLookup>;
107
+ getVaultBalance(ref?: VaultRef): Promise<CreditVaultAccount>;
108
+ getPolicy(ref?: VaultRef): Promise<SpendPolicyAccount>;
109
+ checkService(serviceAuthority: Pubkeyish): Promise<ServiceRegistryAccount>;
110
+ spend(args: SpendArgs): Promise<SpendResult>;
111
+ onEvent(callback: (frame: LiveEventFrame) => void, options?: OnEventOptions): Subscription;
112
+ }
113
+
114
+ declare const PROGRAM_IDS: {
115
+ readonly reputation: PublicKey;
116
+ readonly creditVault: PublicKey;
117
+ };
118
+
119
+ declare const TOKEN_PROGRAM_ID: PublicKey;
120
+ declare const ASSOCIATED_TOKEN_PROGRAM_ID: PublicKey;
121
+ declare const SLOTS_PER_HOUR = 9000;
122
+ declare function getAssociatedTokenAddress(mint: PublicKey, owner: PublicKey): PublicKey;
123
+ declare function createAssociatedTokenAccountIdempotentInstruction(payer: PublicKey, ata: PublicKey, owner: PublicKey, mint: PublicKey): TransactionInstruction;
124
+
125
+ declare function vaultPda(owner: Pubkeyish, agent: Pubkeyish): PublicKey;
126
+ declare function policyPda(vault: Pubkeyish): PublicKey;
127
+ declare function serviceRegistryPda(serviceAuthority: Pubkeyish): PublicKey;
128
+
129
+ declare class AgentFuelError extends Error {
130
+ constructor(message: string);
131
+ }
132
+ declare class OwnerNotConfiguredError extends AgentFuelError {
133
+ constructor();
134
+ }
135
+ declare class AccountNotFoundError extends AgentFuelError {
136
+ readonly account: string;
137
+ constructor(account: string);
138
+ }
139
+ declare class HttpError extends AgentFuelError {
140
+ readonly status: number;
141
+ readonly url: string;
142
+ readonly body: string | undefined;
143
+ constructor(status: number, url: string, body?: string);
144
+ }
145
+ declare class SpendPolicyError extends AgentFuelError {
146
+ constructor(message: string);
147
+ }
148
+ declare class VaultFrozenError extends SpendPolicyError {
149
+ constructor();
150
+ }
151
+ declare class ZeroAmountError extends SpendPolicyError {
152
+ constructor();
153
+ }
154
+ declare class PerTxLimitExceededError extends SpendPolicyError {
155
+ readonly limit: number;
156
+ readonly amount: number;
157
+ constructor(amount: number, limit: number);
158
+ }
159
+ declare class HourlyLimitExceededError extends SpendPolicyError {
160
+ readonly limit: number;
161
+ readonly windowSpent: number;
162
+ readonly amount: number;
163
+ constructor(amount: number, windowSpent: number, limit: number);
164
+ }
165
+ declare class LifetimeLimitExceededError extends SpendPolicyError {
166
+ readonly limit: number;
167
+ readonly totalSpent: number;
168
+ readonly amount: number;
169
+ constructor(amount: number, totalSpent: number, limit: number);
170
+ }
171
+ declare class NotWhitelistedError extends SpendPolicyError {
172
+ readonly service: string;
173
+ constructor(service: string);
174
+ }
175
+
176
+ type PaymentRequirement = {
177
+ recipient: string;
178
+ amountUsdc: number;
179
+ network?: string;
180
+ resource?: string;
181
+ };
182
+ type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
183
+ type PaymentRequiredOptions = {
184
+ fetch?: FetchLike;
185
+ onPaymentRequired?: (req: PaymentRequirement) => void | Promise<void>;
186
+ onPaid?: (signature: string, req: PaymentRequirement) => void | Promise<void>;
187
+ };
188
+ declare class PaymentParseError extends AgentFuelError {
189
+ constructor(message: string);
190
+ }
191
+ declare function paymentRequired(fuel: AgentFuel, opts?: PaymentRequiredOptions): FetchLike;
192
+
193
+ export { ASSOCIATED_TOKEN_PROGRAM_ID, AccountNotFoundError, AgentFuel, AgentFuelError, type AgentFuelOptions, type Cluster, type CreditVaultAccount, type FetchLike, HourlyLimitExceededError, HttpError, LifetimeLimitExceededError, type LiveEventFrame, type LiveStatus, NotWhitelistedError, type OnEventOptions, OwnerNotConfiguredError, PROGRAM_IDS, PaymentParseError, type PaymentRequiredOptions, type PaymentRequirement, PerTxLimitExceededError, type Pubkeyish, type ReputationLookup, SLOTS_PER_HOUR, type ServiceCategory, type ServiceRegistryAccount, type SpendArgs, type SpendPolicyAccount, SpendPolicyError, type SpendResult, type Subscription, TOKEN_PROGRAM_ID, VaultFrozenError, type VaultRef, ZeroAmountError, createAssociatedTokenAccountIdempotentInstruction, getAssociatedTokenAddress, paymentRequired, policyPda, serviceRegistryPda, vaultPda };