@priors/agentkit 0.0.0-stage → 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/README.md +99 -2
- package/dist/constants.d.ts +313 -0
- package/dist/constants.js +44 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +24 -0
- package/dist/priorsActionProvider.d.ts +110 -0
- package/dist/priorsActionProvider.js +516 -0
- package/dist/schemas.d.ts +60 -0
- package/dist/schemas.js +54 -0
- package/package.json +31 -4
package/README.md
CHANGED
|
@@ -1,3 +1,100 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @priors/agentkit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A [Coinbase AgentKit](https://github.com/coinbase/agentkit) action provider for [Priors](https://priors.trade): an
|
|
4
|
+
ERC-8004 agent on Robinhood Chain pays x402 APIs in USDG and, when its wallet is short, borrows the gap from its Priors
|
|
5
|
+
credit line, then repays. Before paying another agent it can read that agent's repayment record.
|
|
6
|
+
|
|
7
|
+
The same provider is proposed to AgentKit itself (`priorsActionProvider` in `@coinbase/agentkit`); this package makes
|
|
8
|
+
it usable with the AgentKit already on npm.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @priors/agentkit @coinbase/agentkit
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Use
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { AgentKit, ViemWalletProvider } from "@coinbase/agentkit";
|
|
20
|
+
import { priorsActionProvider } from "@priors/agentkit";
|
|
21
|
+
import { createWalletClient, defineChain, http } from "viem";
|
|
22
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
23
|
+
|
|
24
|
+
const robinhood = defineChain({
|
|
25
|
+
id: 4663,
|
|
26
|
+
name: "Robinhood Chain",
|
|
27
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
28
|
+
rpcUrls: { default: { http: ["https://rpc.mainnet.chain.robinhood.com"] } },
|
|
29
|
+
});
|
|
30
|
+
const walletProvider = new ViemWalletProvider(
|
|
31
|
+
createWalletClient({ account: privateKeyToAccount(KEY), chain: robinhood, transport: http() }),
|
|
32
|
+
);
|
|
33
|
+
const agentKit = await AgentKit.from({ walletProvider, actionProviders: [priorsActionProvider()] });
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Then hand `agentKit` to your framework as usual (`getVercelAITools(agentKit)`, `getLangChainTools(agentKit)`, ...).
|
|
37
|
+
|
|
38
|
+
**Inference on credit (0.2.0).** Give the provider `autoBorrow`, set by you in code, never by the model:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
priorsActionProvider(undefined, { autoBorrow: { perCall: "5", perDay: "10", hosts: ["agent402.tools"] } })
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
With it, `pay_x402_with_priors_credit` borrows the gap on its own when the wallet is short, for the listed hosts only.
|
|
45
|
+
The limits are `perCall` USDG a call and `perDay` USDG a UTC day in the process, for 14 days (or the pool's maximum
|
|
46
|
+
term). It borrows only while this wallet's Autopay (AutoRepay v2) covers the new loan: the wallet is the agent's
|
|
47
|
+
declared wallet, the plan is on under the agent's current owner, not held or paused, its limit per loan and its USDG
|
|
48
|
+
approval cover the loan's due. Otherwise nothing is borrowed or paid, and the answer says to turn Autopay on. Autopay
|
|
49
|
+
then repays the loan in its window. The model's `maxBorrow` can only lower the amount. A chat completion is one call:
|
|
50
|
+
`url` `https://agent402.tools/v1/chat/completions`, `body` the OpenAI-style request as JSON (sent with POST),
|
|
51
|
+
`maxPrice` `"0.02"`.
|
|
52
|
+
|
|
53
|
+
## Actions
|
|
54
|
+
|
|
55
|
+
| Action | What it does | Moves money |
|
|
56
|
+
|---|---|---|
|
|
57
|
+
| `get_priors_agent_record` | reads an agent's repayment record: loans repaid, late repayments, defaults, score | no |
|
|
58
|
+
| `get_priors_credit_line` | reads an agent's line: size, drawn, available | no |
|
|
59
|
+
| `pay_x402_with_priors_credit` | pays an x402 URL in USDG, at most `maxPrice`, with GET or with POST and a `body`; if the wallet is short, first borrows the gap (at least the pool's minimum loan, 5 USDG today) when `maxBorrow` covers it, or, with `autoBorrow`, on its own within its limits | yes |
|
|
60
|
+
| `borrow_from_priors` | borrows USDG from the agent's line into the wallet | yes |
|
|
61
|
+
| `repay_priors_loan` | repays a loan in full; approves exactly what is due | yes |
|
|
62
|
+
|
|
63
|
+
Only the agent's owner or its registry wallet can borrow against or repay its line. A loan more than three days late
|
|
64
|
+
can be marked defaulted, which ends the agent's record on Priors. The reads use Priors' public API, no key.
|
|
65
|
+
|
|
66
|
+
## Known issue in AgentKit
|
|
67
|
+
|
|
68
|
+
AgentKit sends an analytics event on every action call (to `cca-lite.coinbase.com/amp`). That endpoint answers HTTP
|
|
69
|
+
400 today, and AgentKit's action decorator leaves the rejection unhandled, which ends a Node process on the first
|
|
70
|
+
action call. [coinbase/agentkit#1537](https://github.com/coinbase/agentkit/pull/1537) fixes it. Until it ships, a Node
|
|
71
|
+
host can log that one error instead:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
process.on("unhandledRejection", (e) => {
|
|
75
|
+
if (e instanceof Error && /^HTTP error! status: \d+$/.test(e.message)) return console.warn("AgentKit analytics:", e.message);
|
|
76
|
+
throw e;
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Demo
|
|
81
|
+
|
|
82
|
+

|
|
83
|
+
|
|
84
|
+
A production run on 2026-10-30 (agent #437, Robinhood Chain mainnet; the model calling these actions through
|
|
85
|
+
`@coinbase/agentkit-vercel-ai-sdk`), its own output lines with waits over 6 seconds shortened. The agent reads the
|
|
86
|
+
seller's record (Blockpin, agent #9233), pays its x402 check (0.10 USDG) from an empty wallet by borrowing 5 USDG (loan
|
|
87
|
+
#50884), and repays 5.011666 USDG after its income arrives.
|
|
88
|
+
Transactions: [borrow](https://robinhoodchain.blockscout.com/tx/0x297608c51007480ec8c5aa510d78926d6f14bf58ed467cb797aedc5922884a9e),
|
|
89
|
+
[payment](https://robinhoodchain.blockscout.com/tx/0xbb7fd5dcc13ac547873516713e4940cecadcda76873d980d3ad402de48288c19),
|
|
90
|
+
[repayment](https://robinhoodchain.blockscout.com/tx/0xae5ab2472941bae4ff9d63394247eec90fcf3d2feddd508a4d9e5ebd7ac90c6d).
|
|
91
|
+
|
|
92
|
+
## Test
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npm test # builds, then runs test/*.test.cjs against the published @coinbase/agentkit
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/** Robinhood Chain, where Priors' pool and USDG live. */
|
|
2
|
+
export declare const ROBINHOOD_CHAIN_ID = "4663";
|
|
3
|
+
export declare const ROBINHOOD_NETWORK = "eip155:4663";
|
|
4
|
+
/** Priors' credit pool (CreditPoolV2) on Robinhood Chain. */
|
|
5
|
+
export declare const PRIORS_POOL: "0x281210097f0de7A8FB6F87310AF0f089c9C8DE21";
|
|
6
|
+
/** USDG (Global Dollar) on Robinhood Chain: what lines are drawn and x402 payments settled in. */
|
|
7
|
+
export declare const USDG: "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168";
|
|
8
|
+
export declare const USDG_DECIMALS = 6;
|
|
9
|
+
/** Priors' public read API (records and lines, no key). */
|
|
10
|
+
export declare const PRIORS_API = "https://priors.trade";
|
|
11
|
+
/** Default loan term when borrowing the gap of a payment: 7 days. */
|
|
12
|
+
export declare const DEFAULT_TERM_DAYS = 7;
|
|
13
|
+
/** Auto-borrow's term: 14 days, so a loan Autopay repays in its window (the last hours before due) still counts as
|
|
14
|
+
* seasoned; brought down to the pool's maxTerm. */
|
|
15
|
+
export declare const AUTO_TERM_DAYS = 14;
|
|
16
|
+
/** The ERC-8004 identity registry on Robinhood Chain (the agent's owner and declared wallet). */
|
|
17
|
+
export declare const REGISTRY: "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432";
|
|
18
|
+
/** AutoRepay v2 (Priors' Autopay): repays a loan from the agent's declared wallet in its window. */
|
|
19
|
+
export declare const AUTOREPAY: "0x72B510AF4e66e5960aB9b975e0BdCf80239e83A0";
|
|
20
|
+
export declare const REGISTRY_ABI: readonly [{
|
|
21
|
+
readonly name: "ownerOf";
|
|
22
|
+
readonly type: "function";
|
|
23
|
+
readonly stateMutability: "view";
|
|
24
|
+
readonly inputs: readonly [{
|
|
25
|
+
readonly type: "uint256";
|
|
26
|
+
readonly name: "agentId";
|
|
27
|
+
}];
|
|
28
|
+
readonly outputs: readonly [{
|
|
29
|
+
readonly type: "address";
|
|
30
|
+
}];
|
|
31
|
+
}, {
|
|
32
|
+
readonly name: "getAgentWallet";
|
|
33
|
+
readonly type: "function";
|
|
34
|
+
readonly stateMutability: "view";
|
|
35
|
+
readonly inputs: readonly [{
|
|
36
|
+
readonly type: "uint256";
|
|
37
|
+
readonly name: "agentId";
|
|
38
|
+
}];
|
|
39
|
+
readonly outputs: readonly [{
|
|
40
|
+
readonly type: "address";
|
|
41
|
+
}];
|
|
42
|
+
}];
|
|
43
|
+
export declare const AUTOREPAY_ABI: readonly [{
|
|
44
|
+
readonly name: "planOf";
|
|
45
|
+
readonly type: "function";
|
|
46
|
+
readonly stateMutability: "view";
|
|
47
|
+
readonly inputs: readonly [{
|
|
48
|
+
readonly type: "address";
|
|
49
|
+
readonly name: "wallet";
|
|
50
|
+
}, {
|
|
51
|
+
readonly type: "uint256";
|
|
52
|
+
readonly name: "agentId";
|
|
53
|
+
}];
|
|
54
|
+
readonly outputs: readonly [{
|
|
55
|
+
readonly type: "uint32";
|
|
56
|
+
readonly name: "cap";
|
|
57
|
+
}, {
|
|
58
|
+
readonly type: "address";
|
|
59
|
+
readonly name: "owner";
|
|
60
|
+
}, {
|
|
61
|
+
readonly type: "bool";
|
|
62
|
+
readonly name: "on";
|
|
63
|
+
}, {
|
|
64
|
+
readonly type: "bool";
|
|
65
|
+
readonly name: "useSavings";
|
|
66
|
+
}, {
|
|
67
|
+
readonly type: "bool";
|
|
68
|
+
readonly name: "late";
|
|
69
|
+
}, {
|
|
70
|
+
readonly type: "uint32";
|
|
71
|
+
readonly name: "epoch";
|
|
72
|
+
}];
|
|
73
|
+
}, {
|
|
74
|
+
readonly name: "epochOf";
|
|
75
|
+
readonly type: "function";
|
|
76
|
+
readonly stateMutability: "view";
|
|
77
|
+
readonly inputs: readonly [{
|
|
78
|
+
readonly type: "uint256";
|
|
79
|
+
readonly name: "agentId";
|
|
80
|
+
}];
|
|
81
|
+
readonly outputs: readonly [{
|
|
82
|
+
readonly type: "uint32";
|
|
83
|
+
readonly name: "epoch";
|
|
84
|
+
}, {
|
|
85
|
+
readonly type: "bool";
|
|
86
|
+
readonly name: "stale";
|
|
87
|
+
}];
|
|
88
|
+
}, {
|
|
89
|
+
readonly name: "held";
|
|
90
|
+
readonly type: "function";
|
|
91
|
+
readonly stateMutability: "view";
|
|
92
|
+
readonly inputs: readonly [{
|
|
93
|
+
readonly type: "address";
|
|
94
|
+
readonly name: "who";
|
|
95
|
+
}];
|
|
96
|
+
readonly outputs: readonly [{
|
|
97
|
+
readonly type: "bool";
|
|
98
|
+
}];
|
|
99
|
+
}, {
|
|
100
|
+
readonly name: "pausedUntil";
|
|
101
|
+
readonly type: "function";
|
|
102
|
+
readonly stateMutability: "view";
|
|
103
|
+
readonly inputs: readonly [];
|
|
104
|
+
readonly outputs: readonly [{
|
|
105
|
+
readonly type: "uint64";
|
|
106
|
+
}];
|
|
107
|
+
}];
|
|
108
|
+
export declare const POOL_ABI: readonly [{
|
|
109
|
+
readonly name: "getParams";
|
|
110
|
+
readonly type: "function";
|
|
111
|
+
readonly stateMutability: "view";
|
|
112
|
+
readonly inputs: readonly [];
|
|
113
|
+
readonly outputs: readonly [{
|
|
114
|
+
readonly type: "tuple";
|
|
115
|
+
readonly components: readonly [{
|
|
116
|
+
readonly type: "uint256";
|
|
117
|
+
readonly name: "minLoan";
|
|
118
|
+
}, {
|
|
119
|
+
readonly type: "uint256";
|
|
120
|
+
readonly name: "maxLoan";
|
|
121
|
+
}, {
|
|
122
|
+
readonly type: "uint64";
|
|
123
|
+
readonly name: "minTerm";
|
|
124
|
+
}, {
|
|
125
|
+
readonly type: "uint64";
|
|
126
|
+
readonly name: "maxTerm";
|
|
127
|
+
}, {
|
|
128
|
+
readonly type: "uint64";
|
|
129
|
+
readonly name: "grace";
|
|
130
|
+
}, {
|
|
131
|
+
readonly type: "uint64";
|
|
132
|
+
readonly name: "minScoreTerm";
|
|
133
|
+
}, {
|
|
134
|
+
readonly type: "uint256";
|
|
135
|
+
readonly name: "feeBps";
|
|
136
|
+
}, {
|
|
137
|
+
readonly type: "uint256";
|
|
138
|
+
readonly name: "sponsorFeeBps";
|
|
139
|
+
}, {
|
|
140
|
+
readonly type: "uint256";
|
|
141
|
+
readonly name: "protocolFeeBps";
|
|
142
|
+
}, {
|
|
143
|
+
readonly type: "uint256";
|
|
144
|
+
readonly name: "minStake";
|
|
145
|
+
}, {
|
|
146
|
+
readonly type: "uint256";
|
|
147
|
+
readonly name: "maxUtilizationBps";
|
|
148
|
+
}, {
|
|
149
|
+
readonly type: "uint256";
|
|
150
|
+
readonly name: "keeperBounty";
|
|
151
|
+
}];
|
|
152
|
+
}];
|
|
153
|
+
}, {
|
|
154
|
+
readonly name: "quoteFee";
|
|
155
|
+
readonly type: "function";
|
|
156
|
+
readonly stateMutability: "view";
|
|
157
|
+
readonly inputs: readonly [{
|
|
158
|
+
readonly type: "uint256";
|
|
159
|
+
readonly name: "agentId";
|
|
160
|
+
}, {
|
|
161
|
+
readonly type: "uint256";
|
|
162
|
+
readonly name: "principal";
|
|
163
|
+
}, {
|
|
164
|
+
readonly type: "uint64";
|
|
165
|
+
readonly name: "term";
|
|
166
|
+
}];
|
|
167
|
+
readonly outputs: readonly [{
|
|
168
|
+
readonly type: "uint256";
|
|
169
|
+
readonly name: "fee";
|
|
170
|
+
}, {
|
|
171
|
+
readonly type: "uint256";
|
|
172
|
+
readonly name: "sponsorCut";
|
|
173
|
+
}, {
|
|
174
|
+
readonly type: "uint256";
|
|
175
|
+
readonly name: "reserveCut";
|
|
176
|
+
}, {
|
|
177
|
+
readonly type: "uint256";
|
|
178
|
+
readonly name: "premium";
|
|
179
|
+
}];
|
|
180
|
+
}, {
|
|
181
|
+
readonly name: "borrow";
|
|
182
|
+
readonly type: "function";
|
|
183
|
+
readonly stateMutability: "nonpayable";
|
|
184
|
+
readonly inputs: readonly [{
|
|
185
|
+
readonly type: "uint256";
|
|
186
|
+
readonly name: "agentId";
|
|
187
|
+
}, {
|
|
188
|
+
readonly type: "uint256";
|
|
189
|
+
readonly name: "amount";
|
|
190
|
+
}, {
|
|
191
|
+
readonly type: "uint64";
|
|
192
|
+
readonly name: "term";
|
|
193
|
+
}, {
|
|
194
|
+
readonly type: "address";
|
|
195
|
+
readonly name: "to";
|
|
196
|
+
}, {
|
|
197
|
+
readonly type: "uint256";
|
|
198
|
+
readonly name: "maxFee";
|
|
199
|
+
}];
|
|
200
|
+
readonly outputs: readonly [{
|
|
201
|
+
readonly type: "uint256";
|
|
202
|
+
}];
|
|
203
|
+
}, {
|
|
204
|
+
readonly name: "repay";
|
|
205
|
+
readonly type: "function";
|
|
206
|
+
readonly stateMutability: "nonpayable";
|
|
207
|
+
readonly inputs: readonly [{
|
|
208
|
+
readonly type: "uint256";
|
|
209
|
+
readonly name: "loanId";
|
|
210
|
+
}, {
|
|
211
|
+
readonly type: "uint256";
|
|
212
|
+
readonly name: "expectedAgentId";
|
|
213
|
+
}, {
|
|
214
|
+
readonly type: "uint256";
|
|
215
|
+
readonly name: "maxDue";
|
|
216
|
+
}];
|
|
217
|
+
readonly outputs: readonly [];
|
|
218
|
+
}, {
|
|
219
|
+
readonly name: "loansOf";
|
|
220
|
+
readonly type: "function";
|
|
221
|
+
readonly stateMutability: "view";
|
|
222
|
+
readonly inputs: readonly [{
|
|
223
|
+
readonly type: "uint256";
|
|
224
|
+
readonly name: "agentId";
|
|
225
|
+
}];
|
|
226
|
+
readonly outputs: readonly [{
|
|
227
|
+
readonly type: "uint256[]";
|
|
228
|
+
}];
|
|
229
|
+
}, {
|
|
230
|
+
readonly name: "getLoan";
|
|
231
|
+
readonly type: "function";
|
|
232
|
+
readonly stateMutability: "view";
|
|
233
|
+
readonly inputs: readonly [{
|
|
234
|
+
readonly type: "uint256";
|
|
235
|
+
readonly name: "loanId";
|
|
236
|
+
}];
|
|
237
|
+
readonly outputs: readonly [{
|
|
238
|
+
readonly type: "tuple";
|
|
239
|
+
readonly components: readonly [{
|
|
240
|
+
readonly type: "uint256";
|
|
241
|
+
readonly name: "agentId";
|
|
242
|
+
}, {
|
|
243
|
+
readonly type: "uint256";
|
|
244
|
+
readonly name: "sponsorId";
|
|
245
|
+
}, {
|
|
246
|
+
readonly type: "uint256";
|
|
247
|
+
readonly name: "principal";
|
|
248
|
+
}, {
|
|
249
|
+
readonly type: "uint256";
|
|
250
|
+
readonly name: "fee";
|
|
251
|
+
}, {
|
|
252
|
+
readonly type: "uint256";
|
|
253
|
+
readonly name: "sponsorCut";
|
|
254
|
+
}, {
|
|
255
|
+
readonly type: "uint256";
|
|
256
|
+
readonly name: "reserveCut";
|
|
257
|
+
}, {
|
|
258
|
+
readonly type: "uint256";
|
|
259
|
+
readonly name: "premium";
|
|
260
|
+
}, {
|
|
261
|
+
readonly type: "address";
|
|
262
|
+
readonly name: "owner";
|
|
263
|
+
}, {
|
|
264
|
+
readonly type: "uint64";
|
|
265
|
+
readonly name: "issuedAt";
|
|
266
|
+
}, {
|
|
267
|
+
readonly type: "uint64";
|
|
268
|
+
readonly name: "dueAt";
|
|
269
|
+
}, {
|
|
270
|
+
readonly type: "uint64";
|
|
271
|
+
readonly name: "defaultableAt";
|
|
272
|
+
}, {
|
|
273
|
+
readonly type: "uint64";
|
|
274
|
+
readonly name: "minScoreTerm";
|
|
275
|
+
}, {
|
|
276
|
+
readonly type: "uint64";
|
|
277
|
+
readonly name: "closedAt";
|
|
278
|
+
}, {
|
|
279
|
+
readonly type: "uint8";
|
|
280
|
+
readonly name: "status";
|
|
281
|
+
}];
|
|
282
|
+
}];
|
|
283
|
+
}, {
|
|
284
|
+
readonly name: "Borrowed";
|
|
285
|
+
readonly type: "event";
|
|
286
|
+
readonly inputs: readonly [{
|
|
287
|
+
readonly type: "uint256";
|
|
288
|
+
readonly name: "loanId";
|
|
289
|
+
readonly indexed: true;
|
|
290
|
+
}, {
|
|
291
|
+
readonly type: "uint256";
|
|
292
|
+
readonly name: "agentId";
|
|
293
|
+
readonly indexed: true;
|
|
294
|
+
}, {
|
|
295
|
+
readonly type: "uint256";
|
|
296
|
+
readonly name: "sponsorId";
|
|
297
|
+
readonly indexed: true;
|
|
298
|
+
}, {
|
|
299
|
+
readonly type: "uint256";
|
|
300
|
+
readonly name: "principal";
|
|
301
|
+
}, {
|
|
302
|
+
readonly type: "uint256";
|
|
303
|
+
readonly name: "fee";
|
|
304
|
+
}, {
|
|
305
|
+
readonly type: "uint64";
|
|
306
|
+
readonly name: "dueAt";
|
|
307
|
+
}, {
|
|
308
|
+
readonly type: "address";
|
|
309
|
+
readonly name: "to";
|
|
310
|
+
}];
|
|
311
|
+
}];
|
|
312
|
+
/** Loan status 1 is active in CreditPoolV2. */
|
|
313
|
+
export declare const LOAN_ACTIVE = 1;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LOAN_ACTIVE = exports.POOL_ABI = exports.AUTOREPAY_ABI = exports.REGISTRY_ABI = exports.AUTOREPAY = exports.REGISTRY = exports.AUTO_TERM_DAYS = exports.DEFAULT_TERM_DAYS = exports.PRIORS_API = exports.USDG_DECIMALS = exports.USDG = exports.PRIORS_POOL = exports.ROBINHOOD_NETWORK = exports.ROBINHOOD_CHAIN_ID = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
/** Robinhood Chain, where Priors' pool and USDG live. */
|
|
6
|
+
exports.ROBINHOOD_CHAIN_ID = "4663";
|
|
7
|
+
exports.ROBINHOOD_NETWORK = "eip155:4663";
|
|
8
|
+
/** Priors' credit pool (CreditPoolV2) on Robinhood Chain. */
|
|
9
|
+
exports.PRIORS_POOL = "0x281210097f0de7A8FB6F87310AF0f089c9C8DE21";
|
|
10
|
+
/** USDG (Global Dollar) on Robinhood Chain: what lines are drawn and x402 payments settled in. */
|
|
11
|
+
exports.USDG = "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168";
|
|
12
|
+
exports.USDG_DECIMALS = 6;
|
|
13
|
+
/** Priors' public read API (records and lines, no key). */
|
|
14
|
+
exports.PRIORS_API = "https://priors.trade";
|
|
15
|
+
/** Default loan term when borrowing the gap of a payment: 7 days. */
|
|
16
|
+
exports.DEFAULT_TERM_DAYS = 7;
|
|
17
|
+
/** Auto-borrow's term: 14 days, so a loan Autopay repays in its window (the last hours before due) still counts as
|
|
18
|
+
* seasoned; brought down to the pool's maxTerm. */
|
|
19
|
+
exports.AUTO_TERM_DAYS = 14;
|
|
20
|
+
/** The ERC-8004 identity registry on Robinhood Chain (the agent's owner and declared wallet). */
|
|
21
|
+
exports.REGISTRY = "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432";
|
|
22
|
+
/** AutoRepay v2 (Priors' Autopay): repays a loan from the agent's declared wallet in its window. */
|
|
23
|
+
exports.AUTOREPAY = "0x72B510AF4e66e5960aB9b975e0BdCf80239e83A0";
|
|
24
|
+
exports.REGISTRY_ABI = (0, viem_1.parseAbi)([
|
|
25
|
+
"function ownerOf(uint256 agentId) view returns (address)",
|
|
26
|
+
"function getAgentWallet(uint256 agentId) view returns (address)",
|
|
27
|
+
]);
|
|
28
|
+
exports.AUTOREPAY_ABI = (0, viem_1.parseAbi)([
|
|
29
|
+
"function planOf(address wallet, uint256 agentId) view returns (uint32 cap, address owner, bool on, bool useSavings, bool late, uint32 epoch)",
|
|
30
|
+
"function epochOf(uint256 agentId) view returns (uint32 epoch, bool stale)",
|
|
31
|
+
"function held(address who) view returns (bool)",
|
|
32
|
+
"function pausedUntil() view returns (uint64)",
|
|
33
|
+
]);
|
|
34
|
+
exports.POOL_ABI = (0, viem_1.parseAbi)([
|
|
35
|
+
"function getParams() view returns ((uint256 minLoan, uint256 maxLoan, uint64 minTerm, uint64 maxTerm, uint64 grace, uint64 minScoreTerm, uint256 feeBps, uint256 sponsorFeeBps, uint256 protocolFeeBps, uint256 minStake, uint256 maxUtilizationBps, uint256 keeperBounty))",
|
|
36
|
+
"function quoteFee(uint256 agentId, uint256 principal, uint64 term) view returns (uint256 fee, uint256 sponsorCut, uint256 reserveCut, uint256 premium)",
|
|
37
|
+
"function borrow(uint256 agentId, uint256 amount, uint64 term, address to, uint256 maxFee) returns (uint256)",
|
|
38
|
+
"function repay(uint256 loanId, uint256 expectedAgentId, uint256 maxDue)",
|
|
39
|
+
"function loansOf(uint256 agentId) view returns (uint256[])",
|
|
40
|
+
"function getLoan(uint256 loanId) view returns ((uint256 agentId, uint256 sponsorId, uint256 principal, uint256 fee, uint256 sponsorCut, uint256 reserveCut, uint256 premium, address owner, uint64 issuedAt, uint64 dueAt, uint64 defaultableAt, uint64 minScoreTerm, uint64 closedAt, uint8 status))",
|
|
41
|
+
"event Borrowed(uint256 indexed loanId, uint256 indexed agentId, uint256 indexed sponsorId, uint256 principal, uint256 fee, uint64 dueAt, address to)",
|
|
42
|
+
]);
|
|
43
|
+
/** Loan status 1 is active in CreditPoolV2. */
|
|
44
|
+
exports.LOAN_ACTIVE = 1;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ROBINHOOD_NETWORK = exports.ROBINHOOD_CHAIN_ID = exports.USDG = exports.PRIORS_POOL = void 0;
|
|
18
|
+
__exportStar(require("./priorsActionProvider"), exports);
|
|
19
|
+
__exportStar(require("./schemas"), exports);
|
|
20
|
+
var constants_1 = require("./constants");
|
|
21
|
+
Object.defineProperty(exports, "PRIORS_POOL", { enumerable: true, get: function () { return constants_1.PRIORS_POOL; } });
|
|
22
|
+
Object.defineProperty(exports, "USDG", { enumerable: true, get: function () { return constants_1.USDG; } });
|
|
23
|
+
Object.defineProperty(exports, "ROBINHOOD_CHAIN_ID", { enumerable: true, get: function () { return constants_1.ROBINHOOD_CHAIN_ID; } });
|
|
24
|
+
Object.defineProperty(exports, "ROBINHOOD_NETWORK", { enumerable: true, get: function () { return constants_1.ROBINHOOD_NETWORK; } });
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ActionProvider, EvmWalletProvider, Network } from "@coinbase/agentkit";
|
|
3
|
+
import { BorrowSchema, GetAgentRecordSchema, GetCreditLineSchema, PayX402WithCreditSchema, RepaySchema } from "./schemas";
|
|
4
|
+
/**
|
|
5
|
+
* Auto-borrow, set by the owner in code (never by the model): pay_x402_with_priors_credit borrows the gap on its own,
|
|
6
|
+
* up to `perCall` USDG a call and `perDay` USDG a UTC day in this process, for the `hosts` listed only (exact host
|
|
7
|
+
* names), for 14 days, and only while this wallet's Autopay (AutoRepay v2) covers the new loan. The model's maxBorrow
|
|
8
|
+
* can only lower the amount.
|
|
9
|
+
*/
|
|
10
|
+
export type AutoBorrowOptions = {
|
|
11
|
+
perCall: string;
|
|
12
|
+
perDay: string;
|
|
13
|
+
hosts: string[];
|
|
14
|
+
};
|
|
15
|
+
export type PriorsOptions = {
|
|
16
|
+
autoBorrow?: AutoBorrowOptions;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* PriorsActionProvider gives an agent on Robinhood Chain a USDG credit line from Priors: pay an x402 URL and borrow
|
|
20
|
+
* the gap when the wallet is short, borrow and repay, and read another agent's repayment record before paying it.
|
|
21
|
+
*/
|
|
22
|
+
export declare class PriorsActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
23
|
+
private readonly fetchImpl;
|
|
24
|
+
private readonly auto;
|
|
25
|
+
private borrowedToday;
|
|
26
|
+
/**
|
|
27
|
+
* Constructor for the PriorsActionProvider.
|
|
28
|
+
*
|
|
29
|
+
* @param fetchImpl - The fetch used for Priors' API and the x402 URLs (injectable for tests).
|
|
30
|
+
* @param options - `autoBorrow` (off unless given): see AutoBorrowOptions.
|
|
31
|
+
*/
|
|
32
|
+
constructor(fetchImpl?: typeof fetch, options?: PriorsOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Reads an agent's Priors repayment record.
|
|
35
|
+
*
|
|
36
|
+
* @param _walletProvider - The wallet provider (unused: the record is public).
|
|
37
|
+
* @param args - The agent id.
|
|
38
|
+
* @returns The record in plain words, or an error message.
|
|
39
|
+
*/
|
|
40
|
+
getAgentRecord(_walletProvider: EvmWalletProvider, args: z.infer<typeof GetAgentRecordSchema>): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Reads an agent's Priors credit line.
|
|
43
|
+
*
|
|
44
|
+
* @param _walletProvider - The wallet provider (unused: the line is public).
|
|
45
|
+
* @param args - The agent id.
|
|
46
|
+
* @returns The line in plain words, or an error message.
|
|
47
|
+
*/
|
|
48
|
+
getCreditLine(_walletProvider: EvmWalletProvider, args: z.infer<typeof GetCreditLineSchema>): Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Borrows USDG from the agent's Priors line into this wallet.
|
|
51
|
+
*
|
|
52
|
+
* @param walletProvider - The wallet provider: the agent's owner or its registry wallet.
|
|
53
|
+
* @param args - The agent id, the amount and the term.
|
|
54
|
+
* @returns The loan, or an error message.
|
|
55
|
+
*/
|
|
56
|
+
borrow(walletProvider: EvmWalletProvider, args: z.infer<typeof BorrowSchema>): Promise<string>;
|
|
57
|
+
/**
|
|
58
|
+
* Repays a Priors loan in full from this wallet.
|
|
59
|
+
*
|
|
60
|
+
* @param walletProvider - The wallet provider.
|
|
61
|
+
* @param args - The loan id.
|
|
62
|
+
* @returns The repayment, or an error message.
|
|
63
|
+
*/
|
|
64
|
+
repay(walletProvider: EvmWalletProvider, args: z.infer<typeof RepaySchema>): Promise<string>;
|
|
65
|
+
/**
|
|
66
|
+
* Pays an x402 URL in USDG on Robinhood Chain, borrowing the gap from the Priors line when the wallet is short.
|
|
67
|
+
*
|
|
68
|
+
* @param walletProvider - The wallet provider: the agent's owner or its registry wallet.
|
|
69
|
+
* @param args - The URL, the agent id, the most to pay and the most to borrow.
|
|
70
|
+
* @returns What was paid and borrowed and the response, or an error message.
|
|
71
|
+
*/
|
|
72
|
+
payX402WithCredit(walletProvider: EvmWalletProvider, args: z.infer<typeof PayX402WithCreditSchema>): Promise<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Auto-borrow's condition, read before the borrow is sent: this wallet is the agent's declared wallet, its Autopay
|
|
75
|
+
* plan is on and set under the agent's current owner and key, not held or paused, its limit per loan is at least
|
|
76
|
+
* `due`, and its USDG approval to AutoRepay covers `due` on top of the agent's open loans it already repays (those
|
|
77
|
+
* within its limit), as @priors/mcp's check. Throws a Refusal saying what to turn on otherwise.
|
|
78
|
+
*
|
|
79
|
+
* @param walletProvider - The wallet provider.
|
|
80
|
+
* @param agentId - The agent id.
|
|
81
|
+
* @param due - The new loan's principal plus fee, atomic USDG.
|
|
82
|
+
*/
|
|
83
|
+
private autopayCovers;
|
|
84
|
+
/**
|
|
85
|
+
* Checks if the action provider supports the given network: Robinhood Chain only.
|
|
86
|
+
*
|
|
87
|
+
* @param network - The network to check.
|
|
88
|
+
* @returns True on Robinhood Chain (chain id 4663).
|
|
89
|
+
*/
|
|
90
|
+
supportsNetwork: (network: Network) => boolean;
|
|
91
|
+
/**
|
|
92
|
+
* The x402 v2 `exact` requirement for USDG on Robinhood Chain, from the 402's header or body.
|
|
93
|
+
*
|
|
94
|
+
* @param probe - The 402 response.
|
|
95
|
+
* @returns The requirement, or null.
|
|
96
|
+
*/
|
|
97
|
+
private usdgRequirement;
|
|
98
|
+
/**
|
|
99
|
+
* Borrows `amount` atomic USDG for `days` from the agent's line into this wallet.
|
|
100
|
+
*
|
|
101
|
+
* @param walletProvider - The wallet provider.
|
|
102
|
+
* @param agentId - The agent id.
|
|
103
|
+
* @param amount - Atomic USDG.
|
|
104
|
+
* @param days - The term in days.
|
|
105
|
+
* @param check - Called with the quoted fee before the borrow is sent; a throw refuses it.
|
|
106
|
+
* @returns The loan.
|
|
107
|
+
*/
|
|
108
|
+
private borrowAmount;
|
|
109
|
+
}
|
|
110
|
+
export declare const priorsActionProvider: (fetchImpl?: typeof fetch, options?: PriorsOptions) => PriorsActionProvider;
|
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.priorsActionProvider = exports.PriorsActionProvider = void 0;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const viem_1 = require("viem");
|
|
15
|
+
const fetch_1 = require("@x402/fetch");
|
|
16
|
+
const client_1 = require("@x402/evm/exact/client");
|
|
17
|
+
const agentkit_1 = require("@coinbase/agentkit");
|
|
18
|
+
const schemas_1 = require("./schemas");
|
|
19
|
+
const constants_1 = require("./constants");
|
|
20
|
+
const usdg = (atomic) => (0, viem_1.formatUnits)(atomic, constants_1.USDG_DECIMALS);
|
|
21
|
+
const sameAddress = (a, b) => String(a).toLowerCase() === b.toLowerCase();
|
|
22
|
+
const utcDay = () => new Date().toISOString().slice(0, 10);
|
|
23
|
+
/** A refusal before anything is sent (its message is the answer). */
|
|
24
|
+
class Refusal extends Error {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* PriorsActionProvider gives an agent on Robinhood Chain a USDG credit line from Priors: pay an x402 URL and borrow
|
|
28
|
+
* the gap when the wallet is short, borrow and repay, and read another agent's repayment record before paying it.
|
|
29
|
+
*/
|
|
30
|
+
class PriorsActionProvider extends agentkit_1.ActionProvider {
|
|
31
|
+
fetchImpl;
|
|
32
|
+
auto;
|
|
33
|
+
borrowedToday = { day: "", amount: 0n };
|
|
34
|
+
/**
|
|
35
|
+
* Constructor for the PriorsActionProvider.
|
|
36
|
+
*
|
|
37
|
+
* @param fetchImpl - The fetch used for Priors' API and the x402 URLs (injectable for tests).
|
|
38
|
+
* @param options - `autoBorrow` (off unless given): see AutoBorrowOptions.
|
|
39
|
+
*/
|
|
40
|
+
constructor(fetchImpl = (input, init) => globalThis.fetch(input, init), options = {}) {
|
|
41
|
+
super("priors", []);
|
|
42
|
+
this.fetchImpl = fetchImpl;
|
|
43
|
+
const a = options.autoBorrow;
|
|
44
|
+
if (!a) {
|
|
45
|
+
this.auto = null;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const perCall = (0, viem_1.parseUnits)(String(a.perCall), constants_1.USDG_DECIMALS);
|
|
49
|
+
const perDay = (0, viem_1.parseUnits)(String(a.perDay), constants_1.USDG_DECIMALS);
|
|
50
|
+
if (perCall <= 0n)
|
|
51
|
+
throw new Error("autoBorrow.perCall must be above 0");
|
|
52
|
+
if (perDay < perCall)
|
|
53
|
+
throw new Error("autoBorrow.perDay must be at least autoBorrow.perCall");
|
|
54
|
+
const hosts = (a.hosts ?? []).map(h => String(h).trim().toLowerCase());
|
|
55
|
+
if (!hosts.length || hosts.some(h => !/^[a-z0-9.-]+(:\d{1,5})?$/.test(h)))
|
|
56
|
+
throw new Error("autoBorrow.hosts must list the host names it may borrow to pay, e.g. [\"agent402.tools\"]");
|
|
57
|
+
this.auto = { perCall, perDay, hosts: new Set(hosts) };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Reads an agent's Priors repayment record.
|
|
61
|
+
*
|
|
62
|
+
* @param _walletProvider - The wallet provider (unused: the record is public).
|
|
63
|
+
* @param args - The agent id.
|
|
64
|
+
* @returns The record in plain words, or an error message.
|
|
65
|
+
*/
|
|
66
|
+
async getAgentRecord(_walletProvider, args) {
|
|
67
|
+
try {
|
|
68
|
+
const res = await this.fetchImpl(`${constants_1.PRIORS_API}/api/check?agent=${args.agentId}`);
|
|
69
|
+
if (!res.ok)
|
|
70
|
+
return `Error: Priors answered HTTP ${res.status} for agent #${args.agentId}.`;
|
|
71
|
+
const body = (await res.json());
|
|
72
|
+
const a = body.agents?.[0];
|
|
73
|
+
if (!a || !a.record)
|
|
74
|
+
return `Agent #${args.agentId} has no Priors record.`;
|
|
75
|
+
const r = a.record;
|
|
76
|
+
return [
|
|
77
|
+
`Agent #${args.agentId}${a.name ? ` (${a.name})` : ""} on Priors:`,
|
|
78
|
+
`- loans repaid: ${r.loansRepaid ?? 0} (${r.volumeRepaidUsdg ?? 0} USDG), open loans: ${r.activeLoans ?? 0}`,
|
|
79
|
+
`- defaulted: ${r.defaulted ? "yes" : "no"}${r.frozen ? ", frozen" : ""}`,
|
|
80
|
+
`- late repayments: ${a.scoreV2?.lateRepayments ?? 0}, Score v2: ${a.scoreV2?.score ?? "n/a"} (${a.scoreV2?.rungName ?? "n/a"})`,
|
|
81
|
+
`A record shows how the agent repaid loans on Priors, not whether its service is good.`,
|
|
82
|
+
].join("\n");
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
return `Error reading agent #${args.agentId}'s record: ${error}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Reads an agent's Priors credit line.
|
|
90
|
+
*
|
|
91
|
+
* @param _walletProvider - The wallet provider (unused: the line is public).
|
|
92
|
+
* @param args - The agent id.
|
|
93
|
+
* @returns The line in plain words, or an error message.
|
|
94
|
+
*/
|
|
95
|
+
async getCreditLine(_walletProvider, args) {
|
|
96
|
+
try {
|
|
97
|
+
const res = await this.fetchImpl(`${constants_1.PRIORS_API}/api/hub/agent?id=${args.agentId}`);
|
|
98
|
+
if (!res.ok)
|
|
99
|
+
return `Error: Priors answered HTTP ${res.status} for agent #${args.agentId}.`;
|
|
100
|
+
const body = (await res.json());
|
|
101
|
+
const line = body.agent?.line;
|
|
102
|
+
if (!line)
|
|
103
|
+
return `Agent #${args.agentId} has no Priors line.`;
|
|
104
|
+
const fmt = (n) => usdg(BigInt(Math.round(Number(n ?? 0))));
|
|
105
|
+
return `Agent #${args.agentId}'s Priors line: ${fmt(line.limit)} USDG, drawn ${fmt(line.drawn)}, available ${fmt(line.available)}; open loans: ${body.agent?.activeLoans ?? 0}.`;
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
return `Error reading agent #${args.agentId}'s line: ${error}`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Borrows USDG from the agent's Priors line into this wallet.
|
|
113
|
+
*
|
|
114
|
+
* @param walletProvider - The wallet provider: the agent's owner or its registry wallet.
|
|
115
|
+
* @param args - The agent id, the amount and the term.
|
|
116
|
+
* @returns The loan, or an error message.
|
|
117
|
+
*/
|
|
118
|
+
async borrow(walletProvider, args) {
|
|
119
|
+
try {
|
|
120
|
+
const loan = await this.borrowAmount(walletProvider, args.agentId, (0, viem_1.parseUnits)(args.amount, constants_1.USDG_DECIMALS), args.days);
|
|
121
|
+
return `Borrowed ${usdg(loan.amount)} USDG from agent #${args.agentId}'s Priors line: loan #${loan.loanId}, fee ${usdg(loan.fee)} USDG, due ${loan.dueAt}. Transaction: ${loan.hash}`;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
return `Error borrowing from Priors: ${error}`;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Repays a Priors loan in full from this wallet.
|
|
129
|
+
*
|
|
130
|
+
* @param walletProvider - The wallet provider.
|
|
131
|
+
* @param args - The loan id.
|
|
132
|
+
* @returns The repayment, or an error message.
|
|
133
|
+
*/
|
|
134
|
+
async repay(walletProvider, args) {
|
|
135
|
+
try {
|
|
136
|
+
const loan = (await walletProvider.readContract({
|
|
137
|
+
address: constants_1.PRIORS_POOL,
|
|
138
|
+
abi: constants_1.POOL_ABI,
|
|
139
|
+
functionName: "getLoan",
|
|
140
|
+
args: [BigInt(args.loanId)],
|
|
141
|
+
}));
|
|
142
|
+
if (Number(loan.status) !== constants_1.LOAN_ACTIVE)
|
|
143
|
+
return `Error: loan #${args.loanId} is not active.`;
|
|
144
|
+
const due = loan.principal + loan.fee;
|
|
145
|
+
const me = walletProvider.getAddress();
|
|
146
|
+
const balance = (await walletProvider.readContract({
|
|
147
|
+
address: constants_1.USDG,
|
|
148
|
+
abi: viem_1.erc20Abi,
|
|
149
|
+
functionName: "balanceOf",
|
|
150
|
+
args: [me],
|
|
151
|
+
}));
|
|
152
|
+
if (balance < due)
|
|
153
|
+
return `Error: repaying loan #${args.loanId} needs ${usdg(due)} USDG, the wallet holds ${usdg(balance)}.`;
|
|
154
|
+
const allowance = (await walletProvider.readContract({
|
|
155
|
+
address: constants_1.USDG,
|
|
156
|
+
abi: viem_1.erc20Abi,
|
|
157
|
+
functionName: "allowance",
|
|
158
|
+
args: [me, constants_1.PRIORS_POOL],
|
|
159
|
+
}));
|
|
160
|
+
if (allowance < due) {
|
|
161
|
+
const approve = await walletProvider.sendTransaction({
|
|
162
|
+
to: constants_1.USDG,
|
|
163
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
164
|
+
abi: viem_1.erc20Abi,
|
|
165
|
+
functionName: "approve",
|
|
166
|
+
args: [constants_1.PRIORS_POOL, due],
|
|
167
|
+
}),
|
|
168
|
+
});
|
|
169
|
+
await walletProvider.waitForTransactionReceipt(approve);
|
|
170
|
+
}
|
|
171
|
+
const hash = await walletProvider.sendTransaction({
|
|
172
|
+
to: constants_1.PRIORS_POOL,
|
|
173
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
174
|
+
abi: constants_1.POOL_ABI,
|
|
175
|
+
functionName: "repay",
|
|
176
|
+
args: [BigInt(args.loanId), loan.agentId, due],
|
|
177
|
+
}),
|
|
178
|
+
});
|
|
179
|
+
await walletProvider.waitForTransactionReceipt(hash);
|
|
180
|
+
return `Repaid Priors loan #${args.loanId}: ${usdg(due)} USDG. Transaction: ${hash}`;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
return `Error repaying loan #${args.loanId}: ${error}`;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Pays an x402 URL in USDG on Robinhood Chain, borrowing the gap from the Priors line when the wallet is short.
|
|
188
|
+
*
|
|
189
|
+
* @param walletProvider - The wallet provider: the agent's owner or its registry wallet.
|
|
190
|
+
* @param args - The URL, the agent id, the most to pay and the most to borrow.
|
|
191
|
+
* @returns What was paid and borrowed and the response, or an error message.
|
|
192
|
+
*/
|
|
193
|
+
async payX402WithCredit(walletProvider, args) {
|
|
194
|
+
try {
|
|
195
|
+
if (!/^https:\/\//i.test(args.url))
|
|
196
|
+
return "Error: only https URLs are paid.";
|
|
197
|
+
const method = args.method ?? (args.body !== undefined ? "POST" : "GET");
|
|
198
|
+
if (method === "GET" && args.body !== undefined)
|
|
199
|
+
return "Error: a GET request cannot carry a body: use POST.";
|
|
200
|
+
let json = false;
|
|
201
|
+
if (args.body !== undefined) {
|
|
202
|
+
try {
|
|
203
|
+
JSON.parse(args.body);
|
|
204
|
+
json = true;
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
json = false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const init = () => args.body !== undefined
|
|
211
|
+
? { method, body: args.body, headers: { "content-type": json ? "application/json" : "text/plain; charset=utf-8" } }
|
|
212
|
+
: { method };
|
|
213
|
+
const maxPrice = (0, viem_1.parseUnits)(args.maxPrice, constants_1.USDG_DECIMALS);
|
|
214
|
+
// autoBorrow: the owner's amount per call, which the model's maxBorrow can only lower, and only for its hosts
|
|
215
|
+
const auto = this.auto;
|
|
216
|
+
const host = new URL(args.url).host.toLowerCase();
|
|
217
|
+
const autoHere = !!auto && auto.hosts.has(host);
|
|
218
|
+
const named = (0, viem_1.parseUnits)(args.maxBorrow ?? "0", constants_1.USDG_DECIMALS);
|
|
219
|
+
const maxBorrow = !auto
|
|
220
|
+
? named
|
|
221
|
+
: !autoHere
|
|
222
|
+
? 0n
|
|
223
|
+
: args.maxBorrow === undefined || named > auto.perCall
|
|
224
|
+
? auto.perCall
|
|
225
|
+
: named;
|
|
226
|
+
const days = args.days ?? (auto ? constants_1.AUTO_TERM_DAYS : constants_1.DEFAULT_TERM_DAYS);
|
|
227
|
+
const probe = await this.fetchImpl(args.url, init());
|
|
228
|
+
if (probe.status !== 402)
|
|
229
|
+
return `No payment asked (HTTP ${probe.status}):\n${(await probe.text()).slice(0, 2000)}`;
|
|
230
|
+
const requirement = await this.usdgRequirement(probe);
|
|
231
|
+
if (!requirement)
|
|
232
|
+
return "Error: the URL asks for no USDG payment on Robinhood Chain (x402 exact).";
|
|
233
|
+
const price = BigInt(requirement.amount ?? "0");
|
|
234
|
+
if (price > maxPrice)
|
|
235
|
+
return `Error: the URL asks ${usdg(price)} USDG, above maxPrice ${args.maxPrice}. Nothing was paid.`;
|
|
236
|
+
const me = walletProvider.getAddress();
|
|
237
|
+
const balance = (await walletProvider.readContract({
|
|
238
|
+
address: constants_1.USDG,
|
|
239
|
+
abi: viem_1.erc20Abi,
|
|
240
|
+
functionName: "balanceOf",
|
|
241
|
+
args: [me],
|
|
242
|
+
}));
|
|
243
|
+
let borrowed = "";
|
|
244
|
+
if (balance < price) {
|
|
245
|
+
const params = (await walletProvider.readContract({
|
|
246
|
+
address: constants_1.PRIORS_POOL,
|
|
247
|
+
abi: constants_1.POOL_ABI,
|
|
248
|
+
functionName: "getParams",
|
|
249
|
+
}));
|
|
250
|
+
const gap = price - balance;
|
|
251
|
+
const amount = gap > params.minLoan ? gap : params.minLoan;
|
|
252
|
+
if (auto && !autoHere)
|
|
253
|
+
return `Error: the wallet holds ${usdg(balance)} USDG, short of ${usdg(price)}, and auto-borrow borrows only to pay ${[...auto.hosts].join(", ")}. Nothing was borrowed or paid.`;
|
|
254
|
+
if (amount > maxBorrow) {
|
|
255
|
+
return `Error: the wallet holds ${usdg(balance)} USDG, short of ${usdg(price)}; borrowing ${usdg(amount)} (the pool's minimum loan is ${usdg(params.minLoan)}) is above ${auto ? `the most this call may borrow, ${usdg(maxBorrow)}` : `maxBorrow ${args.maxBorrow || "0"}`}. Nothing was paid.`;
|
|
256
|
+
}
|
|
257
|
+
// auto: the day's room is taken here, before any await, so two calls running at once never both pass the
|
|
258
|
+
// limit; it is given back only when the borrow is refused before anything is sent (a borrow sent whose answer
|
|
259
|
+
// was lost stays counted, the safe direction)
|
|
260
|
+
let reserved = null;
|
|
261
|
+
if (auto) {
|
|
262
|
+
const today = utcDay();
|
|
263
|
+
if (this.borrowedToday.day !== today)
|
|
264
|
+
this.borrowedToday = { day: today, amount: 0n };
|
|
265
|
+
if (this.borrowedToday.amount + amount > auto.perDay)
|
|
266
|
+
return `Error: the wallet holds ${usdg(balance)} USDG, short of ${usdg(price)}, and auto-borrow's limit of ${usdg(auto.perDay)} USDG a day has ${usdg(auto.perDay - this.borrowedToday.amount)} left in this process, less than ${usdg(amount)}. Nothing was borrowed or paid.`;
|
|
267
|
+
this.borrowedToday.amount += amount;
|
|
268
|
+
reserved = { day: today, amount };
|
|
269
|
+
}
|
|
270
|
+
// auto: 14 days, brought down to the pool's maxTerm; otherwise the term asked, as before
|
|
271
|
+
const termDays = auto && params.maxTerm !== undefined && BigInt(days) * 86400n > BigInt(params.maxTerm) ? Number(BigInt(params.maxTerm) / 86400n) : days;
|
|
272
|
+
const loan = await this.borrowAmount(walletProvider, args.agentId, amount, termDays, auto ? (fee) => this.autopayCovers(walletProvider, args.agentId, amount + fee) : undefined)
|
|
273
|
+
.catch((error) => {
|
|
274
|
+
if (reserved && error instanceof Refusal && this.borrowedToday.day === reserved.day)
|
|
275
|
+
this.borrowedToday.amount -= reserved.amount;
|
|
276
|
+
throw error;
|
|
277
|
+
});
|
|
278
|
+
borrowed = `Borrowed ${usdg(loan.amount)} USDG first: loan #${loan.loanId}, fee ${usdg(loan.fee)}, due ${loan.dueAt} (transaction ${loan.hash}). ${auto ? "Auto-borrow: Autopay repays it from this wallet in its window, the last hours before it is due; keep its due in the wallet by then." : "Repay it with repay_priors_loan before then."}\n`;
|
|
279
|
+
}
|
|
280
|
+
const client = new fetch_1.x402Client()
|
|
281
|
+
.register(constants_1.ROBINHOOD_NETWORK, new client_1.ExactEvmScheme(walletProvider.toSigner()))
|
|
282
|
+
.registerPolicy((_version, reqs) => reqs.filter(r => r.network === constants_1.ROBINHOOD_NETWORK &&
|
|
283
|
+
sameAddress(r.asset, constants_1.USDG) &&
|
|
284
|
+
BigInt(r.amount ?? "0") <= maxPrice));
|
|
285
|
+
const paid = await (0, fetch_1.wrapFetchWithPayment)(this.fetchImpl, client)(args.url, init());
|
|
286
|
+
const receipt = paid.headers.get("payment-response") || paid.headers.get("x-payment-response");
|
|
287
|
+
return `${borrowed}Paid ${usdg(price)} USDG to ${requirement.payTo} (HTTP ${paid.status})${receipt ? `; settlement: ${receipt.slice(0, 200)}` : ""}.\nResponse:\n${(await paid.text()).slice(0, 2000)}`;
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
if (error instanceof Refusal)
|
|
291
|
+
return `Error: ${error.message}`;
|
|
292
|
+
return `Error paying ${args.url} with Priors credit: ${error}`;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Auto-borrow's condition, read before the borrow is sent: this wallet is the agent's declared wallet, its Autopay
|
|
297
|
+
* plan is on and set under the agent's current owner and key, not held or paused, its limit per loan is at least
|
|
298
|
+
* `due`, and its USDG approval to AutoRepay covers `due` on top of the agent's open loans it already repays (those
|
|
299
|
+
* within its limit), as @priors/mcp's check. Throws a Refusal saying what to turn on otherwise.
|
|
300
|
+
*
|
|
301
|
+
* @param walletProvider - The wallet provider.
|
|
302
|
+
* @param agentId - The agent id.
|
|
303
|
+
* @param due - The new loan's principal plus fee, atomic USDG.
|
|
304
|
+
*/
|
|
305
|
+
async autopayCovers(walletProvider, agentId, due) {
|
|
306
|
+
const me = walletProvider.getAddress();
|
|
307
|
+
const id = BigInt(agentId);
|
|
308
|
+
const read = (address, abi, functionName, args = []) => walletProvider.readContract({ address, abi, functionName, args });
|
|
309
|
+
const [wallet, owner, plan, epoch, held, pausedUntil, allowance] = (await Promise.all([
|
|
310
|
+
read(constants_1.REGISTRY, constants_1.REGISTRY_ABI, "getAgentWallet", [id]),
|
|
311
|
+
read(constants_1.REGISTRY, constants_1.REGISTRY_ABI, "ownerOf", [id]),
|
|
312
|
+
read(constants_1.AUTOREPAY, constants_1.AUTOREPAY_ABI, "planOf", [me, id]),
|
|
313
|
+
read(constants_1.AUTOREPAY, constants_1.AUTOREPAY_ABI, "epochOf", [id]),
|
|
314
|
+
read(constants_1.AUTOREPAY, constants_1.AUTOREPAY_ABI, "held", [me]),
|
|
315
|
+
read(constants_1.AUTOREPAY, constants_1.AUTOREPAY_ABI, "pausedUntil"),
|
|
316
|
+
read(constants_1.USDG, viem_1.erc20Abi, "allowance", [me, constants_1.AUTOREPAY]),
|
|
317
|
+
]));
|
|
318
|
+
const no = (why) => new Refusal(`auto-borrow borrows only when Autopay covers the new loan (${usdg(due)} USDG due), and ${why}. Nothing was borrowed or paid. Turn Autopay on for this wallet with a limit of at least ${usdg(due)} USDG per loan (Go mode, or @priors/mcp's autopay_on).`);
|
|
319
|
+
const [cap, planOwner, on, , , planEpoch] = plan;
|
|
320
|
+
if (!sameAddress(wallet, me))
|
|
321
|
+
throw no(`this wallet is not agent #${agentId}'s declared wallet`);
|
|
322
|
+
if (!on)
|
|
323
|
+
throw no("Autopay is off for this wallet");
|
|
324
|
+
if (!sameAddress(planOwner, owner) || BigInt(planEpoch) !== BigInt(epoch[0]))
|
|
325
|
+
throw no("this wallet's Autopay plan was set under an earlier owner or key of the agent");
|
|
326
|
+
if (held)
|
|
327
|
+
throw no("Autopay is on hold for this wallet");
|
|
328
|
+
if (BigInt(pausedUntil) > BigInt(Math.floor(Date.now() / 1000)))
|
|
329
|
+
throw no("Autopay is paused by the Safe");
|
|
330
|
+
if (BigInt(cap) < due)
|
|
331
|
+
throw no(`Autopay's limit is ${usdg(BigInt(cap))} USDG per loan`);
|
|
332
|
+
// what the agent's open loans already need from that approval: each active loan within the plan's limit
|
|
333
|
+
const ids = (await walletProvider.readContract({ address: constants_1.PRIORS_POOL, abi: constants_1.POOL_ABI, functionName: "loansOf", args: [id] }));
|
|
334
|
+
let owed = 0n;
|
|
335
|
+
for (const loanId of ids) {
|
|
336
|
+
const l = (await walletProvider.readContract({ address: constants_1.PRIORS_POOL, abi: constants_1.POOL_ABI, functionName: "getLoan", args: [loanId] }));
|
|
337
|
+
const loanDue = BigInt(l.principal) + BigInt(l.fee);
|
|
338
|
+
if (Number(l.status) === constants_1.LOAN_ACTIVE && loanDue <= BigInt(cap))
|
|
339
|
+
owed += loanDue;
|
|
340
|
+
}
|
|
341
|
+
if (BigInt(allowance) < owed + due)
|
|
342
|
+
throw no(`Autopay may pull ${usdg(BigInt(allowance))} USDG from this wallet, and its open loans already need ${usdg(owed)} USDG`);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Checks if the action provider supports the given network: Robinhood Chain only.
|
|
346
|
+
*
|
|
347
|
+
* @param network - The network to check.
|
|
348
|
+
* @returns True on Robinhood Chain (chain id 4663).
|
|
349
|
+
*/
|
|
350
|
+
supportsNetwork = (network) => network.protocolFamily === "evm" && String(network.chainId) === constants_1.ROBINHOOD_CHAIN_ID;
|
|
351
|
+
/**
|
|
352
|
+
* The x402 v2 `exact` requirement for USDG on Robinhood Chain, from the 402's header or body.
|
|
353
|
+
*
|
|
354
|
+
* @param probe - The 402 response.
|
|
355
|
+
* @returns The requirement, or null.
|
|
356
|
+
*/
|
|
357
|
+
async usdgRequirement(probe) {
|
|
358
|
+
let accepts = [];
|
|
359
|
+
const header = probe.headers.get("payment-required");
|
|
360
|
+
if (header) {
|
|
361
|
+
try {
|
|
362
|
+
accepts = JSON.parse(Buffer.from(header, "base64").toString("utf8")).accepts ?? [];
|
|
363
|
+
}
|
|
364
|
+
catch {
|
|
365
|
+
accepts = [];
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (!accepts.length) {
|
|
369
|
+
try {
|
|
370
|
+
accepts = (await probe.clone().json()).accepts ?? [];
|
|
371
|
+
}
|
|
372
|
+
catch {
|
|
373
|
+
accepts = [];
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return (accepts.find(r => r.scheme === "exact" &&
|
|
377
|
+
r.network === constants_1.ROBINHOOD_NETWORK &&
|
|
378
|
+
sameAddress(r.asset, constants_1.USDG) &&
|
|
379
|
+
/^\d+$/.test(String(r.amount))) ?? null);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Borrows `amount` atomic USDG for `days` from the agent's line into this wallet.
|
|
383
|
+
*
|
|
384
|
+
* @param walletProvider - The wallet provider.
|
|
385
|
+
* @param agentId - The agent id.
|
|
386
|
+
* @param amount - Atomic USDG.
|
|
387
|
+
* @param days - The term in days.
|
|
388
|
+
* @param check - Called with the quoted fee before the borrow is sent; a throw refuses it.
|
|
389
|
+
* @returns The loan.
|
|
390
|
+
*/
|
|
391
|
+
async borrowAmount(walletProvider, agentId, amount, days, check) {
|
|
392
|
+
const me = walletProvider.getAddress();
|
|
393
|
+
const term = BigInt(days * 86400);
|
|
394
|
+
const [fee] = (await walletProvider.readContract({
|
|
395
|
+
address: constants_1.PRIORS_POOL,
|
|
396
|
+
abi: constants_1.POOL_ABI,
|
|
397
|
+
functionName: "quoteFee",
|
|
398
|
+
args: [BigInt(agentId), amount, term],
|
|
399
|
+
}));
|
|
400
|
+
if (check)
|
|
401
|
+
await check(fee);
|
|
402
|
+
const hash = await walletProvider.sendTransaction({
|
|
403
|
+
to: constants_1.PRIORS_POOL,
|
|
404
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
405
|
+
abi: constants_1.POOL_ABI,
|
|
406
|
+
functionName: "borrow",
|
|
407
|
+
args: [BigInt(agentId), amount, term, me, fee],
|
|
408
|
+
}),
|
|
409
|
+
});
|
|
410
|
+
const receipt = await walletProvider.waitForTransactionReceipt(hash);
|
|
411
|
+
let loanId = "?";
|
|
412
|
+
let dueAt = "?";
|
|
413
|
+
for (const log of (receipt?.logs ?? [])) {
|
|
414
|
+
if (!sameAddress(log.address, constants_1.PRIORS_POOL))
|
|
415
|
+
continue;
|
|
416
|
+
try {
|
|
417
|
+
const ev = (0, viem_1.decodeEventLog)({ abi: constants_1.POOL_ABI, data: log.data, topics: log.topics });
|
|
418
|
+
if (ev.eventName === "Borrowed") {
|
|
419
|
+
loanId = String(ev.args.loanId);
|
|
420
|
+
dueAt = new Date(Number(ev.args.dueAt) * 1000).toISOString();
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
// another event of the pool
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return { amount, fee, hash, loanId, dueAt };
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
exports.PriorsActionProvider = PriorsActionProvider;
|
|
431
|
+
__decorate([
|
|
432
|
+
(0, agentkit_1.CreateAction)({
|
|
433
|
+
name: "get_priors_agent_record",
|
|
434
|
+
description: `
|
|
435
|
+
This tool reads an ERC-8004 agent's repayment record on Priors: loans repaid, late repayments, defaults and score.
|
|
436
|
+
Use it before paying or hiring another agent. It moves no money.
|
|
437
|
+
|
|
438
|
+
Inputs:
|
|
439
|
+
- agentId: the agent's ERC-8004 id on Robinhood Chain.`,
|
|
440
|
+
schema: schemas_1.GetAgentRecordSchema,
|
|
441
|
+
}),
|
|
442
|
+
__metadata("design:type", Function),
|
|
443
|
+
__metadata("design:paramtypes", [agentkit_1.EvmWalletProvider, void 0]),
|
|
444
|
+
__metadata("design:returntype", Promise)
|
|
445
|
+
], PriorsActionProvider.prototype, "getAgentRecord", null);
|
|
446
|
+
__decorate([
|
|
447
|
+
(0, agentkit_1.CreateAction)({
|
|
448
|
+
name: "get_priors_credit_line",
|
|
449
|
+
description: `
|
|
450
|
+
This tool reads an agent's Priors credit line: its size, what is drawn and what is available to borrow. It moves no money.
|
|
451
|
+
|
|
452
|
+
Inputs:
|
|
453
|
+
- agentId: the agent's ERC-8004 id on Robinhood Chain.`,
|
|
454
|
+
schema: schemas_1.GetCreditLineSchema,
|
|
455
|
+
}),
|
|
456
|
+
__metadata("design:type", Function),
|
|
457
|
+
__metadata("design:paramtypes", [agentkit_1.EvmWalletProvider, void 0]),
|
|
458
|
+
__metadata("design:returntype", Promise)
|
|
459
|
+
], PriorsActionProvider.prototype, "getCreditLine", null);
|
|
460
|
+
__decorate([
|
|
461
|
+
(0, agentkit_1.CreateAction)({
|
|
462
|
+
name: "borrow_from_priors",
|
|
463
|
+
description: `
|
|
464
|
+
This tool borrows USDG from the agent's Priors credit line into this wallet, on Robinhood Chain. Real money: the loan
|
|
465
|
+
must be repaid (principal and fee) before its due date, or the agent's record ends in a default.
|
|
466
|
+
|
|
467
|
+
Inputs:
|
|
468
|
+
- agentId: the agent's ERC-8004 id; this wallet must be its owner or its registry wallet.
|
|
469
|
+
- amount: USDG to borrow, e.g. 1.5 (at least the pool's minimum loan).
|
|
470
|
+
- days: the loan term in days (default 7).`,
|
|
471
|
+
schema: schemas_1.BorrowSchema,
|
|
472
|
+
}),
|
|
473
|
+
__metadata("design:type", Function),
|
|
474
|
+
__metadata("design:paramtypes", [agentkit_1.EvmWalletProvider, void 0]),
|
|
475
|
+
__metadata("design:returntype", Promise)
|
|
476
|
+
], PriorsActionProvider.prototype, "borrow", null);
|
|
477
|
+
__decorate([
|
|
478
|
+
(0, agentkit_1.CreateAction)({
|
|
479
|
+
name: "repay_priors_loan",
|
|
480
|
+
description: `
|
|
481
|
+
This tool repays a Priors loan in full (principal and fee) from this wallet's USDG on Robinhood Chain. Real money.
|
|
482
|
+
|
|
483
|
+
Inputs:
|
|
484
|
+
- loanId: the loan to repay.`,
|
|
485
|
+
schema: schemas_1.RepaySchema,
|
|
486
|
+
}),
|
|
487
|
+
__metadata("design:type", Function),
|
|
488
|
+
__metadata("design:paramtypes", [agentkit_1.EvmWalletProvider, void 0]),
|
|
489
|
+
__metadata("design:returntype", Promise)
|
|
490
|
+
], PriorsActionProvider.prototype, "repay", null);
|
|
491
|
+
__decorate([
|
|
492
|
+
(0, agentkit_1.CreateAction)({
|
|
493
|
+
name: "pay_x402_with_priors_credit",
|
|
494
|
+
description: `
|
|
495
|
+
This tool fetches a URL that charges per call with x402 (HTTP 402) and pays it in USDG on Robinhood Chain from this
|
|
496
|
+
wallet, with GET, or with POST and a body (an OpenAI-style chat completion, for one). If the wallet is short of the
|
|
497
|
+
price, it first borrows the gap from the agent's Priors line, only when maxBorrow covers it, or, when the provider was
|
|
498
|
+
set up with autoBorrow, on its own within the owner's limits while Autopay covers the loan. Real money: confirm the URL,
|
|
499
|
+
the price and the most to borrow with the user first.
|
|
500
|
+
|
|
501
|
+
Inputs:
|
|
502
|
+
- url: the https URL.
|
|
503
|
+
- agentId: the agent's ERC-8004 id whose line may be drawn.
|
|
504
|
+
- maxPrice: the most to pay for this call, in USDG (e.g. 0.10).
|
|
505
|
+
- maxBorrow: the most to borrow if the wallet is short, in USDG (default 0: never borrow; with autoBorrow, its amount
|
|
506
|
+
per call, which this can only lower).
|
|
507
|
+
- days: the term of a loan taken for the gap (default 7; 14 with autoBorrow).
|
|
508
|
+
- method, body: POST and its body (default GET with no body).`,
|
|
509
|
+
schema: schemas_1.PayX402WithCreditSchema,
|
|
510
|
+
}),
|
|
511
|
+
__metadata("design:type", Function),
|
|
512
|
+
__metadata("design:paramtypes", [agentkit_1.EvmWalletProvider, void 0]),
|
|
513
|
+
__metadata("design:returntype", Promise)
|
|
514
|
+
], PriorsActionProvider.prototype, "payX402WithCredit", null);
|
|
515
|
+
const priorsActionProvider = (fetchImpl, options) => new PriorsActionProvider(fetchImpl, options);
|
|
516
|
+
exports.priorsActionProvider = priorsActionProvider;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const GetAgentRecordSchema: z.ZodObject<{
|
|
3
|
+
agentId: z.ZodNumber;
|
|
4
|
+
}, "strip", z.ZodTypeAny, {
|
|
5
|
+
agentId: number;
|
|
6
|
+
}, {
|
|
7
|
+
agentId: number;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const GetCreditLineSchema: z.ZodObject<{
|
|
10
|
+
agentId: z.ZodNumber;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
agentId: number;
|
|
13
|
+
}, {
|
|
14
|
+
agentId: number;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const BorrowSchema: z.ZodObject<{
|
|
17
|
+
agentId: z.ZodNumber;
|
|
18
|
+
amount: z.ZodString;
|
|
19
|
+
days: z.ZodDefault<z.ZodNumber>;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
agentId: number;
|
|
22
|
+
amount: string;
|
|
23
|
+
days: number;
|
|
24
|
+
}, {
|
|
25
|
+
agentId: number;
|
|
26
|
+
amount: string;
|
|
27
|
+
days?: number | undefined;
|
|
28
|
+
}>;
|
|
29
|
+
export declare const RepaySchema: z.ZodObject<{
|
|
30
|
+
loanId: z.ZodNumber;
|
|
31
|
+
}, "strip", z.ZodTypeAny, {
|
|
32
|
+
loanId: number;
|
|
33
|
+
}, {
|
|
34
|
+
loanId: number;
|
|
35
|
+
}>;
|
|
36
|
+
export declare const PayX402WithCreditSchema: z.ZodObject<{
|
|
37
|
+
url: z.ZodString;
|
|
38
|
+
agentId: z.ZodNumber;
|
|
39
|
+
maxPrice: z.ZodString;
|
|
40
|
+
maxBorrow: z.ZodOptional<z.ZodString>;
|
|
41
|
+
days: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
method: z.ZodOptional<z.ZodEnum<["GET", "POST"]>>;
|
|
43
|
+
body: z.ZodOptional<z.ZodString>;
|
|
44
|
+
}, "strip", z.ZodTypeAny, {
|
|
45
|
+
agentId: number;
|
|
46
|
+
url: string;
|
|
47
|
+
maxPrice: string;
|
|
48
|
+
days?: number | undefined;
|
|
49
|
+
maxBorrow?: string | undefined;
|
|
50
|
+
method?: "GET" | "POST" | undefined;
|
|
51
|
+
body?: string | undefined;
|
|
52
|
+
}, {
|
|
53
|
+
agentId: number;
|
|
54
|
+
url: string;
|
|
55
|
+
maxPrice: string;
|
|
56
|
+
days?: number | undefined;
|
|
57
|
+
maxBorrow?: string | undefined;
|
|
58
|
+
method?: "GET" | "POST" | undefined;
|
|
59
|
+
body?: string | undefined;
|
|
60
|
+
}>;
|
package/dist/schemas.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PayX402WithCreditSchema = exports.RepaySchema = exports.BorrowSchema = exports.GetCreditLineSchema = exports.GetAgentRecordSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const agentId = zod_1.z
|
|
6
|
+
.number()
|
|
7
|
+
.int()
|
|
8
|
+
.positive()
|
|
9
|
+
.describe("The ERC-8004 agent id on Robinhood Chain, e.g. 9233");
|
|
10
|
+
exports.GetAgentRecordSchema = zod_1.z
|
|
11
|
+
.object({ agentId })
|
|
12
|
+
.describe("Read an agent's Priors repayment record before paying or hiring it");
|
|
13
|
+
exports.GetCreditLineSchema = zod_1.z
|
|
14
|
+
.object({ agentId })
|
|
15
|
+
.describe("Read an agent's Priors credit line: its size, what is drawn and available, its open loans");
|
|
16
|
+
exports.BorrowSchema = zod_1.z
|
|
17
|
+
.object({
|
|
18
|
+
agentId,
|
|
19
|
+
amount: zod_1.z.string().describe("Amount of USDG to borrow in human-readable format, e.g. 1.5"),
|
|
20
|
+
days: zod_1.z.number().int().positive().max(90).default(7).describe("Loan term in days (default 7)"),
|
|
21
|
+
})
|
|
22
|
+
.describe("Borrow USDG from the agent's Priors credit line into this wallet");
|
|
23
|
+
exports.RepaySchema = zod_1.z
|
|
24
|
+
.object({
|
|
25
|
+
loanId: zod_1.z.number().int().positive().describe("The Priors loan id to repay, e.g. 50900"),
|
|
26
|
+
})
|
|
27
|
+
.describe("Repay a Priors loan in full (principal and fee) from this wallet");
|
|
28
|
+
exports.PayX402WithCreditSchema = zod_1.z
|
|
29
|
+
.object({
|
|
30
|
+
url: zod_1.z.string().url().describe("The https URL that answers HTTP 402 (x402)"),
|
|
31
|
+
agentId,
|
|
32
|
+
maxPrice: zod_1.z.string().describe("Most to pay for this call, in USDG, e.g. 0.10"),
|
|
33
|
+
maxBorrow: zod_1.z
|
|
34
|
+
.string()
|
|
35
|
+
.optional()
|
|
36
|
+
.describe("Most to borrow from the Priors line if the wallet is short, in USDG; 0 never borrows. Default 0, or, when the provider was given autoBorrow, its amount per call (a value here can only lower it)"),
|
|
37
|
+
days: zod_1.z
|
|
38
|
+
.number()
|
|
39
|
+
.int()
|
|
40
|
+
.positive()
|
|
41
|
+
.max(90)
|
|
42
|
+
.optional()
|
|
43
|
+
.describe("Term of a loan taken for the gap (default 7, or 14 with the provider's autoBorrow)"),
|
|
44
|
+
method: zod_1.z
|
|
45
|
+
.enum(["GET", "POST"])
|
|
46
|
+
.optional()
|
|
47
|
+
.describe("HTTP method (default GET, or POST when a body is given)"),
|
|
48
|
+
body: zod_1.z
|
|
49
|
+
.string()
|
|
50
|
+
.max(100_000)
|
|
51
|
+
.optional()
|
|
52
|
+
.describe("Request body, e.g. an OpenAI-style chat completion request as JSON; sent as application/json when it parses"),
|
|
53
|
+
})
|
|
54
|
+
.describe("Pay an x402 URL in USDG on Robinhood Chain, borrowing the gap from the Priors line if needed");
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@priors/agentkit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Priors action provider for Coinbase AgentKit: pay x402 APIs in USDG on Robinhood Chain and borrow the gap from an ERC-8004 agent's Priors credit line, repay, and read another agent's repayment record before paying it.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Priors <contact@priors.trade>",
|
|
7
|
+
"homepage": "https://priors.trade",
|
|
8
|
+
"repository": { "type": "git", "url": "git+https://github.com/priors-agents/priors.git", "directory": "integrations/agentkit" },
|
|
9
|
+
"keywords": ["agentkit", "coinbase", "priors", "credit", "x402", "usdg", "erc-8004", "robinhood-chain"],
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"files": ["dist", "README.md"],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc -p tsconfig.json",
|
|
15
|
+
"test": "npm run build && node --test test/*.test.cjs",
|
|
16
|
+
"prepack": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@x402/evm": "^2.7.0",
|
|
20
|
+
"@x402/fetch": "^2.7.0",
|
|
21
|
+
"viem": "^2.38.3"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@coinbase/agentkit": ">=0.10.4",
|
|
25
|
+
"zod": "^3.23.8 || ^4.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@coinbase/agentkit": "0.10.4",
|
|
29
|
+
"typescript": "^5.9.0",
|
|
30
|
+
"zod": "^3.25.0"
|
|
31
|
+
},
|
|
32
|
+
"engines": { "node": ">=18" }
|
|
33
|
+
}
|