@priors/agentkit 0.0.0-stage → 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/README.md +84 -2
- package/dist/constants.d.ts +207 -0
- package/dist/constants.js +26 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +24 -0
- package/dist/priorsActionProvider.d.ts +81 -0
- package/dist/priorsActionProvider.js +386 -0
- package/dist/schemas.d.ts +54 -0
- package/dist/schemas.js +45 -0
- package/package.json +31 -4
package/README.md
CHANGED
|
@@ -1,3 +1,85 @@
|
|
|
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
|
+
## Actions
|
|
39
|
+
|
|
40
|
+
| Action | What it does | Moves money |
|
|
41
|
+
|---|---|---|
|
|
42
|
+
| `get_priors_agent_record` | reads an agent's repayment record: loans repaid, late repayments, defaults, score | no |
|
|
43
|
+
| `get_priors_credit_line` | reads an agent's line: size, drawn, available | no |
|
|
44
|
+
| `pay_x402_with_priors_credit` | pays an x402 URL in USDG, at most `maxPrice`; if the wallet is short, first borrows the gap (at least the pool's minimum loan, 5 USDG today) only when `maxBorrow` covers it | yes |
|
|
45
|
+
| `borrow_from_priors` | borrows USDG from the agent's line into the wallet | yes |
|
|
46
|
+
| `repay_priors_loan` | repays a loan in full; approves exactly what is due | yes |
|
|
47
|
+
|
|
48
|
+
Only the agent's owner or its registry wallet can borrow against or repay its line. A loan more than three days late
|
|
49
|
+
can be marked defaulted, which ends the agent's record on Priors. The reads use Priors' public API, no key.
|
|
50
|
+
|
|
51
|
+
## Known issue in AgentKit
|
|
52
|
+
|
|
53
|
+
AgentKit sends an analytics event on every action call (to `cca-lite.coinbase.com/amp`). That endpoint answers HTTP
|
|
54
|
+
400 today, and AgentKit's action decorator leaves the rejection unhandled, which ends a Node process on the first
|
|
55
|
+
action call. [coinbase/agentkit#1537](https://github.com/coinbase/agentkit/pull/1537) fixes it. Until it ships, a Node
|
|
56
|
+
host can log that one error instead:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
process.on("unhandledRejection", (e) => {
|
|
60
|
+
if (e instanceof Error && /^HTTP error! status: \d+$/.test(e.message)) return console.warn("AgentKit analytics:", e.message);
|
|
61
|
+
throw e;
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Demo
|
|
66
|
+
|
|
67
|
+

|
|
68
|
+
|
|
69
|
+
A production run on 2026-10-30 (agent #437, Robinhood Chain mainnet; the model calling these actions through
|
|
70
|
+
`@coinbase/agentkit-vercel-ai-sdk`), its own output lines with waits over 6 seconds shortened. The agent reads the
|
|
71
|
+
seller's record (Blockpin, agent #9233), pays its x402 check (0.10 USDG) from an empty wallet by borrowing 5 USDG (loan
|
|
72
|
+
#50884), and repays 5.011666 USDG after its income arrives.
|
|
73
|
+
Transactions: [borrow](https://robinhoodchain.blockscout.com/tx/0x297608c51007480ec8c5aa510d78926d6f14bf58ed467cb797aedc5922884a9e),
|
|
74
|
+
[payment](https://robinhoodchain.blockscout.com/tx/0xbb7fd5dcc13ac547873516713e4940cecadcda76873d980d3ad402de48288c19),
|
|
75
|
+
[repayment](https://robinhoodchain.blockscout.com/tx/0xae5ab2472941bae4ff9d63394247eec90fcf3d2feddd508a4d9e5ebd7ac90c6d).
|
|
76
|
+
|
|
77
|
+
## Test
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npm test # builds, then runs test/*.test.cjs against the published @coinbase/agentkit
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
MIT
|
|
@@ -0,0 +1,207 @@
|
|
|
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
|
+
export declare const POOL_ABI: readonly [{
|
|
14
|
+
readonly name: "getParams";
|
|
15
|
+
readonly type: "function";
|
|
16
|
+
readonly stateMutability: "view";
|
|
17
|
+
readonly inputs: readonly [];
|
|
18
|
+
readonly outputs: readonly [{
|
|
19
|
+
readonly type: "tuple";
|
|
20
|
+
readonly components: readonly [{
|
|
21
|
+
readonly type: "uint256";
|
|
22
|
+
readonly name: "minLoan";
|
|
23
|
+
}, {
|
|
24
|
+
readonly type: "uint256";
|
|
25
|
+
readonly name: "maxLoan";
|
|
26
|
+
}, {
|
|
27
|
+
readonly type: "uint64";
|
|
28
|
+
readonly name: "minTerm";
|
|
29
|
+
}, {
|
|
30
|
+
readonly type: "uint64";
|
|
31
|
+
readonly name: "maxTerm";
|
|
32
|
+
}, {
|
|
33
|
+
readonly type: "uint64";
|
|
34
|
+
readonly name: "grace";
|
|
35
|
+
}, {
|
|
36
|
+
readonly type: "uint64";
|
|
37
|
+
readonly name: "minScoreTerm";
|
|
38
|
+
}, {
|
|
39
|
+
readonly type: "uint256";
|
|
40
|
+
readonly name: "feeBps";
|
|
41
|
+
}, {
|
|
42
|
+
readonly type: "uint256";
|
|
43
|
+
readonly name: "sponsorFeeBps";
|
|
44
|
+
}, {
|
|
45
|
+
readonly type: "uint256";
|
|
46
|
+
readonly name: "protocolFeeBps";
|
|
47
|
+
}, {
|
|
48
|
+
readonly type: "uint256";
|
|
49
|
+
readonly name: "minStake";
|
|
50
|
+
}, {
|
|
51
|
+
readonly type: "uint256";
|
|
52
|
+
readonly name: "maxUtilizationBps";
|
|
53
|
+
}, {
|
|
54
|
+
readonly type: "uint256";
|
|
55
|
+
readonly name: "keeperBounty";
|
|
56
|
+
}];
|
|
57
|
+
}];
|
|
58
|
+
}, {
|
|
59
|
+
readonly name: "quoteFee";
|
|
60
|
+
readonly type: "function";
|
|
61
|
+
readonly stateMutability: "view";
|
|
62
|
+
readonly inputs: readonly [{
|
|
63
|
+
readonly type: "uint256";
|
|
64
|
+
readonly name: "agentId";
|
|
65
|
+
}, {
|
|
66
|
+
readonly type: "uint256";
|
|
67
|
+
readonly name: "principal";
|
|
68
|
+
}, {
|
|
69
|
+
readonly type: "uint64";
|
|
70
|
+
readonly name: "term";
|
|
71
|
+
}];
|
|
72
|
+
readonly outputs: readonly [{
|
|
73
|
+
readonly type: "uint256";
|
|
74
|
+
readonly name: "fee";
|
|
75
|
+
}, {
|
|
76
|
+
readonly type: "uint256";
|
|
77
|
+
readonly name: "sponsorCut";
|
|
78
|
+
}, {
|
|
79
|
+
readonly type: "uint256";
|
|
80
|
+
readonly name: "reserveCut";
|
|
81
|
+
}, {
|
|
82
|
+
readonly type: "uint256";
|
|
83
|
+
readonly name: "premium";
|
|
84
|
+
}];
|
|
85
|
+
}, {
|
|
86
|
+
readonly name: "borrow";
|
|
87
|
+
readonly type: "function";
|
|
88
|
+
readonly stateMutability: "nonpayable";
|
|
89
|
+
readonly inputs: readonly [{
|
|
90
|
+
readonly type: "uint256";
|
|
91
|
+
readonly name: "agentId";
|
|
92
|
+
}, {
|
|
93
|
+
readonly type: "uint256";
|
|
94
|
+
readonly name: "amount";
|
|
95
|
+
}, {
|
|
96
|
+
readonly type: "uint64";
|
|
97
|
+
readonly name: "term";
|
|
98
|
+
}, {
|
|
99
|
+
readonly type: "address";
|
|
100
|
+
readonly name: "to";
|
|
101
|
+
}, {
|
|
102
|
+
readonly type: "uint256";
|
|
103
|
+
readonly name: "maxFee";
|
|
104
|
+
}];
|
|
105
|
+
readonly outputs: readonly [{
|
|
106
|
+
readonly type: "uint256";
|
|
107
|
+
}];
|
|
108
|
+
}, {
|
|
109
|
+
readonly name: "repay";
|
|
110
|
+
readonly type: "function";
|
|
111
|
+
readonly stateMutability: "nonpayable";
|
|
112
|
+
readonly inputs: readonly [{
|
|
113
|
+
readonly type: "uint256";
|
|
114
|
+
readonly name: "loanId";
|
|
115
|
+
}, {
|
|
116
|
+
readonly type: "uint256";
|
|
117
|
+
readonly name: "expectedAgentId";
|
|
118
|
+
}, {
|
|
119
|
+
readonly type: "uint256";
|
|
120
|
+
readonly name: "maxDue";
|
|
121
|
+
}];
|
|
122
|
+
readonly outputs: readonly [];
|
|
123
|
+
}, {
|
|
124
|
+
readonly name: "getLoan";
|
|
125
|
+
readonly type: "function";
|
|
126
|
+
readonly stateMutability: "view";
|
|
127
|
+
readonly inputs: readonly [{
|
|
128
|
+
readonly type: "uint256";
|
|
129
|
+
readonly name: "loanId";
|
|
130
|
+
}];
|
|
131
|
+
readonly outputs: readonly [{
|
|
132
|
+
readonly type: "tuple";
|
|
133
|
+
readonly components: readonly [{
|
|
134
|
+
readonly type: "uint256";
|
|
135
|
+
readonly name: "agentId";
|
|
136
|
+
}, {
|
|
137
|
+
readonly type: "uint256";
|
|
138
|
+
readonly name: "sponsorId";
|
|
139
|
+
}, {
|
|
140
|
+
readonly type: "uint256";
|
|
141
|
+
readonly name: "principal";
|
|
142
|
+
}, {
|
|
143
|
+
readonly type: "uint256";
|
|
144
|
+
readonly name: "fee";
|
|
145
|
+
}, {
|
|
146
|
+
readonly type: "uint256";
|
|
147
|
+
readonly name: "sponsorCut";
|
|
148
|
+
}, {
|
|
149
|
+
readonly type: "uint256";
|
|
150
|
+
readonly name: "reserveCut";
|
|
151
|
+
}, {
|
|
152
|
+
readonly type: "uint256";
|
|
153
|
+
readonly name: "premium";
|
|
154
|
+
}, {
|
|
155
|
+
readonly type: "address";
|
|
156
|
+
readonly name: "owner";
|
|
157
|
+
}, {
|
|
158
|
+
readonly type: "uint64";
|
|
159
|
+
readonly name: "issuedAt";
|
|
160
|
+
}, {
|
|
161
|
+
readonly type: "uint64";
|
|
162
|
+
readonly name: "dueAt";
|
|
163
|
+
}, {
|
|
164
|
+
readonly type: "uint64";
|
|
165
|
+
readonly name: "defaultableAt";
|
|
166
|
+
}, {
|
|
167
|
+
readonly type: "uint64";
|
|
168
|
+
readonly name: "minScoreTerm";
|
|
169
|
+
}, {
|
|
170
|
+
readonly type: "uint64";
|
|
171
|
+
readonly name: "closedAt";
|
|
172
|
+
}, {
|
|
173
|
+
readonly type: "uint8";
|
|
174
|
+
readonly name: "status";
|
|
175
|
+
}];
|
|
176
|
+
}];
|
|
177
|
+
}, {
|
|
178
|
+
readonly name: "Borrowed";
|
|
179
|
+
readonly type: "event";
|
|
180
|
+
readonly inputs: readonly [{
|
|
181
|
+
readonly type: "uint256";
|
|
182
|
+
readonly name: "loanId";
|
|
183
|
+
readonly indexed: true;
|
|
184
|
+
}, {
|
|
185
|
+
readonly type: "uint256";
|
|
186
|
+
readonly name: "agentId";
|
|
187
|
+
readonly indexed: true;
|
|
188
|
+
}, {
|
|
189
|
+
readonly type: "uint256";
|
|
190
|
+
readonly name: "sponsorId";
|
|
191
|
+
readonly indexed: true;
|
|
192
|
+
}, {
|
|
193
|
+
readonly type: "uint256";
|
|
194
|
+
readonly name: "principal";
|
|
195
|
+
}, {
|
|
196
|
+
readonly type: "uint256";
|
|
197
|
+
readonly name: "fee";
|
|
198
|
+
}, {
|
|
199
|
+
readonly type: "uint64";
|
|
200
|
+
readonly name: "dueAt";
|
|
201
|
+
}, {
|
|
202
|
+
readonly type: "address";
|
|
203
|
+
readonly name: "to";
|
|
204
|
+
}];
|
|
205
|
+
}];
|
|
206
|
+
/** Loan status 1 is active in CreditPoolV2. */
|
|
207
|
+
export declare const LOAN_ACTIVE = 1;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LOAN_ACTIVE = exports.POOL_ABI = 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
|
+
exports.POOL_ABI = (0, viem_1.parseAbi)([
|
|
18
|
+
"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))",
|
|
19
|
+
"function quoteFee(uint256 agentId, uint256 principal, uint64 term) view returns (uint256 fee, uint256 sponsorCut, uint256 reserveCut, uint256 premium)",
|
|
20
|
+
"function borrow(uint256 agentId, uint256 amount, uint64 term, address to, uint256 maxFee) returns (uint256)",
|
|
21
|
+
"function repay(uint256 loanId, uint256 expectedAgentId, uint256 maxDue)",
|
|
22
|
+
"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))",
|
|
23
|
+
"event Borrowed(uint256 indexed loanId, uint256 indexed agentId, uint256 indexed sponsorId, uint256 principal, uint256 fee, uint64 dueAt, address to)",
|
|
24
|
+
]);
|
|
25
|
+
/** Loan status 1 is active in CreditPoolV2. */
|
|
26
|
+
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,81 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ActionProvider, EvmWalletProvider, Network } from "@coinbase/agentkit";
|
|
3
|
+
import { BorrowSchema, GetAgentRecordSchema, GetCreditLineSchema, PayX402WithCreditSchema, RepaySchema } from "./schemas";
|
|
4
|
+
/**
|
|
5
|
+
* PriorsActionProvider gives an agent on Robinhood Chain a USDG credit line from Priors: pay an x402 URL and borrow
|
|
6
|
+
* the gap when the wallet is short, borrow and repay, and read another agent's repayment record before paying it.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PriorsActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
9
|
+
private readonly fetchImpl;
|
|
10
|
+
/**
|
|
11
|
+
* Constructor for the PriorsActionProvider.
|
|
12
|
+
*
|
|
13
|
+
* @param fetchImpl - The fetch used for Priors' API and the x402 URLs (injectable for tests).
|
|
14
|
+
*/
|
|
15
|
+
constructor(fetchImpl?: typeof fetch);
|
|
16
|
+
/**
|
|
17
|
+
* Reads an agent's Priors repayment record.
|
|
18
|
+
*
|
|
19
|
+
* @param _walletProvider - The wallet provider (unused: the record is public).
|
|
20
|
+
* @param args - The agent id.
|
|
21
|
+
* @returns The record in plain words, or an error message.
|
|
22
|
+
*/
|
|
23
|
+
getAgentRecord(_walletProvider: EvmWalletProvider, args: z.infer<typeof GetAgentRecordSchema>): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Reads an agent's Priors credit line.
|
|
26
|
+
*
|
|
27
|
+
* @param _walletProvider - The wallet provider (unused: the line is public).
|
|
28
|
+
* @param args - The agent id.
|
|
29
|
+
* @returns The line in plain words, or an error message.
|
|
30
|
+
*/
|
|
31
|
+
getCreditLine(_walletProvider: EvmWalletProvider, args: z.infer<typeof GetCreditLineSchema>): Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Borrows USDG from the agent's Priors line into this wallet.
|
|
34
|
+
*
|
|
35
|
+
* @param walletProvider - The wallet provider: the agent's owner or its registry wallet.
|
|
36
|
+
* @param args - The agent id, the amount and the term.
|
|
37
|
+
* @returns The loan, or an error message.
|
|
38
|
+
*/
|
|
39
|
+
borrow(walletProvider: EvmWalletProvider, args: z.infer<typeof BorrowSchema>): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Repays a Priors loan in full from this wallet.
|
|
42
|
+
*
|
|
43
|
+
* @param walletProvider - The wallet provider.
|
|
44
|
+
* @param args - The loan id.
|
|
45
|
+
* @returns The repayment, or an error message.
|
|
46
|
+
*/
|
|
47
|
+
repay(walletProvider: EvmWalletProvider, args: z.infer<typeof RepaySchema>): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Pays an x402 URL in USDG on Robinhood Chain, borrowing the gap from the Priors line when the wallet is short.
|
|
50
|
+
*
|
|
51
|
+
* @param walletProvider - The wallet provider: the agent's owner or its registry wallet.
|
|
52
|
+
* @param args - The URL, the agent id, the most to pay and the most to borrow.
|
|
53
|
+
* @returns What was paid and borrowed and the response, or an error message.
|
|
54
|
+
*/
|
|
55
|
+
payX402WithCredit(walletProvider: EvmWalletProvider, args: z.infer<typeof PayX402WithCreditSchema>): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Checks if the action provider supports the given network: Robinhood Chain only.
|
|
58
|
+
*
|
|
59
|
+
* @param network - The network to check.
|
|
60
|
+
* @returns True on Robinhood Chain (chain id 4663).
|
|
61
|
+
*/
|
|
62
|
+
supportsNetwork: (network: Network) => boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The x402 v2 `exact` requirement for USDG on Robinhood Chain, from the 402's header or body.
|
|
65
|
+
*
|
|
66
|
+
* @param probe - The 402 response.
|
|
67
|
+
* @returns The requirement, or null.
|
|
68
|
+
*/
|
|
69
|
+
private usdgRequirement;
|
|
70
|
+
/**
|
|
71
|
+
* Borrows `amount` atomic USDG for `days` from the agent's line into this wallet.
|
|
72
|
+
*
|
|
73
|
+
* @param walletProvider - The wallet provider.
|
|
74
|
+
* @param agentId - The agent id.
|
|
75
|
+
* @param amount - Atomic USDG.
|
|
76
|
+
* @param days - The term in days.
|
|
77
|
+
* @returns The loan.
|
|
78
|
+
*/
|
|
79
|
+
private borrowAmount;
|
|
80
|
+
}
|
|
81
|
+
export declare const priorsActionProvider: (fetchImpl?: typeof fetch) => PriorsActionProvider;
|
|
@@ -0,0 +1,386 @@
|
|
|
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
|
+
/**
|
|
23
|
+
* PriorsActionProvider gives an agent on Robinhood Chain a USDG credit line from Priors: pay an x402 URL and borrow
|
|
24
|
+
* the gap when the wallet is short, borrow and repay, and read another agent's repayment record before paying it.
|
|
25
|
+
*/
|
|
26
|
+
class PriorsActionProvider extends agentkit_1.ActionProvider {
|
|
27
|
+
fetchImpl;
|
|
28
|
+
/**
|
|
29
|
+
* Constructor for the PriorsActionProvider.
|
|
30
|
+
*
|
|
31
|
+
* @param fetchImpl - The fetch used for Priors' API and the x402 URLs (injectable for tests).
|
|
32
|
+
*/
|
|
33
|
+
constructor(fetchImpl = (input, init) => globalThis.fetch(input, init)) {
|
|
34
|
+
super("priors", []);
|
|
35
|
+
this.fetchImpl = fetchImpl;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Reads an agent's Priors repayment record.
|
|
39
|
+
*
|
|
40
|
+
* @param _walletProvider - The wallet provider (unused: the record is public).
|
|
41
|
+
* @param args - The agent id.
|
|
42
|
+
* @returns The record in plain words, or an error message.
|
|
43
|
+
*/
|
|
44
|
+
async getAgentRecord(_walletProvider, args) {
|
|
45
|
+
try {
|
|
46
|
+
const res = await this.fetchImpl(`${constants_1.PRIORS_API}/api/check?agent=${args.agentId}`);
|
|
47
|
+
if (!res.ok)
|
|
48
|
+
return `Error: Priors answered HTTP ${res.status} for agent #${args.agentId}.`;
|
|
49
|
+
const body = (await res.json());
|
|
50
|
+
const a = body.agents?.[0];
|
|
51
|
+
if (!a || !a.record)
|
|
52
|
+
return `Agent #${args.agentId} has no Priors record.`;
|
|
53
|
+
const r = a.record;
|
|
54
|
+
return [
|
|
55
|
+
`Agent #${args.agentId}${a.name ? ` (${a.name})` : ""} on Priors:`,
|
|
56
|
+
`- loans repaid: ${r.loansRepaid ?? 0} (${r.volumeRepaidUsdg ?? 0} USDG), open loans: ${r.activeLoans ?? 0}`,
|
|
57
|
+
`- defaulted: ${r.defaulted ? "yes" : "no"}${r.frozen ? ", frozen" : ""}`,
|
|
58
|
+
`- late repayments: ${a.scoreV2?.lateRepayments ?? 0}, Score v2: ${a.scoreV2?.score ?? "n/a"} (${a.scoreV2?.rungName ?? "n/a"})`,
|
|
59
|
+
`A record shows how the agent repaid loans on Priors, not whether its service is good.`,
|
|
60
|
+
].join("\n");
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
return `Error reading agent #${args.agentId}'s record: ${error}`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Reads an agent's Priors credit line.
|
|
68
|
+
*
|
|
69
|
+
* @param _walletProvider - The wallet provider (unused: the line is public).
|
|
70
|
+
* @param args - The agent id.
|
|
71
|
+
* @returns The line in plain words, or an error message.
|
|
72
|
+
*/
|
|
73
|
+
async getCreditLine(_walletProvider, args) {
|
|
74
|
+
try {
|
|
75
|
+
const res = await this.fetchImpl(`${constants_1.PRIORS_API}/api/hub/agent?id=${args.agentId}`);
|
|
76
|
+
if (!res.ok)
|
|
77
|
+
return `Error: Priors answered HTTP ${res.status} for agent #${args.agentId}.`;
|
|
78
|
+
const body = (await res.json());
|
|
79
|
+
const line = body.agent?.line;
|
|
80
|
+
if (!line)
|
|
81
|
+
return `Agent #${args.agentId} has no Priors line.`;
|
|
82
|
+
const fmt = (n) => usdg(BigInt(Math.round(Number(n ?? 0))));
|
|
83
|
+
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}.`;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return `Error reading agent #${args.agentId}'s line: ${error}`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Borrows USDG from the agent's Priors line into this wallet.
|
|
91
|
+
*
|
|
92
|
+
* @param walletProvider - The wallet provider: the agent's owner or its registry wallet.
|
|
93
|
+
* @param args - The agent id, the amount and the term.
|
|
94
|
+
* @returns The loan, or an error message.
|
|
95
|
+
*/
|
|
96
|
+
async borrow(walletProvider, args) {
|
|
97
|
+
try {
|
|
98
|
+
const loan = await this.borrowAmount(walletProvider, args.agentId, (0, viem_1.parseUnits)(args.amount, constants_1.USDG_DECIMALS), args.days);
|
|
99
|
+
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}`;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
return `Error borrowing from Priors: ${error}`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Repays a Priors loan in full from this wallet.
|
|
107
|
+
*
|
|
108
|
+
* @param walletProvider - The wallet provider.
|
|
109
|
+
* @param args - The loan id.
|
|
110
|
+
* @returns The repayment, or an error message.
|
|
111
|
+
*/
|
|
112
|
+
async repay(walletProvider, args) {
|
|
113
|
+
try {
|
|
114
|
+
const loan = (await walletProvider.readContract({
|
|
115
|
+
address: constants_1.PRIORS_POOL,
|
|
116
|
+
abi: constants_1.POOL_ABI,
|
|
117
|
+
functionName: "getLoan",
|
|
118
|
+
args: [BigInt(args.loanId)],
|
|
119
|
+
}));
|
|
120
|
+
if (Number(loan.status) !== constants_1.LOAN_ACTIVE)
|
|
121
|
+
return `Error: loan #${args.loanId} is not active.`;
|
|
122
|
+
const due = loan.principal + loan.fee;
|
|
123
|
+
const me = walletProvider.getAddress();
|
|
124
|
+
const balance = (await walletProvider.readContract({
|
|
125
|
+
address: constants_1.USDG,
|
|
126
|
+
abi: viem_1.erc20Abi,
|
|
127
|
+
functionName: "balanceOf",
|
|
128
|
+
args: [me],
|
|
129
|
+
}));
|
|
130
|
+
if (balance < due)
|
|
131
|
+
return `Error: repaying loan #${args.loanId} needs ${usdg(due)} USDG, the wallet holds ${usdg(balance)}.`;
|
|
132
|
+
const allowance = (await walletProvider.readContract({
|
|
133
|
+
address: constants_1.USDG,
|
|
134
|
+
abi: viem_1.erc20Abi,
|
|
135
|
+
functionName: "allowance",
|
|
136
|
+
args: [me, constants_1.PRIORS_POOL],
|
|
137
|
+
}));
|
|
138
|
+
if (allowance < due) {
|
|
139
|
+
const approve = await walletProvider.sendTransaction({
|
|
140
|
+
to: constants_1.USDG,
|
|
141
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
142
|
+
abi: viem_1.erc20Abi,
|
|
143
|
+
functionName: "approve",
|
|
144
|
+
args: [constants_1.PRIORS_POOL, due],
|
|
145
|
+
}),
|
|
146
|
+
});
|
|
147
|
+
await walletProvider.waitForTransactionReceipt(approve);
|
|
148
|
+
}
|
|
149
|
+
const hash = await walletProvider.sendTransaction({
|
|
150
|
+
to: constants_1.PRIORS_POOL,
|
|
151
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
152
|
+
abi: constants_1.POOL_ABI,
|
|
153
|
+
functionName: "repay",
|
|
154
|
+
args: [BigInt(args.loanId), loan.agentId, due],
|
|
155
|
+
}),
|
|
156
|
+
});
|
|
157
|
+
await walletProvider.waitForTransactionReceipt(hash);
|
|
158
|
+
return `Repaid Priors loan #${args.loanId}: ${usdg(due)} USDG. Transaction: ${hash}`;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
return `Error repaying loan #${args.loanId}: ${error}`;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Pays an x402 URL in USDG on Robinhood Chain, borrowing the gap from the Priors line when the wallet is short.
|
|
166
|
+
*
|
|
167
|
+
* @param walletProvider - The wallet provider: the agent's owner or its registry wallet.
|
|
168
|
+
* @param args - The URL, the agent id, the most to pay and the most to borrow.
|
|
169
|
+
* @returns What was paid and borrowed and the response, or an error message.
|
|
170
|
+
*/
|
|
171
|
+
async payX402WithCredit(walletProvider, args) {
|
|
172
|
+
try {
|
|
173
|
+
if (!/^https:\/\//i.test(args.url))
|
|
174
|
+
return "Error: only https URLs are paid.";
|
|
175
|
+
const maxPrice = (0, viem_1.parseUnits)(args.maxPrice, constants_1.USDG_DECIMALS);
|
|
176
|
+
const maxBorrow = (0, viem_1.parseUnits)(args.maxBorrow || "0", constants_1.USDG_DECIMALS);
|
|
177
|
+
const probe = await this.fetchImpl(args.url);
|
|
178
|
+
if (probe.status !== 402)
|
|
179
|
+
return `No payment asked (HTTP ${probe.status}):\n${(await probe.text()).slice(0, 2000)}`;
|
|
180
|
+
const requirement = await this.usdgRequirement(probe);
|
|
181
|
+
if (!requirement)
|
|
182
|
+
return "Error: the URL asks for no USDG payment on Robinhood Chain (x402 exact).";
|
|
183
|
+
const price = BigInt(requirement.amount ?? "0");
|
|
184
|
+
if (price > maxPrice)
|
|
185
|
+
return `Error: the URL asks ${usdg(price)} USDG, above maxPrice ${args.maxPrice}. Nothing was paid.`;
|
|
186
|
+
const me = walletProvider.getAddress();
|
|
187
|
+
const balance = (await walletProvider.readContract({
|
|
188
|
+
address: constants_1.USDG,
|
|
189
|
+
abi: viem_1.erc20Abi,
|
|
190
|
+
functionName: "balanceOf",
|
|
191
|
+
args: [me],
|
|
192
|
+
}));
|
|
193
|
+
let borrowed = "";
|
|
194
|
+
if (balance < price) {
|
|
195
|
+
const params = (await walletProvider.readContract({
|
|
196
|
+
address: constants_1.PRIORS_POOL,
|
|
197
|
+
abi: constants_1.POOL_ABI,
|
|
198
|
+
functionName: "getParams",
|
|
199
|
+
}));
|
|
200
|
+
const gap = price - balance;
|
|
201
|
+
const amount = gap > params.minLoan ? gap : params.minLoan;
|
|
202
|
+
if (amount > maxBorrow) {
|
|
203
|
+
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 maxBorrow ${args.maxBorrow || "0"}. Nothing was paid.`;
|
|
204
|
+
}
|
|
205
|
+
const loan = await this.borrowAmount(walletProvider, args.agentId, amount, args.days);
|
|
206
|
+
borrowed = `Borrowed ${usdg(loan.amount)} USDG first: loan #${loan.loanId}, fee ${usdg(loan.fee)}, due ${loan.dueAt} (transaction ${loan.hash}). Repay it with repay_priors_loan before then.\n`;
|
|
207
|
+
}
|
|
208
|
+
const client = new fetch_1.x402Client()
|
|
209
|
+
.register(constants_1.ROBINHOOD_NETWORK, new client_1.ExactEvmScheme(walletProvider.toSigner()))
|
|
210
|
+
.registerPolicy((_version, reqs) => reqs.filter(r => r.network === constants_1.ROBINHOOD_NETWORK &&
|
|
211
|
+
sameAddress(r.asset, constants_1.USDG) &&
|
|
212
|
+
BigInt(r.amount ?? "0") <= maxPrice));
|
|
213
|
+
const paid = await (0, fetch_1.wrapFetchWithPayment)(this.fetchImpl, client)(args.url);
|
|
214
|
+
const receipt = paid.headers.get("payment-response") || paid.headers.get("x-payment-response");
|
|
215
|
+
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)}`;
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
return `Error paying ${args.url} with Priors credit: ${error}`;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Checks if the action provider supports the given network: Robinhood Chain only.
|
|
223
|
+
*
|
|
224
|
+
* @param network - The network to check.
|
|
225
|
+
* @returns True on Robinhood Chain (chain id 4663).
|
|
226
|
+
*/
|
|
227
|
+
supportsNetwork = (network) => network.protocolFamily === "evm" && String(network.chainId) === constants_1.ROBINHOOD_CHAIN_ID;
|
|
228
|
+
/**
|
|
229
|
+
* The x402 v2 `exact` requirement for USDG on Robinhood Chain, from the 402's header or body.
|
|
230
|
+
*
|
|
231
|
+
* @param probe - The 402 response.
|
|
232
|
+
* @returns The requirement, or null.
|
|
233
|
+
*/
|
|
234
|
+
async usdgRequirement(probe) {
|
|
235
|
+
let accepts = [];
|
|
236
|
+
const header = probe.headers.get("payment-required");
|
|
237
|
+
if (header) {
|
|
238
|
+
try {
|
|
239
|
+
accepts = JSON.parse(Buffer.from(header, "base64").toString("utf8")).accepts ?? [];
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
accepts = [];
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (!accepts.length) {
|
|
246
|
+
try {
|
|
247
|
+
accepts = (await probe.clone().json()).accepts ?? [];
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
accepts = [];
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return (accepts.find(r => r.scheme === "exact" &&
|
|
254
|
+
r.network === constants_1.ROBINHOOD_NETWORK &&
|
|
255
|
+
sameAddress(r.asset, constants_1.USDG) &&
|
|
256
|
+
/^\d+$/.test(String(r.amount))) ?? null);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Borrows `amount` atomic USDG for `days` from the agent's line into this wallet.
|
|
260
|
+
*
|
|
261
|
+
* @param walletProvider - The wallet provider.
|
|
262
|
+
* @param agentId - The agent id.
|
|
263
|
+
* @param amount - Atomic USDG.
|
|
264
|
+
* @param days - The term in days.
|
|
265
|
+
* @returns The loan.
|
|
266
|
+
*/
|
|
267
|
+
async borrowAmount(walletProvider, agentId, amount, days) {
|
|
268
|
+
const me = walletProvider.getAddress();
|
|
269
|
+
const term = BigInt(days * 86400);
|
|
270
|
+
const [fee] = (await walletProvider.readContract({
|
|
271
|
+
address: constants_1.PRIORS_POOL,
|
|
272
|
+
abi: constants_1.POOL_ABI,
|
|
273
|
+
functionName: "quoteFee",
|
|
274
|
+
args: [BigInt(agentId), amount, term],
|
|
275
|
+
}));
|
|
276
|
+
const hash = await walletProvider.sendTransaction({
|
|
277
|
+
to: constants_1.PRIORS_POOL,
|
|
278
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
279
|
+
abi: constants_1.POOL_ABI,
|
|
280
|
+
functionName: "borrow",
|
|
281
|
+
args: [BigInt(agentId), amount, term, me, fee],
|
|
282
|
+
}),
|
|
283
|
+
});
|
|
284
|
+
const receipt = await walletProvider.waitForTransactionReceipt(hash);
|
|
285
|
+
let loanId = "?";
|
|
286
|
+
let dueAt = "?";
|
|
287
|
+
for (const log of (receipt?.logs ?? [])) {
|
|
288
|
+
if (!sameAddress(log.address, constants_1.PRIORS_POOL))
|
|
289
|
+
continue;
|
|
290
|
+
try {
|
|
291
|
+
const ev = (0, viem_1.decodeEventLog)({ abi: constants_1.POOL_ABI, data: log.data, topics: log.topics });
|
|
292
|
+
if (ev.eventName === "Borrowed") {
|
|
293
|
+
loanId = String(ev.args.loanId);
|
|
294
|
+
dueAt = new Date(Number(ev.args.dueAt) * 1000).toISOString();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
// another event of the pool
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return { amount, fee, hash, loanId, dueAt };
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
exports.PriorsActionProvider = PriorsActionProvider;
|
|
305
|
+
__decorate([
|
|
306
|
+
(0, agentkit_1.CreateAction)({
|
|
307
|
+
name: "get_priors_agent_record",
|
|
308
|
+
description: `
|
|
309
|
+
This tool reads an ERC-8004 agent's repayment record on Priors: loans repaid, late repayments, defaults and score.
|
|
310
|
+
Use it before paying or hiring another agent. It moves no money.
|
|
311
|
+
|
|
312
|
+
Inputs:
|
|
313
|
+
- agentId: the agent's ERC-8004 id on Robinhood Chain.`,
|
|
314
|
+
schema: schemas_1.GetAgentRecordSchema,
|
|
315
|
+
}),
|
|
316
|
+
__metadata("design:type", Function),
|
|
317
|
+
__metadata("design:paramtypes", [agentkit_1.EvmWalletProvider, void 0]),
|
|
318
|
+
__metadata("design:returntype", Promise)
|
|
319
|
+
], PriorsActionProvider.prototype, "getAgentRecord", null);
|
|
320
|
+
__decorate([
|
|
321
|
+
(0, agentkit_1.CreateAction)({
|
|
322
|
+
name: "get_priors_credit_line",
|
|
323
|
+
description: `
|
|
324
|
+
This tool reads an agent's Priors credit line: its size, what is drawn and what is available to borrow. It moves no money.
|
|
325
|
+
|
|
326
|
+
Inputs:
|
|
327
|
+
- agentId: the agent's ERC-8004 id on Robinhood Chain.`,
|
|
328
|
+
schema: schemas_1.GetCreditLineSchema,
|
|
329
|
+
}),
|
|
330
|
+
__metadata("design:type", Function),
|
|
331
|
+
__metadata("design:paramtypes", [agentkit_1.EvmWalletProvider, void 0]),
|
|
332
|
+
__metadata("design:returntype", Promise)
|
|
333
|
+
], PriorsActionProvider.prototype, "getCreditLine", null);
|
|
334
|
+
__decorate([
|
|
335
|
+
(0, agentkit_1.CreateAction)({
|
|
336
|
+
name: "borrow_from_priors",
|
|
337
|
+
description: `
|
|
338
|
+
This tool borrows USDG from the agent's Priors credit line into this wallet, on Robinhood Chain. Real money: the loan
|
|
339
|
+
must be repaid (principal and fee) before its due date, or the agent's record ends in a default.
|
|
340
|
+
|
|
341
|
+
Inputs:
|
|
342
|
+
- agentId: the agent's ERC-8004 id; this wallet must be its owner or its registry wallet.
|
|
343
|
+
- amount: USDG to borrow, e.g. 1.5 (at least the pool's minimum loan).
|
|
344
|
+
- days: the loan term in days (default 7).`,
|
|
345
|
+
schema: schemas_1.BorrowSchema,
|
|
346
|
+
}),
|
|
347
|
+
__metadata("design:type", Function),
|
|
348
|
+
__metadata("design:paramtypes", [agentkit_1.EvmWalletProvider, void 0]),
|
|
349
|
+
__metadata("design:returntype", Promise)
|
|
350
|
+
], PriorsActionProvider.prototype, "borrow", null);
|
|
351
|
+
__decorate([
|
|
352
|
+
(0, agentkit_1.CreateAction)({
|
|
353
|
+
name: "repay_priors_loan",
|
|
354
|
+
description: `
|
|
355
|
+
This tool repays a Priors loan in full (principal and fee) from this wallet's USDG on Robinhood Chain. Real money.
|
|
356
|
+
|
|
357
|
+
Inputs:
|
|
358
|
+
- loanId: the loan to repay.`,
|
|
359
|
+
schema: schemas_1.RepaySchema,
|
|
360
|
+
}),
|
|
361
|
+
__metadata("design:type", Function),
|
|
362
|
+
__metadata("design:paramtypes", [agentkit_1.EvmWalletProvider, void 0]),
|
|
363
|
+
__metadata("design:returntype", Promise)
|
|
364
|
+
], PriorsActionProvider.prototype, "repay", null);
|
|
365
|
+
__decorate([
|
|
366
|
+
(0, agentkit_1.CreateAction)({
|
|
367
|
+
name: "pay_x402_with_priors_credit",
|
|
368
|
+
description: `
|
|
369
|
+
This tool fetches a URL that charges per call with x402 (HTTP 402) and pays it in USDG on Robinhood Chain from this
|
|
370
|
+
wallet. If the wallet is short of the price, it first borrows the gap from the agent's Priors line, only when maxBorrow
|
|
371
|
+
covers it. Real money: confirm the URL, the price and the most to borrow with the user first.
|
|
372
|
+
|
|
373
|
+
Inputs:
|
|
374
|
+
- url: the https URL.
|
|
375
|
+
- agentId: the agent's ERC-8004 id whose line may be drawn.
|
|
376
|
+
- maxPrice: the most to pay for this call, in USDG (e.g. 0.10).
|
|
377
|
+
- maxBorrow: the most to borrow if the wallet is short, in USDG (default 0: never borrow).
|
|
378
|
+
- days: the term of a loan taken for the gap (default 7).`,
|
|
379
|
+
schema: schemas_1.PayX402WithCreditSchema,
|
|
380
|
+
}),
|
|
381
|
+
__metadata("design:type", Function),
|
|
382
|
+
__metadata("design:paramtypes", [agentkit_1.EvmWalletProvider, void 0]),
|
|
383
|
+
__metadata("design:returntype", Promise)
|
|
384
|
+
], PriorsActionProvider.prototype, "payX402WithCredit", null);
|
|
385
|
+
const priorsActionProvider = (fetchImpl) => new PriorsActionProvider(fetchImpl);
|
|
386
|
+
exports.priorsActionProvider = priorsActionProvider;
|
|
@@ -0,0 +1,54 @@
|
|
|
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.ZodDefault<z.ZodString>;
|
|
41
|
+
days: z.ZodDefault<z.ZodNumber>;
|
|
42
|
+
}, "strip", z.ZodTypeAny, {
|
|
43
|
+
agentId: number;
|
|
44
|
+
days: number;
|
|
45
|
+
url: string;
|
|
46
|
+
maxPrice: string;
|
|
47
|
+
maxBorrow: string;
|
|
48
|
+
}, {
|
|
49
|
+
agentId: number;
|
|
50
|
+
url: string;
|
|
51
|
+
maxPrice: string;
|
|
52
|
+
days?: number | undefined;
|
|
53
|
+
maxBorrow?: string | undefined;
|
|
54
|
+
}>;
|
package/dist/schemas.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
.default("0")
|
|
36
|
+
.describe("Most to borrow from the Priors line if the wallet is short, in USDG; 0 never borrows"),
|
|
37
|
+
days: zod_1.z
|
|
38
|
+
.number()
|
|
39
|
+
.int()
|
|
40
|
+
.positive()
|
|
41
|
+
.max(90)
|
|
42
|
+
.default(7)
|
|
43
|
+
.describe("Term of a loan taken for the gap (default 7)"),
|
|
44
|
+
})
|
|
45
|
+
.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.1.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
|
+
}
|