@paylobster/mcp-server 1.0.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 +341 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +86 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/index.d.ts +9 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +60 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +240 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/balance.d.ts +6 -0
- package/dist/tools/balance.d.ts.map +1 -0
- package/dist/tools/balance.js +37 -0
- package/dist/tools/balance.js.map +1 -0
- package/dist/tools/escrow.d.ts +91 -0
- package/dist/tools/escrow.d.ts.map +1 -0
- package/dist/tools/escrow.js +244 -0
- package/dist/tools/escrow.js.map +1 -0
- package/dist/tools/reputation.d.ts +51 -0
- package/dist/tools/reputation.d.ts.map +1 -0
- package/dist/tools/reputation.js +125 -0
- package/dist/tools/reputation.js.map +1 -0
- package/dist/tools/search.d.ts +55 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +103 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/types/index.d.ts +73 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/contracts.d.ts +236 -0
- package/dist/utils/contracts.d.ts.map +1 -0
- package/dist/utils/contracts.js +200 -0
- package/dist/utils/contracts.js.map +1 -0
- package/package.json +39 -0
package/dist/server.js
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PayLobsterMCPServer = void 0;
|
|
4
|
+
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
5
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
6
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
7
|
+
const contracts_js_1 = require("./utils/contracts.js");
|
|
8
|
+
const search_js_1 = require("./tools/search.js");
|
|
9
|
+
const escrow_js_1 = require("./tools/escrow.js");
|
|
10
|
+
const reputation_js_1 = require("./tools/reputation.js");
|
|
11
|
+
const balance_js_1 = require("./tools/balance.js");
|
|
12
|
+
const index_js_2 = require("./resources/index.js");
|
|
13
|
+
class PayLobsterMCPServer {
|
|
14
|
+
server;
|
|
15
|
+
client;
|
|
16
|
+
constructor(config) {
|
|
17
|
+
this.client = new contracts_js_1.ContractClient(config);
|
|
18
|
+
this.server = new index_js_1.Server({
|
|
19
|
+
name: '@paylobster/mcp-server',
|
|
20
|
+
version: '1.0.0',
|
|
21
|
+
}, {
|
|
22
|
+
capabilities: {
|
|
23
|
+
tools: {},
|
|
24
|
+
resources: {},
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
this.setupHandlers();
|
|
28
|
+
}
|
|
29
|
+
setupHandlers() {
|
|
30
|
+
// List available tools
|
|
31
|
+
this.server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({
|
|
32
|
+
tools: [
|
|
33
|
+
{
|
|
34
|
+
name: 'search_services',
|
|
35
|
+
description: 'Find PayLobster services by capabilities, category, or price',
|
|
36
|
+
inputSchema: {
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: {
|
|
39
|
+
query: { type: 'string', description: 'Semantic search query' },
|
|
40
|
+
filters: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
properties: {
|
|
43
|
+
category: { type: 'string' },
|
|
44
|
+
capabilities: { type: 'array', items: { type: 'string' } },
|
|
45
|
+
maxPrice: { type: 'string' },
|
|
46
|
+
minReputation: { type: 'number' },
|
|
47
|
+
currency: { type: 'string', default: 'USDC' },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
sort: { type: 'string', enum: ['price', 'reputation', 'relevance'], default: 'relevance' },
|
|
51
|
+
limit: { type: 'number', default: 20 },
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'create_escrow',
|
|
57
|
+
description: 'Create a payment escrow for a service',
|
|
58
|
+
inputSchema: {
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties: {
|
|
61
|
+
to: { type: 'string', description: 'Recipient address' },
|
|
62
|
+
amount: { type: 'string', description: 'Amount in USDC' },
|
|
63
|
+
currency: { type: 'string', default: 'USDC' },
|
|
64
|
+
terms: {
|
|
65
|
+
type: 'object',
|
|
66
|
+
properties: {
|
|
67
|
+
releaseOn: { type: 'string', enum: ['delivery-confirmed', 'timeout', 'manual'] },
|
|
68
|
+
timeout: { type: 'string', description: 'ISO 8601 duration' },
|
|
69
|
+
disputeWindow: { type: 'string', description: 'ISO 8601 duration' },
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
metadata: { type: 'object' },
|
|
73
|
+
},
|
|
74
|
+
required: ['to', 'amount'],
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'release_escrow',
|
|
79
|
+
description: 'Release funds from an escrow',
|
|
80
|
+
inputSchema: {
|
|
81
|
+
type: 'object',
|
|
82
|
+
properties: {
|
|
83
|
+
escrowId: { type: 'string', description: 'Escrow ID' },
|
|
84
|
+
},
|
|
85
|
+
required: ['escrowId'],
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'get_escrow',
|
|
90
|
+
description: 'Get details of a specific escrow',
|
|
91
|
+
inputSchema: {
|
|
92
|
+
type: 'object',
|
|
93
|
+
properties: {
|
|
94
|
+
escrowId: { type: 'string', description: 'Escrow ID' },
|
|
95
|
+
},
|
|
96
|
+
required: ['escrowId'],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: 'list_escrows',
|
|
101
|
+
description: 'List escrows by creator or provider',
|
|
102
|
+
inputSchema: {
|
|
103
|
+
type: 'object',
|
|
104
|
+
properties: {
|
|
105
|
+
creator: { type: 'string', description: 'Filter by creator address' },
|
|
106
|
+
provider: { type: 'string', description: 'Filter by provider address' },
|
|
107
|
+
status: { type: 'string', enum: ['pending', 'active', 'released', 'disputed', 'refunded'] },
|
|
108
|
+
limit: { type: 'number', default: 20 },
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: 'get_reputation',
|
|
114
|
+
description: 'Check an agent\'s reputation score and history',
|
|
115
|
+
inputSchema: {
|
|
116
|
+
type: 'object',
|
|
117
|
+
properties: {
|
|
118
|
+
address: { type: 'string', description: 'Ethereum address' },
|
|
119
|
+
},
|
|
120
|
+
required: ['address'],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: 'register_agent',
|
|
125
|
+
description: 'Register agent identity on PayLobster',
|
|
126
|
+
inputSchema: {
|
|
127
|
+
type: 'object',
|
|
128
|
+
properties: {
|
|
129
|
+
name: { type: 'string', description: 'Agent name' },
|
|
130
|
+
metadata: {
|
|
131
|
+
type: 'object',
|
|
132
|
+
properties: {
|
|
133
|
+
description: { type: 'string' },
|
|
134
|
+
website: { type: 'string' },
|
|
135
|
+
contact: { type: 'string' },
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
stake: { type: 'string', description: 'USDC amount to stake (minimum 100)' },
|
|
139
|
+
},
|
|
140
|
+
required: ['name', 'stake'],
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
name: 'get_balance',
|
|
145
|
+
description: 'Check USDC and credit balance',
|
|
146
|
+
inputSchema: {
|
|
147
|
+
type: 'object',
|
|
148
|
+
properties: {},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
}));
|
|
153
|
+
// Handle tool calls
|
|
154
|
+
this.server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
155
|
+
try {
|
|
156
|
+
switch (request.params.name) {
|
|
157
|
+
case 'search_services': {
|
|
158
|
+
const params = search_js_1.searchServicesSchema.parse(request.params.arguments);
|
|
159
|
+
const result = await (0, search_js_1.searchServices)(params, this.client);
|
|
160
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
161
|
+
}
|
|
162
|
+
case 'create_escrow': {
|
|
163
|
+
const params = escrow_js_1.createEscrowSchema.parse(request.params.arguments);
|
|
164
|
+
const result = await (0, escrow_js_1.createEscrow)(params, this.client);
|
|
165
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
166
|
+
}
|
|
167
|
+
case 'release_escrow': {
|
|
168
|
+
const params = escrow_js_1.releaseEscrowSchema.parse(request.params.arguments);
|
|
169
|
+
const result = await (0, escrow_js_1.releaseEscrow)(params, this.client);
|
|
170
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
171
|
+
}
|
|
172
|
+
case 'get_escrow': {
|
|
173
|
+
const params = escrow_js_1.getEscrowSchema.parse(request.params.arguments);
|
|
174
|
+
const result = await (0, escrow_js_1.getEscrow)(params, this.client);
|
|
175
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
176
|
+
}
|
|
177
|
+
case 'list_escrows': {
|
|
178
|
+
const params = escrow_js_1.listEscrowsSchema.parse(request.params.arguments);
|
|
179
|
+
const result = await (0, escrow_js_1.listEscrows)(params, this.client);
|
|
180
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
181
|
+
}
|
|
182
|
+
case 'get_reputation': {
|
|
183
|
+
const params = reputation_js_1.getReputationSchema.parse(request.params.arguments);
|
|
184
|
+
const result = await (0, reputation_js_1.getReputation)(params, this.client);
|
|
185
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
186
|
+
}
|
|
187
|
+
case 'register_agent': {
|
|
188
|
+
const params = reputation_js_1.registerAgentSchema.parse(request.params.arguments);
|
|
189
|
+
const result = await (0, reputation_js_1.registerAgent)(params, this.client);
|
|
190
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
191
|
+
}
|
|
192
|
+
case 'get_balance': {
|
|
193
|
+
const params = balance_js_1.getBalanceSchema.parse(request.params.arguments);
|
|
194
|
+
const result = await (0, balance_js_1.getBalance)(params, this.client);
|
|
195
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
196
|
+
}
|
|
197
|
+
default:
|
|
198
|
+
throw new Error(`Unknown tool: ${request.params.name}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
203
|
+
return {
|
|
204
|
+
content: [{ type: 'text', text: `Error: ${errorMessage}` }],
|
|
205
|
+
isError: true,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
// List available resources
|
|
210
|
+
this.server.setRequestHandler(types_js_1.ListResourcesRequestSchema, async () => ({
|
|
211
|
+
resources: (0, index_js_2.listResources)(),
|
|
212
|
+
}));
|
|
213
|
+
// Read resource
|
|
214
|
+
this.server.setRequestHandler(types_js_1.ReadResourceRequestSchema, async (request) => {
|
|
215
|
+
try {
|
|
216
|
+
const result = await (0, index_js_2.handleResource)(request.params.uri, this.client);
|
|
217
|
+
return {
|
|
218
|
+
contents: [
|
|
219
|
+
{
|
|
220
|
+
uri: request.params.uri,
|
|
221
|
+
mimeType: 'application/json',
|
|
222
|
+
text: JSON.stringify(result, null, 2),
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
229
|
+
throw new Error(`Failed to read resource: ${errorMessage}`);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
async start() {
|
|
234
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
235
|
+
await this.server.connect(transport);
|
|
236
|
+
console.error('PayLobster MCP server running on stdio');
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
exports.PayLobsterMCPServer = PayLobsterMCPServer;
|
|
240
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;AAAA,wEAAmE;AACnE,wEAAiF;AACjF,iEAK4C;AAC5C,uDAAsD;AAEtD,iDAG2B;AAC3B,iDAS2B;AAC3B,yDAK+B;AAC/B,mDAG4B;AAC5B,mDAAqE;AAErE,MAAa,mBAAmB;IACtB,MAAM,CAAS;IACf,MAAM,CAAiB;IAE/B,YAAY,MAAwB;QAClC,IAAI,CAAC,MAAM,GAAG,IAAI,6BAAc,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,GAAG,IAAI,iBAAM,CACtB;YACE,IAAI,EAAE,wBAAwB;YAC9B,OAAO,EAAE,OAAO;SACjB,EACD;YACE,YAAY,EAAE;gBACZ,KAAK,EAAE,EAAE;gBACT,SAAS,EAAE,EAAE;aACd;SACF,CACF,CAAC;QAEF,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IAEO,aAAa;QACnB,uBAAuB;QACvB,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,iCAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;YACjE,KAAK,EAAE;gBACL;oBACE,IAAI,EAAE,iBAAiB;oBACvB,WAAW,EAAE,8DAA8D;oBAC3E,WAAW,EAAE;wBACX,IAAI,EAAE,QAAQ;wBACd,UAAU,EAAE;4BACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW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CAAC,qCAA0B,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;YACrE,SAAS,EAAE,IAAA,wBAAa,GAAE;SAC3B,CAAC,CAAC,CAAC;QAEJ,gBAAgB;QAChB,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,oCAAyB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACzE,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,IAAA,yBAAc,EAAC,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;gBACrE,OAAO;oBACL,QAAQ,EAAE;wBACR;4BACE,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG;4BACvB,QAAQ,EAAE,kBAAkB;4BAC5B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;yBACtC;qBACF;iBACF,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC5E,MAAM,IAAI,KAAK,CAAC,4BAA4B,YAAY,EAAE,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;QAC7C,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACrC,OAAO,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC1D,CAAC;CACF;AAjPD,kDAiPC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ContractClient } from '../utils/contracts';
|
|
3
|
+
import { BalanceData } from '../types';
|
|
4
|
+
export declare const getBalanceSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
5
|
+
export declare function getBalance(params: z.infer<typeof getBalanceSchema>, client: ContractClient): Promise<BalanceData>;
|
|
6
|
+
//# sourceMappingURL=balance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../../src/tools/balance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAwB,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,gBAAgB,gDAAe,CAAC;AAE7C,wBAAsB,UAAU,CAC9B,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,EACxC,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,WAAW,CAAC,CA8BtB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBalanceSchema = void 0;
|
|
4
|
+
exports.getBalance = getBalance;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const contracts_1 = require("../utils/contracts");
|
|
7
|
+
exports.getBalanceSchema = zod_1.z.object({});
|
|
8
|
+
async function getBalance(params, client) {
|
|
9
|
+
const account = client.getAccount();
|
|
10
|
+
const publicClient = client.getPublicClient();
|
|
11
|
+
const contracts = client.getContracts();
|
|
12
|
+
try {
|
|
13
|
+
// Query USDC balance
|
|
14
|
+
const usdcBalance = await publicClient.readContract({
|
|
15
|
+
address: contracts.usdc,
|
|
16
|
+
abi: contracts_1.USDC_ABI,
|
|
17
|
+
functionName: 'balanceOf',
|
|
18
|
+
args: [account.address],
|
|
19
|
+
});
|
|
20
|
+
// Query credit status
|
|
21
|
+
const [creditLimit, creditAvailable, creditInUse] = await publicClient.readContract({
|
|
22
|
+
address: contracts.credit,
|
|
23
|
+
abi: contracts_1.CREDIT_ABI,
|
|
24
|
+
functionName: 'getCreditStatus',
|
|
25
|
+
args: [account.address],
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
usdc: client.formatUSDC(usdcBalance),
|
|
29
|
+
credit: client.formatUSDC(creditAvailable),
|
|
30
|
+
locked: client.formatUSDC(creditInUse),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new Error(`Failed to fetch balance: ${error.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=balance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balance.js","sourceRoot":"","sources":["../../src/tools/balance.ts"],"names":[],"mappings":";;;AAMA,gCAiCC;AAvCD,6BAAwB;AACxB,kDAA0E;AAG7D,QAAA,gBAAgB,GAAG,OAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAEtC,KAAK,UAAU,UAAU,CAC9B,MAAwC,EACxC,MAAsB;IAEtB,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IACpC,MAAM,YAAY,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAC9C,MAAM,SAAS,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC;IAExC,IAAI,CAAC;QACH,qBAAqB;QACrB,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,YAAY,CAAC;YAClD,OAAO,EAAE,SAAS,CAAC,IAAI;YACvB,GAAG,EAAE,oBAAQ;YACb,YAAY,EAAE,WAAW;YACzB,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;SACxB,CAAC,CAAC;QAEH,sBAAsB;QACtB,MAAM,CAAC,WAAW,EAAE,eAAe,EAAE,WAAW,CAAC,GAAG,MAAM,YAAY,CAAC,YAAY,CAAC;YAClF,OAAO,EAAE,SAAS,CAAC,MAAM;YACzB,GAAG,EAAE,sBAAU;YACf,YAAY,EAAE,iBAAiB;YAC/B,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;SACxB,CAAC,CAAC;QAEH,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,WAAqB,CAAC;YAC9C,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,eAAyB,CAAC;YACpD,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,WAAqB,CAAC;SACjD,CAAC;IACJ,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ContractClient } from '../utils/contracts';
|
|
3
|
+
import { EscrowData } from '../types';
|
|
4
|
+
export declare const createEscrowSchema: z.ZodObject<{
|
|
5
|
+
to: z.ZodString;
|
|
6
|
+
amount: z.ZodString;
|
|
7
|
+
currency: z.ZodDefault<z.ZodString>;
|
|
8
|
+
terms: z.ZodOptional<z.ZodObject<{
|
|
9
|
+
releaseOn: z.ZodDefault<z.ZodEnum<["delivery-confirmed", "timeout", "manual"]>>;
|
|
10
|
+
timeout: z.ZodOptional<z.ZodString>;
|
|
11
|
+
disputeWindow: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
releaseOn: "timeout" | "delivery-confirmed" | "manual";
|
|
14
|
+
timeout?: string | undefined;
|
|
15
|
+
disputeWindow?: string | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
timeout?: string | undefined;
|
|
18
|
+
releaseOn?: "timeout" | "delivery-confirmed" | "manual" | undefined;
|
|
19
|
+
disputeWindow?: string | undefined;
|
|
20
|
+
}>>;
|
|
21
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
to: string;
|
|
24
|
+
amount: string;
|
|
25
|
+
currency: string;
|
|
26
|
+
metadata?: Record<string, any> | undefined;
|
|
27
|
+
terms?: {
|
|
28
|
+
releaseOn: "timeout" | "delivery-confirmed" | "manual";
|
|
29
|
+
timeout?: string | undefined;
|
|
30
|
+
disputeWindow?: string | undefined;
|
|
31
|
+
} | undefined;
|
|
32
|
+
}, {
|
|
33
|
+
to: string;
|
|
34
|
+
amount: string;
|
|
35
|
+
metadata?: Record<string, any> | undefined;
|
|
36
|
+
currency?: string | undefined;
|
|
37
|
+
terms?: {
|
|
38
|
+
timeout?: string | undefined;
|
|
39
|
+
releaseOn?: "timeout" | "delivery-confirmed" | "manual" | undefined;
|
|
40
|
+
disputeWindow?: string | undefined;
|
|
41
|
+
} | undefined;
|
|
42
|
+
}>;
|
|
43
|
+
export declare const releaseEscrowSchema: z.ZodObject<{
|
|
44
|
+
escrowId: z.ZodString;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
escrowId: string;
|
|
47
|
+
}, {
|
|
48
|
+
escrowId: string;
|
|
49
|
+
}>;
|
|
50
|
+
export declare const getEscrowSchema: z.ZodObject<{
|
|
51
|
+
escrowId: z.ZodString;
|
|
52
|
+
}, "strip", z.ZodTypeAny, {
|
|
53
|
+
escrowId: string;
|
|
54
|
+
}, {
|
|
55
|
+
escrowId: string;
|
|
56
|
+
}>;
|
|
57
|
+
export declare const listEscrowsSchema: z.ZodObject<{
|
|
58
|
+
creator: z.ZodOptional<z.ZodString>;
|
|
59
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
60
|
+
status: z.ZodOptional<z.ZodEnum<["pending", "active", "released", "disputed", "refunded"]>>;
|
|
61
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
limit: number;
|
|
64
|
+
status?: "pending" | "active" | "released" | "disputed" | "refunded" | undefined;
|
|
65
|
+
creator?: string | undefined;
|
|
66
|
+
provider?: string | undefined;
|
|
67
|
+
}, {
|
|
68
|
+
limit?: number | undefined;
|
|
69
|
+
status?: "pending" | "active" | "released" | "disputed" | "refunded" | undefined;
|
|
70
|
+
creator?: string | undefined;
|
|
71
|
+
provider?: string | undefined;
|
|
72
|
+
}>;
|
|
73
|
+
export declare function createEscrow(params: z.infer<typeof createEscrowSchema>, client: ContractClient): Promise<{
|
|
74
|
+
escrowId: string;
|
|
75
|
+
transactionHash: string;
|
|
76
|
+
amount: string;
|
|
77
|
+
currency: string;
|
|
78
|
+
releaseAt: number;
|
|
79
|
+
status: string;
|
|
80
|
+
}>;
|
|
81
|
+
export declare function releaseEscrow(params: z.infer<typeof releaseEscrowSchema>, client: ContractClient): Promise<{
|
|
82
|
+
transactionHash: string;
|
|
83
|
+
released: string;
|
|
84
|
+
recipient: string;
|
|
85
|
+
}>;
|
|
86
|
+
export declare function getEscrow(params: z.infer<typeof getEscrowSchema>, client: ContractClient): Promise<EscrowData>;
|
|
87
|
+
export declare function listEscrows(params: z.infer<typeof listEscrowsSchema>, client: ContractClient): Promise<{
|
|
88
|
+
escrows: EscrowData[];
|
|
89
|
+
total: number;
|
|
90
|
+
}>;
|
|
91
|
+
//# sourceMappingURL=escrow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escrow.d.ts","sourceRoot":"","sources":["../../src/tools/escrow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,cAAc,EAAwB,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAU7B,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;EAE9B,CAAC;AAEH,eAAO,MAAM,eAAe;;;;;;EAE1B,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;EAK5B,CAAC;AAEH,wBAAsB,YAAY,CAChC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,EAC1C,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC;IACT,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC,CA+DD;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,EAC3C,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC;IACT,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC,CAuCD;AAED,wBAAsB,SAAS,CAC7B,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,EACvC,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,UAAU,CAAC,CAoCrB;AAED,wBAAsB,WAAW,CAC/B,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,EACzC,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC;IAAE,OAAO,EAAE,UAAU,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CA+EnD"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listEscrowsSchema = exports.getEscrowSchema = exports.releaseEscrowSchema = exports.createEscrowSchema = void 0;
|
|
4
|
+
exports.createEscrow = createEscrow;
|
|
5
|
+
exports.releaseEscrow = releaseEscrow;
|
|
6
|
+
exports.getEscrow = getEscrow;
|
|
7
|
+
exports.listEscrows = listEscrows;
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const contracts_1 = require("../utils/contracts");
|
|
10
|
+
exports.createEscrowSchema = zod_1.z.object({
|
|
11
|
+
to: zod_1.z.string().describe('Recipient address'),
|
|
12
|
+
amount: zod_1.z.string().describe('Amount in USDC'),
|
|
13
|
+
currency: zod_1.z.string().default('USDC'),
|
|
14
|
+
terms: zod_1.z.object({
|
|
15
|
+
releaseOn: zod_1.z.enum(['delivery-confirmed', 'timeout', 'manual']).default('delivery-confirmed'),
|
|
16
|
+
timeout: zod_1.z.string().optional().describe('ISO 8601 duration (e.g., P1D for 1 day)'),
|
|
17
|
+
disputeWindow: zod_1.z.string().optional().describe('ISO 8601 duration'),
|
|
18
|
+
}).optional(),
|
|
19
|
+
metadata: zod_1.z.record(zod_1.z.any()).optional(),
|
|
20
|
+
});
|
|
21
|
+
exports.releaseEscrowSchema = zod_1.z.object({
|
|
22
|
+
escrowId: zod_1.z.string().describe('Escrow ID'),
|
|
23
|
+
});
|
|
24
|
+
exports.getEscrowSchema = zod_1.z.object({
|
|
25
|
+
escrowId: zod_1.z.string().describe('Escrow ID'),
|
|
26
|
+
});
|
|
27
|
+
exports.listEscrowsSchema = zod_1.z.object({
|
|
28
|
+
creator: zod_1.z.string().optional().describe('Filter by creator address'),
|
|
29
|
+
provider: zod_1.z.string().optional().describe('Filter by provider address'),
|
|
30
|
+
status: zod_1.z.enum(['pending', 'active', 'released', 'disputed', 'refunded']).optional(),
|
|
31
|
+
limit: zod_1.z.number().default(20),
|
|
32
|
+
});
|
|
33
|
+
async function createEscrow(params, client) {
|
|
34
|
+
const account = client.getAccount();
|
|
35
|
+
const walletClient = client.getWalletClient();
|
|
36
|
+
const publicClient = client.getPublicClient();
|
|
37
|
+
const contracts = client.getContracts();
|
|
38
|
+
// Parse amount
|
|
39
|
+
const amountBigInt = client.parseUSDC(params.amount);
|
|
40
|
+
// Parse timeout
|
|
41
|
+
let timeoutMs = 7 * 24 * 60 * 60 * 1000; // Default 7 days
|
|
42
|
+
if (params.terms?.timeout) {
|
|
43
|
+
timeoutMs = parseDuration(params.terms.timeout);
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
// Step 1: Approve USDC spending by escrow contract
|
|
47
|
+
const approveHash = await walletClient.writeContract({
|
|
48
|
+
address: contracts.usdc,
|
|
49
|
+
abi: contracts_1.USDC_ABI,
|
|
50
|
+
functionName: 'approve',
|
|
51
|
+
args: [contracts.escrow, amountBigInt],
|
|
52
|
+
account,
|
|
53
|
+
});
|
|
54
|
+
await publicClient.waitForTransactionReceipt({ hash: approveHash });
|
|
55
|
+
// Step 2: Create escrow
|
|
56
|
+
const description = JSON.stringify(params.metadata || {});
|
|
57
|
+
const hash = await walletClient.writeContract({
|
|
58
|
+
address: contracts.escrow,
|
|
59
|
+
abi: contracts_1.ESCROW_ABI,
|
|
60
|
+
functionName: 'createEscrow',
|
|
61
|
+
args: [params.to, amountBigInt, contracts.usdc, description],
|
|
62
|
+
account,
|
|
63
|
+
});
|
|
64
|
+
// Wait for transaction confirmation
|
|
65
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
66
|
+
// Parse escrow ID from event logs
|
|
67
|
+
let escrowId = '0';
|
|
68
|
+
if (receipt.logs && receipt.logs.length > 0) {
|
|
69
|
+
// Look for EscrowCreated event - escrowId is first indexed parameter
|
|
70
|
+
const escrowCreatedLog = receipt.logs.find((log) => log.topics && log.topics.length > 1);
|
|
71
|
+
if (escrowCreatedLog && escrowCreatedLog.topics) {
|
|
72
|
+
escrowId = BigInt(escrowCreatedLog.topics[1]).toString();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
escrowId,
|
|
77
|
+
transactionHash: hash,
|
|
78
|
+
amount: params.amount,
|
|
79
|
+
currency: params.currency,
|
|
80
|
+
releaseAt: Date.now() + timeoutMs,
|
|
81
|
+
status: 'active',
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
throw new Error(`Failed to create escrow: ${error.message}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function releaseEscrow(params, client) {
|
|
89
|
+
const account = client.getAccount();
|
|
90
|
+
const walletClient = client.getWalletClient();
|
|
91
|
+
const publicClient = client.getPublicClient();
|
|
92
|
+
const contracts = client.getContracts();
|
|
93
|
+
try {
|
|
94
|
+
// Get escrow details first
|
|
95
|
+
const escrowId = BigInt(params.escrowId);
|
|
96
|
+
const [sender, recipient, amount, token, status] = await publicClient.readContract({
|
|
97
|
+
address: contracts.escrow,
|
|
98
|
+
abi: contracts_1.ESCROW_ABI,
|
|
99
|
+
functionName: 'getEscrow',
|
|
100
|
+
args: [escrowId],
|
|
101
|
+
});
|
|
102
|
+
if (status !== 1) { // 1 = active status
|
|
103
|
+
throw new Error(`Escrow ${params.escrowId} is not active`);
|
|
104
|
+
}
|
|
105
|
+
// Release escrow
|
|
106
|
+
const hash = await walletClient.writeContract({
|
|
107
|
+
address: contracts.escrow,
|
|
108
|
+
abi: contracts_1.ESCROW_ABI,
|
|
109
|
+
functionName: 'releaseEscrow',
|
|
110
|
+
args: [escrowId],
|
|
111
|
+
account,
|
|
112
|
+
});
|
|
113
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
114
|
+
return {
|
|
115
|
+
transactionHash: hash,
|
|
116
|
+
released: client.formatUSDC(amount),
|
|
117
|
+
recipient: recipient,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
throw new Error(`Failed to release escrow: ${error.message}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function getEscrow(params, client) {
|
|
125
|
+
const publicClient = client.getPublicClient();
|
|
126
|
+
const contracts = client.getContracts();
|
|
127
|
+
try {
|
|
128
|
+
const escrowId = BigInt(params.escrowId);
|
|
129
|
+
const [sender, recipient, amount, token, status] = await publicClient.readContract({
|
|
130
|
+
address: contracts.escrow,
|
|
131
|
+
abi: contracts_1.ESCROW_ABI,
|
|
132
|
+
functionName: 'getEscrow',
|
|
133
|
+
args: [escrowId],
|
|
134
|
+
});
|
|
135
|
+
// Map contract status (uint8) to string status
|
|
136
|
+
const statusMap = {
|
|
137
|
+
0: 'pending',
|
|
138
|
+
1: 'active',
|
|
139
|
+
2: 'released',
|
|
140
|
+
3: 'disputed',
|
|
141
|
+
4: 'refunded',
|
|
142
|
+
};
|
|
143
|
+
return {
|
|
144
|
+
escrowId: params.escrowId,
|
|
145
|
+
from: sender,
|
|
146
|
+
to: recipient,
|
|
147
|
+
amount: client.formatUSDC(amount),
|
|
148
|
+
currency: 'USDC',
|
|
149
|
+
status: statusMap[status] || 'pending',
|
|
150
|
+
createdAt: Date.now(), // Would come from creation event
|
|
151
|
+
releaseAt: undefined,
|
|
152
|
+
releasedAt: status === 2 ? Date.now() : undefined,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
throw new Error(`Failed to fetch escrow: ${error.message}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function listEscrows(params, client) {
|
|
160
|
+
const publicClient = client.getPublicClient();
|
|
161
|
+
const contracts = client.getContracts();
|
|
162
|
+
try {
|
|
163
|
+
// Get EscrowCreated events
|
|
164
|
+
const latestBlock = await publicClient.getBlockNumber();
|
|
165
|
+
const fromBlock = latestBlock - BigInt(10000); // Last ~10k blocks
|
|
166
|
+
const logs = await publicClient.getLogs({
|
|
167
|
+
address: contracts.escrow,
|
|
168
|
+
event: contracts_1.ESCROW_ABI.find(e => e.type === 'event' && e.name === 'EscrowCreated'),
|
|
169
|
+
fromBlock,
|
|
170
|
+
toBlock: 'latest',
|
|
171
|
+
});
|
|
172
|
+
// Parse logs into escrow data
|
|
173
|
+
let escrows = [];
|
|
174
|
+
for (const log of logs) {
|
|
175
|
+
const { escrowId, sender, recipient, amount } = log.args;
|
|
176
|
+
// Apply filters
|
|
177
|
+
if (params.creator && sender.toLowerCase() !== params.creator.toLowerCase()) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (params.provider && recipient.toLowerCase() !== params.provider.toLowerCase()) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
// Fetch full escrow details
|
|
184
|
+
try {
|
|
185
|
+
const [_, __, amountFull, token, status] = await publicClient.readContract({
|
|
186
|
+
address: contracts.escrow,
|
|
187
|
+
abi: contracts_1.ESCROW_ABI,
|
|
188
|
+
functionName: 'getEscrow',
|
|
189
|
+
args: [escrowId],
|
|
190
|
+
});
|
|
191
|
+
const statusMap = {
|
|
192
|
+
0: 'pending',
|
|
193
|
+
1: 'active',
|
|
194
|
+
2: 'released',
|
|
195
|
+
3: 'disputed',
|
|
196
|
+
4: 'refunded',
|
|
197
|
+
};
|
|
198
|
+
const escrowStatus = statusMap[status] || 'pending';
|
|
199
|
+
// Apply status filter
|
|
200
|
+
if (params.status && escrowStatus !== params.status) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
escrows.push({
|
|
204
|
+
escrowId: escrowId.toString(),
|
|
205
|
+
from: sender,
|
|
206
|
+
to: recipient,
|
|
207
|
+
amount: client.formatUSDC(amountFull),
|
|
208
|
+
currency: 'USDC',
|
|
209
|
+
status: escrowStatus,
|
|
210
|
+
createdAt: Date.now(), // Would parse from block timestamp
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
catch (e) {
|
|
214
|
+
// Skip escrows that fail to fetch
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// Sort by creation (most recent first) and limit
|
|
219
|
+
escrows = escrows.slice(0, params.limit);
|
|
220
|
+
return {
|
|
221
|
+
escrows,
|
|
222
|
+
total: escrows.length,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
throw new Error(`Failed to list escrows: ${error.message}`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// Helper function to parse ISO 8601 duration
|
|
230
|
+
function parseDuration(duration) {
|
|
231
|
+
// Simple parser for P{n}D (days), P{n}H (hours), P{n}M (minutes)
|
|
232
|
+
const days = duration.match(/P(\d+)D/);
|
|
233
|
+
const hours = duration.match(/PT?(\d+)H/);
|
|
234
|
+
const minutes = duration.match(/PT?(\d+)M/);
|
|
235
|
+
let ms = 0;
|
|
236
|
+
if (days)
|
|
237
|
+
ms += parseInt(days[1]) * 24 * 60 * 60 * 1000;
|
|
238
|
+
if (hours)
|
|
239
|
+
ms += parseInt(hours[1]) * 60 * 60 * 1000;
|
|
240
|
+
if (minutes)
|
|
241
|
+
ms += parseInt(minutes[1]) * 60 * 1000;
|
|
242
|
+
return ms || 7 * 24 * 60 * 60 * 1000; // Default 7 days
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=escrow.js.map
|