@agent-fuel/sdk 0.1.1 → 0.2.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/CHANGELOG.md +16 -0
- package/dist/idl/credit-vault.cjs +475 -1
- package/dist/idl/credit-vault.cjs.map +1 -1
- package/dist/idl/credit-vault.d.cts +477 -1
- package/dist/idl/credit-vault.d.ts +477 -1
- package/dist/idl/credit-vault.js +475 -1
- package/dist/idl/credit-vault.js.map +1 -1
- package/dist/index.cjs +723 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -1
- package/dist/index.d.ts +87 -1
- package/dist/index.js +722 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -15,6 +15,16 @@ type CreditVaultAccount = {
|
|
|
15
15
|
frozen: boolean;
|
|
16
16
|
created_slot: number;
|
|
17
17
|
last_active_slot: number;
|
|
18
|
+
pending_count: number;
|
|
19
|
+
};
|
|
20
|
+
type PendingSpendAccount = {
|
|
21
|
+
pubkey: PublicKey;
|
|
22
|
+
vault: PublicKey;
|
|
23
|
+
agent: PublicKey;
|
|
24
|
+
service: PublicKey;
|
|
25
|
+
amount_usdc: number;
|
|
26
|
+
nonce: number;
|
|
27
|
+
requested_slot: number;
|
|
18
28
|
};
|
|
19
29
|
type SpendPolicyAccount = {
|
|
20
30
|
pubkey: PublicKey;
|
|
@@ -66,6 +76,70 @@ type ReputationLookup = {
|
|
|
66
76
|
updated_at: string;
|
|
67
77
|
};
|
|
68
78
|
|
|
79
|
+
type PayArgs = {
|
|
80
|
+
/** Agent keypair — spends from the vault and pays tx fees. */
|
|
81
|
+
agent: Keypair;
|
|
82
|
+
/** Service keypair — co-signs the reputation half. Its pubkey must
|
|
83
|
+
* match the service registered on chain. */
|
|
84
|
+
service: Keypair;
|
|
85
|
+
/** Vault owner. */
|
|
86
|
+
owner: Pubkeyish;
|
|
87
|
+
/** Amount in micro-USDC. */
|
|
88
|
+
amountUsdc: number;
|
|
89
|
+
/** 32-byte receipt hash. Common: `sha256(agent|service|tick|...)`. */
|
|
90
|
+
receiptHash: Uint8Array;
|
|
91
|
+
connection: Connection;
|
|
92
|
+
};
|
|
93
|
+
type PayResult = {
|
|
94
|
+
signature: string;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Atomic spend + record_payment. The vault burn and reputation accrual
|
|
98
|
+
* happen in one transaction — without this, a service could mirror only
|
|
99
|
+
* payments it actually received, but the agent's score wouldn't reflect
|
|
100
|
+
* its own spending. Both sides of the SDK need this primitive to keep
|
|
101
|
+
* reputation honest.
|
|
102
|
+
*/
|
|
103
|
+
declare function pay(args: PayArgs): Promise<PayResult>;
|
|
104
|
+
|
|
105
|
+
type RequestSpendArgs = {
|
|
106
|
+
agent: Keypair;
|
|
107
|
+
owner: Pubkeyish;
|
|
108
|
+
service: Pubkeyish;
|
|
109
|
+
amountUsdc: number;
|
|
110
|
+
connection: Connection;
|
|
111
|
+
};
|
|
112
|
+
type RequestSpendResult = {
|
|
113
|
+
signature: string;
|
|
114
|
+
/** The PendingSpend account the owner approves / cancels and the bot
|
|
115
|
+
* polls for resolution. */
|
|
116
|
+
pendingSpend: PublicKey;
|
|
117
|
+
/** Vault nonce burned by this request. */
|
|
118
|
+
nonce: number;
|
|
119
|
+
};
|
|
120
|
+
declare function requestSpend(args: RequestSpendArgs): Promise<RequestSpendResult>;
|
|
121
|
+
|
|
122
|
+
type RegisterServiceArgs = {
|
|
123
|
+
/** Pays rent for the registry PDA and submits the tx. Typically the
|
|
124
|
+
* same wallet that owns the service brand. */
|
|
125
|
+
sponsor: Keypair;
|
|
126
|
+
/** Long-lived service identity. Co-signs registration to prevent
|
|
127
|
+
* someone else from squatting on the keypair. Must hold ~0.05 SOL
|
|
128
|
+
* for downstream `record_payment` receipt PDAs to be fundable from
|
|
129
|
+
* the service side. */
|
|
130
|
+
service: Keypair;
|
|
131
|
+
name: string;
|
|
132
|
+
category: ServiceCategory;
|
|
133
|
+
/** Off-chain metadata URI (pricing, docs, endpoint). Empty string is
|
|
134
|
+
* allowed; chain just stores zero-padded bytes. */
|
|
135
|
+
serviceUri?: string;
|
|
136
|
+
connection: Connection;
|
|
137
|
+
};
|
|
138
|
+
type RegisterServiceResult = {
|
|
139
|
+
signature: string;
|
|
140
|
+
};
|
|
141
|
+
declare function registerService(args: RegisterServiceArgs): Promise<RegisterServiceResult>;
|
|
142
|
+
|
|
69
143
|
type Cluster = "mainnet-beta" | "devnet" | "testnet" | "localnet";
|
|
70
144
|
type AgentFuelOptions = {
|
|
71
145
|
agent: Keypair;
|
|
@@ -108,6 +182,13 @@ declare class AgentFuel {
|
|
|
108
182
|
getPolicy(ref?: VaultRef): Promise<SpendPolicyAccount>;
|
|
109
183
|
checkService(serviceAuthority: Pubkeyish): Promise<ServiceRegistryAccount>;
|
|
110
184
|
spend(args: SpendArgs): Promise<SpendResult>;
|
|
185
|
+
pay(args: Omit<PayArgs, "connection" | "agent" | "owner"> & {
|
|
186
|
+
owner?: Pubkeyish;
|
|
187
|
+
}): Promise<PayResult>;
|
|
188
|
+
requestSpend(args: Omit<RequestSpendArgs, "connection" | "agent" | "owner"> & {
|
|
189
|
+
owner?: Pubkeyish;
|
|
190
|
+
}): Promise<RequestSpendResult>;
|
|
191
|
+
registerService(args: Omit<RegisterServiceArgs, "connection">): Promise<RegisterServiceResult>;
|
|
111
192
|
computeScore(): Promise<{
|
|
112
193
|
signature: string;
|
|
113
194
|
}>;
|
|
@@ -133,6 +214,11 @@ declare function agentProfilePda(agent: Pubkeyish): PublicKey;
|
|
|
133
214
|
* are the *PDAs* of the agent profile and service registry, not the raw
|
|
134
215
|
* authority pubkeys — match the on-chain Anchor account constraint. */
|
|
135
216
|
declare function agentServiceLinkPda(agentProfile: Pubkeyish, serviceRegistry: Pubkeyish): PublicKey;
|
|
217
|
+
/** PendingSpend PDA — created by `request_spend`, consumed (and closed) by
|
|
218
|
+
* either `approve_spend` (CPIs into `spend`, transfers USDC) or
|
|
219
|
+
* `cancel_spend` (closes without transfer). Nonce is the vault's
|
|
220
|
+
* `pending_count` at request time, so every request gets a fresh PDA. */
|
|
221
|
+
declare function pendingSpendPda(vault: Pubkeyish, nonce: number | bigint): PublicKey;
|
|
136
222
|
/** Existence-as-signal: a `ReceiptUsed` PDA at `[b"receipt", hash]` proves
|
|
137
223
|
* the receipt has been recorded. `record_payment`'s `init` constraint (not
|
|
138
224
|
* `init_if_needed`) means a duplicate hash fails with `AccountAlreadyInUse`,
|
|
@@ -241,4 +327,4 @@ declare class PaymentParseError extends AgentFuelError {
|
|
|
241
327
|
}
|
|
242
328
|
declare function paymentRequired(fuel: AgentFuel, opts?: PaymentRequiredOptions): FetchLike;
|
|
243
329
|
|
|
244
|
-
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, ReceiptAlreadyRecordedError, type RecordPaymentArgs, RecordPaymentError, type RecordPaymentResult, type ReputationLookup, SLOTS_PER_HOUR, type ServiceCategory, ServiceInactiveError, type ServiceRegistryAccount, type SpendArgs, type SpendPolicyAccount, SpendPolicyError, type SpendResult, type SubscribeOptions, type Subscription, TOKEN_PROGRAM_ID, VaultFrozenError, type VaultRef, ZeroAmountError, agentProfilePda, agentServiceLinkPda, createAssociatedTokenAccountIdempotentInstruction, getAssociatedTokenAddress, paymentRequired, policyPda, receiptUsedPda, recordPayment, serviceRegistryPda, subscribeService, subscribeVault, vaultPda };
|
|
330
|
+
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, type PayArgs, type PayResult, PaymentParseError, type PaymentRequiredOptions, type PaymentRequirement, type PendingSpendAccount, PerTxLimitExceededError, type Pubkeyish, ReceiptAlreadyRecordedError, type RecordPaymentArgs, RecordPaymentError, type RecordPaymentResult, type RegisterServiceArgs, type RegisterServiceResult, type ReputationLookup, type RequestSpendArgs, type RequestSpendResult, SLOTS_PER_HOUR, type ServiceCategory, ServiceInactiveError, type ServiceRegistryAccount, type SpendArgs, type SpendPolicyAccount, SpendPolicyError, type SpendResult, type SubscribeOptions, type Subscription, TOKEN_PROGRAM_ID, VaultFrozenError, type VaultRef, ZeroAmountError, agentProfilePda, agentServiceLinkPda, createAssociatedTokenAccountIdempotentInstruction, getAssociatedTokenAddress, pay, paymentRequired, pendingSpendPda, policyPda, receiptUsedPda, recordPayment, registerService, requestSpend, serviceRegistryPda, subscribeService, subscribeVault, vaultPda };
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,16 @@ type CreditVaultAccount = {
|
|
|
15
15
|
frozen: boolean;
|
|
16
16
|
created_slot: number;
|
|
17
17
|
last_active_slot: number;
|
|
18
|
+
pending_count: number;
|
|
19
|
+
};
|
|
20
|
+
type PendingSpendAccount = {
|
|
21
|
+
pubkey: PublicKey;
|
|
22
|
+
vault: PublicKey;
|
|
23
|
+
agent: PublicKey;
|
|
24
|
+
service: PublicKey;
|
|
25
|
+
amount_usdc: number;
|
|
26
|
+
nonce: number;
|
|
27
|
+
requested_slot: number;
|
|
18
28
|
};
|
|
19
29
|
type SpendPolicyAccount = {
|
|
20
30
|
pubkey: PublicKey;
|
|
@@ -66,6 +76,70 @@ type ReputationLookup = {
|
|
|
66
76
|
updated_at: string;
|
|
67
77
|
};
|
|
68
78
|
|
|
79
|
+
type PayArgs = {
|
|
80
|
+
/** Agent keypair — spends from the vault and pays tx fees. */
|
|
81
|
+
agent: Keypair;
|
|
82
|
+
/** Service keypair — co-signs the reputation half. Its pubkey must
|
|
83
|
+
* match the service registered on chain. */
|
|
84
|
+
service: Keypair;
|
|
85
|
+
/** Vault owner. */
|
|
86
|
+
owner: Pubkeyish;
|
|
87
|
+
/** Amount in micro-USDC. */
|
|
88
|
+
amountUsdc: number;
|
|
89
|
+
/** 32-byte receipt hash. Common: `sha256(agent|service|tick|...)`. */
|
|
90
|
+
receiptHash: Uint8Array;
|
|
91
|
+
connection: Connection;
|
|
92
|
+
};
|
|
93
|
+
type PayResult = {
|
|
94
|
+
signature: string;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Atomic spend + record_payment. The vault burn and reputation accrual
|
|
98
|
+
* happen in one transaction — without this, a service could mirror only
|
|
99
|
+
* payments it actually received, but the agent's score wouldn't reflect
|
|
100
|
+
* its own spending. Both sides of the SDK need this primitive to keep
|
|
101
|
+
* reputation honest.
|
|
102
|
+
*/
|
|
103
|
+
declare function pay(args: PayArgs): Promise<PayResult>;
|
|
104
|
+
|
|
105
|
+
type RequestSpendArgs = {
|
|
106
|
+
agent: Keypair;
|
|
107
|
+
owner: Pubkeyish;
|
|
108
|
+
service: Pubkeyish;
|
|
109
|
+
amountUsdc: number;
|
|
110
|
+
connection: Connection;
|
|
111
|
+
};
|
|
112
|
+
type RequestSpendResult = {
|
|
113
|
+
signature: string;
|
|
114
|
+
/** The PendingSpend account the owner approves / cancels and the bot
|
|
115
|
+
* polls for resolution. */
|
|
116
|
+
pendingSpend: PublicKey;
|
|
117
|
+
/** Vault nonce burned by this request. */
|
|
118
|
+
nonce: number;
|
|
119
|
+
};
|
|
120
|
+
declare function requestSpend(args: RequestSpendArgs): Promise<RequestSpendResult>;
|
|
121
|
+
|
|
122
|
+
type RegisterServiceArgs = {
|
|
123
|
+
/** Pays rent for the registry PDA and submits the tx. Typically the
|
|
124
|
+
* same wallet that owns the service brand. */
|
|
125
|
+
sponsor: Keypair;
|
|
126
|
+
/** Long-lived service identity. Co-signs registration to prevent
|
|
127
|
+
* someone else from squatting on the keypair. Must hold ~0.05 SOL
|
|
128
|
+
* for downstream `record_payment` receipt PDAs to be fundable from
|
|
129
|
+
* the service side. */
|
|
130
|
+
service: Keypair;
|
|
131
|
+
name: string;
|
|
132
|
+
category: ServiceCategory;
|
|
133
|
+
/** Off-chain metadata URI (pricing, docs, endpoint). Empty string is
|
|
134
|
+
* allowed; chain just stores zero-padded bytes. */
|
|
135
|
+
serviceUri?: string;
|
|
136
|
+
connection: Connection;
|
|
137
|
+
};
|
|
138
|
+
type RegisterServiceResult = {
|
|
139
|
+
signature: string;
|
|
140
|
+
};
|
|
141
|
+
declare function registerService(args: RegisterServiceArgs): Promise<RegisterServiceResult>;
|
|
142
|
+
|
|
69
143
|
type Cluster = "mainnet-beta" | "devnet" | "testnet" | "localnet";
|
|
70
144
|
type AgentFuelOptions = {
|
|
71
145
|
agent: Keypair;
|
|
@@ -108,6 +182,13 @@ declare class AgentFuel {
|
|
|
108
182
|
getPolicy(ref?: VaultRef): Promise<SpendPolicyAccount>;
|
|
109
183
|
checkService(serviceAuthority: Pubkeyish): Promise<ServiceRegistryAccount>;
|
|
110
184
|
spend(args: SpendArgs): Promise<SpendResult>;
|
|
185
|
+
pay(args: Omit<PayArgs, "connection" | "agent" | "owner"> & {
|
|
186
|
+
owner?: Pubkeyish;
|
|
187
|
+
}): Promise<PayResult>;
|
|
188
|
+
requestSpend(args: Omit<RequestSpendArgs, "connection" | "agent" | "owner"> & {
|
|
189
|
+
owner?: Pubkeyish;
|
|
190
|
+
}): Promise<RequestSpendResult>;
|
|
191
|
+
registerService(args: Omit<RegisterServiceArgs, "connection">): Promise<RegisterServiceResult>;
|
|
111
192
|
computeScore(): Promise<{
|
|
112
193
|
signature: string;
|
|
113
194
|
}>;
|
|
@@ -133,6 +214,11 @@ declare function agentProfilePda(agent: Pubkeyish): PublicKey;
|
|
|
133
214
|
* are the *PDAs* of the agent profile and service registry, not the raw
|
|
134
215
|
* authority pubkeys — match the on-chain Anchor account constraint. */
|
|
135
216
|
declare function agentServiceLinkPda(agentProfile: Pubkeyish, serviceRegistry: Pubkeyish): PublicKey;
|
|
217
|
+
/** PendingSpend PDA — created by `request_spend`, consumed (and closed) by
|
|
218
|
+
* either `approve_spend` (CPIs into `spend`, transfers USDC) or
|
|
219
|
+
* `cancel_spend` (closes without transfer). Nonce is the vault's
|
|
220
|
+
* `pending_count` at request time, so every request gets a fresh PDA. */
|
|
221
|
+
declare function pendingSpendPda(vault: Pubkeyish, nonce: number | bigint): PublicKey;
|
|
136
222
|
/** Existence-as-signal: a `ReceiptUsed` PDA at `[b"receipt", hash]` proves
|
|
137
223
|
* the receipt has been recorded. `record_payment`'s `init` constraint (not
|
|
138
224
|
* `init_if_needed`) means a duplicate hash fails with `AccountAlreadyInUse`,
|
|
@@ -241,4 +327,4 @@ declare class PaymentParseError extends AgentFuelError {
|
|
|
241
327
|
}
|
|
242
328
|
declare function paymentRequired(fuel: AgentFuel, opts?: PaymentRequiredOptions): FetchLike;
|
|
243
329
|
|
|
244
|
-
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, ReceiptAlreadyRecordedError, type RecordPaymentArgs, RecordPaymentError, type RecordPaymentResult, type ReputationLookup, SLOTS_PER_HOUR, type ServiceCategory, ServiceInactiveError, type ServiceRegistryAccount, type SpendArgs, type SpendPolicyAccount, SpendPolicyError, type SpendResult, type SubscribeOptions, type Subscription, TOKEN_PROGRAM_ID, VaultFrozenError, type VaultRef, ZeroAmountError, agentProfilePda, agentServiceLinkPda, createAssociatedTokenAccountIdempotentInstruction, getAssociatedTokenAddress, paymentRequired, policyPda, receiptUsedPda, recordPayment, serviceRegistryPda, subscribeService, subscribeVault, vaultPda };
|
|
330
|
+
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, type PayArgs, type PayResult, PaymentParseError, type PaymentRequiredOptions, type PaymentRequirement, type PendingSpendAccount, PerTxLimitExceededError, type Pubkeyish, ReceiptAlreadyRecordedError, type RecordPaymentArgs, RecordPaymentError, type RecordPaymentResult, type RegisterServiceArgs, type RegisterServiceResult, type ReputationLookup, type RequestSpendArgs, type RequestSpendResult, SLOTS_PER_HOUR, type ServiceCategory, ServiceInactiveError, type ServiceRegistryAccount, type SpendArgs, type SpendPolicyAccount, SpendPolicyError, type SpendResult, type SubscribeOptions, type Subscription, TOKEN_PROGRAM_ID, VaultFrozenError, type VaultRef, ZeroAmountError, agentProfilePda, agentServiceLinkPda, createAssociatedTokenAccountIdempotentInstruction, getAssociatedTokenAddress, pay, paymentRequired, pendingSpendPda, policyPda, receiptUsedPda, recordPayment, registerService, requestSpend, serviceRegistryPda, subscribeService, subscribeVault, vaultPda };
|