@mcpaid/sdk 2.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/LICENSE +176 -0
- package/NPM_RESTRUCTURE.md +86 -0
- package/OPERATOR-LICENSE.md +18 -0
- package/README.md +380 -0
- package/SELF-HOSTING.md +108 -0
- package/dist/circuit-breaker/circuit-breaker.d.ts +26 -0
- package/dist/circuit-breaker/circuit-breaker.d.ts.map +1 -0
- package/dist/circuit-breaker/circuit-breaker.js +128 -0
- package/dist/circuit-breaker/circuit-breaker.js.map +1 -0
- package/dist/cli.d.ts +21 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +1560 -0
- package/dist/cli.js.map +1 -0
- package/dist/contracts/ToolPayRouter.d.ts +288 -0
- package/dist/contracts/ToolPayRouter.d.ts.map +1 -0
- package/dist/contracts/ToolPayRouter.js +370 -0
- package/dist/contracts/ToolPayRouter.js.map +1 -0
- package/dist/contracts/router-registry.d.ts +19 -0
- package/dist/contracts/router-registry.d.ts.map +1 -0
- package/dist/contracts/router-registry.js +28 -0
- package/dist/contracts/router-registry.js.map +1 -0
- package/dist/fee/fee-calculator.d.ts +35 -0
- package/dist/fee/fee-calculator.d.ts.map +1 -0
- package/dist/fee/fee-calculator.js +57 -0
- package/dist/fee/fee-calculator.js.map +1 -0
- package/dist/fee/fee-ledger.d.ts +66 -0
- package/dist/fee/fee-ledger.d.ts.map +1 -0
- package/dist/fee/fee-ledger.js +181 -0
- package/dist/fee/fee-ledger.js.map +1 -0
- package/dist/gateway/config-loader.d.ts +38 -0
- package/dist/gateway/config-loader.d.ts.map +1 -0
- package/dist/gateway/config-loader.js +125 -0
- package/dist/gateway/config-loader.js.map +1 -0
- package/dist/gateway/server-registry.d.ts +25 -0
- package/dist/gateway/server-registry.d.ts.map +1 -0
- package/dist/gateway/server-registry.js +59 -0
- package/dist/gateway/server-registry.js.map +1 -0
- package/dist/gateway/toolpay-gateway.d.ts +57 -0
- package/dist/gateway/toolpay-gateway.d.ts.map +1 -0
- package/dist/gateway/toolpay-gateway.js +320 -0
- package/dist/gateway/toolpay-gateway.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/sdk/client-agent.d.ts +47 -0
- package/dist/sdk/client-agent.d.ts.map +1 -0
- package/dist/sdk/client-agent.js +158 -0
- package/dist/sdk/client-agent.js.map +1 -0
- package/dist/sdk/server-sdk.d.ts +51 -0
- package/dist/sdk/server-sdk.d.ts.map +1 -0
- package/dist/sdk/server-sdk.js +170 -0
- package/dist/sdk/server-sdk.js.map +1 -0
- package/dist/settlement/base-contract-client.d.ts +156 -0
- package/dist/settlement/base-contract-client.d.ts.map +1 -0
- package/dist/settlement/base-contract-client.js +156 -0
- package/dist/settlement/base-contract-client.js.map +1 -0
- package/dist/settlement/nonce-store.d.ts +54 -0
- package/dist/settlement/nonce-store.d.ts.map +1 -0
- package/dist/settlement/nonce-store.js +125 -0
- package/dist/settlement/nonce-store.js.map +1 -0
- package/dist/settlement/onchain-verifier.d.ts +41 -0
- package/dist/settlement/onchain-verifier.d.ts.map +1 -0
- package/dist/settlement/onchain-verifier.js +114 -0
- package/dist/settlement/onchain-verifier.js.map +1 -0
- package/dist/settlement/payment-orchestrator.d.ts +59 -0
- package/dist/settlement/payment-orchestrator.d.ts.map +1 -0
- package/dist/settlement/payment-orchestrator.js +282 -0
- package/dist/settlement/payment-orchestrator.js.map +1 -0
- package/dist/settlement/permit-verifier.d.ts +60 -0
- package/dist/settlement/permit-verifier.d.ts.map +1 -0
- package/dist/settlement/permit-verifier.js +80 -0
- package/dist/settlement/permit-verifier.js.map +1 -0
- package/dist/settlement/session-wallet.d.ts +60 -0
- package/dist/settlement/session-wallet.d.ts.map +1 -0
- package/dist/settlement/session-wallet.js +105 -0
- package/dist/settlement/session-wallet.js.map +1 -0
- package/dist/transports/sse-transport.d.ts +27 -0
- package/dist/transports/sse-transport.d.ts.map +1 -0
- package/dist/transports/sse-transport.js +65 -0
- package/dist/transports/sse-transport.js.map +1 -0
- package/dist/transports/stdio-bridge.d.ts +29 -0
- package/dist/transports/stdio-bridge.d.ts.map +1 -0
- package/dist/transports/stdio-bridge.js +133 -0
- package/dist/transports/stdio-bridge.js.map +1 -0
- package/dist/types/circuit-breaker.d.ts +22 -0
- package/dist/types/circuit-breaker.d.ts.map +1 -0
- package/dist/types/circuit-breaker.js +5 -0
- package/dist/types/circuit-breaker.js.map +1 -0
- package/dist/types/ledger.d.ts +57 -0
- package/dist/types/ledger.d.ts.map +1 -0
- package/dist/types/ledger.js +5 -0
- package/dist/types/ledger.js.map +1 -0
- package/dist/types/mcp.d.ts +67 -0
- package/dist/types/mcp.d.ts.map +1 -0
- package/dist/types/mcp.js +5 -0
- package/dist/types/mcp.js.map +1 -0
- package/dist/types/pricing.d.ts +68 -0
- package/dist/types/pricing.d.ts.map +1 -0
- package/dist/types/pricing.js +5 -0
- package/dist/types/pricing.js.map +1 -0
- package/dist/types/x402.d.ts +76 -0
- package/dist/types/x402.d.ts.map +1 -0
- package/dist/types/x402.js +5 -0
- package/dist/types/x402.js.map +1 -0
- package/dist/utils/units.d.ts +45 -0
- package/dist/utils/units.d.ts.map +1 -0
- package/dist/utils/units.js +141 -0
- package/dist/utils/units.js.map +1 -0
- package/package.json +72 -0
- package/src/contracts/ToolPayRouter.json +371 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated ToolPayRouter ABI & Bytecode
|
|
3
|
+
*/
|
|
4
|
+
export const TOOLPAY_ROUTER_ABI = [
|
|
5
|
+
{
|
|
6
|
+
"inputs": [
|
|
7
|
+
{
|
|
8
|
+
"internalType": "address",
|
|
9
|
+
"name": "_platformTreasury",
|
|
10
|
+
"type": "address"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"internalType": "uint256",
|
|
14
|
+
"name": "_defaultFeeBps",
|
|
15
|
+
"type": "uint256"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"stateMutability": "nonpayable",
|
|
19
|
+
"type": "constructor"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"anonymous": false,
|
|
23
|
+
"inputs": [
|
|
24
|
+
{
|
|
25
|
+
"indexed": true,
|
|
26
|
+
"internalType": "address",
|
|
27
|
+
"name": "developer",
|
|
28
|
+
"type": "address"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"indexed": false,
|
|
32
|
+
"internalType": "uint256",
|
|
33
|
+
"name": "feeBps",
|
|
34
|
+
"type": "uint256"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"name": "CustomFeeSet",
|
|
38
|
+
"type": "event"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"anonymous": false,
|
|
42
|
+
"inputs": [
|
|
43
|
+
{
|
|
44
|
+
"indexed": true,
|
|
45
|
+
"internalType": "address",
|
|
46
|
+
"name": "oldOwner",
|
|
47
|
+
"type": "address"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"indexed": true,
|
|
51
|
+
"internalType": "address",
|
|
52
|
+
"name": "newOwner",
|
|
53
|
+
"type": "address"
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"name": "OwnershipTransferred",
|
|
57
|
+
"type": "event"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"anonymous": false,
|
|
61
|
+
"inputs": [
|
|
62
|
+
{
|
|
63
|
+
"indexed": true,
|
|
64
|
+
"internalType": "bytes32",
|
|
65
|
+
"name": "challengeNonce",
|
|
66
|
+
"type": "bytes32"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"indexed": true,
|
|
70
|
+
"internalType": "address",
|
|
71
|
+
"name": "agent",
|
|
72
|
+
"type": "address"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"indexed": true,
|
|
76
|
+
"internalType": "address",
|
|
77
|
+
"name": "developer",
|
|
78
|
+
"type": "address"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"indexed": false,
|
|
82
|
+
"internalType": "address",
|
|
83
|
+
"name": "token",
|
|
84
|
+
"type": "address"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"indexed": false,
|
|
88
|
+
"internalType": "uint256",
|
|
89
|
+
"name": "grossAmount",
|
|
90
|
+
"type": "uint256"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"indexed": false,
|
|
94
|
+
"internalType": "uint256",
|
|
95
|
+
"name": "platformCut",
|
|
96
|
+
"type": "uint256"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"indexed": false,
|
|
100
|
+
"internalType": "uint256",
|
|
101
|
+
"name": "developerPayout",
|
|
102
|
+
"type": "uint256"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"indexed": false,
|
|
106
|
+
"internalType": "string",
|
|
107
|
+
"name": "serverId",
|
|
108
|
+
"type": "string"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"indexed": false,
|
|
112
|
+
"internalType": "string",
|
|
113
|
+
"name": "toolName",
|
|
114
|
+
"type": "string"
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
"name": "PaymentSettled",
|
|
118
|
+
"type": "event"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"anonymous": false,
|
|
122
|
+
"inputs": [
|
|
123
|
+
{
|
|
124
|
+
"indexed": false,
|
|
125
|
+
"internalType": "uint256",
|
|
126
|
+
"name": "oldBps",
|
|
127
|
+
"type": "uint256"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"indexed": false,
|
|
131
|
+
"internalType": "uint256",
|
|
132
|
+
"name": "newBps",
|
|
133
|
+
"type": "uint256"
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
"name": "PlatformFeeUpdated",
|
|
137
|
+
"type": "event"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"anonymous": false,
|
|
141
|
+
"inputs": [
|
|
142
|
+
{
|
|
143
|
+
"indexed": true,
|
|
144
|
+
"internalType": "address",
|
|
145
|
+
"name": "oldTreasury",
|
|
146
|
+
"type": "address"
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"indexed": true,
|
|
150
|
+
"internalType": "address",
|
|
151
|
+
"name": "newTreasury",
|
|
152
|
+
"type": "address"
|
|
153
|
+
}
|
|
154
|
+
],
|
|
155
|
+
"name": "TreasuryUpdated",
|
|
156
|
+
"type": "event"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"inputs": [],
|
|
160
|
+
"name": "BASIS_POINTS_DIVISOR",
|
|
161
|
+
"outputs": [
|
|
162
|
+
{
|
|
163
|
+
"internalType": "uint256",
|
|
164
|
+
"name": "",
|
|
165
|
+
"type": "uint256"
|
|
166
|
+
}
|
|
167
|
+
],
|
|
168
|
+
"stateMutability": "view",
|
|
169
|
+
"type": "function"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"inputs": [
|
|
173
|
+
{
|
|
174
|
+
"internalType": "address",
|
|
175
|
+
"name": "",
|
|
176
|
+
"type": "address"
|
|
177
|
+
}
|
|
178
|
+
],
|
|
179
|
+
"name": "customDeveloperFeeBps",
|
|
180
|
+
"outputs": [
|
|
181
|
+
{
|
|
182
|
+
"internalType": "uint256",
|
|
183
|
+
"name": "",
|
|
184
|
+
"type": "uint256"
|
|
185
|
+
}
|
|
186
|
+
],
|
|
187
|
+
"stateMutability": "view",
|
|
188
|
+
"type": "function"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"inputs": [],
|
|
192
|
+
"name": "defaultPlatformFeeBps",
|
|
193
|
+
"outputs": [
|
|
194
|
+
{
|
|
195
|
+
"internalType": "uint256",
|
|
196
|
+
"name": "",
|
|
197
|
+
"type": "uint256"
|
|
198
|
+
}
|
|
199
|
+
],
|
|
200
|
+
"stateMutability": "view",
|
|
201
|
+
"type": "function"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"inputs": [
|
|
205
|
+
{
|
|
206
|
+
"internalType": "bytes32",
|
|
207
|
+
"name": "",
|
|
208
|
+
"type": "bytes32"
|
|
209
|
+
}
|
|
210
|
+
],
|
|
211
|
+
"name": "expendedNonces",
|
|
212
|
+
"outputs": [
|
|
213
|
+
{
|
|
214
|
+
"internalType": "bool",
|
|
215
|
+
"name": "",
|
|
216
|
+
"type": "bool"
|
|
217
|
+
}
|
|
218
|
+
],
|
|
219
|
+
"stateMutability": "view",
|
|
220
|
+
"type": "function"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"inputs": [
|
|
224
|
+
{
|
|
225
|
+
"internalType": "address",
|
|
226
|
+
"name": "",
|
|
227
|
+
"type": "address"
|
|
228
|
+
}
|
|
229
|
+
],
|
|
230
|
+
"name": "hasCustomFee",
|
|
231
|
+
"outputs": [
|
|
232
|
+
{
|
|
233
|
+
"internalType": "bool",
|
|
234
|
+
"name": "",
|
|
235
|
+
"type": "bool"
|
|
236
|
+
}
|
|
237
|
+
],
|
|
238
|
+
"stateMutability": "view",
|
|
239
|
+
"type": "function"
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"inputs": [],
|
|
243
|
+
"name": "owner",
|
|
244
|
+
"outputs": [
|
|
245
|
+
{
|
|
246
|
+
"internalType": "address",
|
|
247
|
+
"name": "",
|
|
248
|
+
"type": "address"
|
|
249
|
+
}
|
|
250
|
+
],
|
|
251
|
+
"stateMutability": "view",
|
|
252
|
+
"type": "function"
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
"inputs": [
|
|
256
|
+
{
|
|
257
|
+
"internalType": "address",
|
|
258
|
+
"name": "token",
|
|
259
|
+
"type": "address"
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
"internalType": "address",
|
|
263
|
+
"name": "developer",
|
|
264
|
+
"type": "address"
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
"internalType": "uint256",
|
|
268
|
+
"name": "grossAmount",
|
|
269
|
+
"type": "uint256"
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
"internalType": "bytes32",
|
|
273
|
+
"name": "challengeNonce",
|
|
274
|
+
"type": "bytes32"
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
"internalType": "string",
|
|
278
|
+
"name": "serverId",
|
|
279
|
+
"type": "string"
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
"internalType": "string",
|
|
283
|
+
"name": "toolName",
|
|
284
|
+
"type": "string"
|
|
285
|
+
}
|
|
286
|
+
],
|
|
287
|
+
"name": "payForTool",
|
|
288
|
+
"outputs": [
|
|
289
|
+
{
|
|
290
|
+
"internalType": "bool",
|
|
291
|
+
"name": "",
|
|
292
|
+
"type": "bool"
|
|
293
|
+
}
|
|
294
|
+
],
|
|
295
|
+
"stateMutability": "nonpayable",
|
|
296
|
+
"type": "function"
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
"inputs": [],
|
|
300
|
+
"name": "platformTreasury",
|
|
301
|
+
"outputs": [
|
|
302
|
+
{
|
|
303
|
+
"internalType": "address",
|
|
304
|
+
"name": "",
|
|
305
|
+
"type": "address"
|
|
306
|
+
}
|
|
307
|
+
],
|
|
308
|
+
"stateMutability": "view",
|
|
309
|
+
"type": "function"
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
"inputs": [
|
|
313
|
+
{
|
|
314
|
+
"internalType": "address",
|
|
315
|
+
"name": "developer",
|
|
316
|
+
"type": "address"
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
"internalType": "uint256",
|
|
320
|
+
"name": "feeBps",
|
|
321
|
+
"type": "uint256"
|
|
322
|
+
}
|
|
323
|
+
],
|
|
324
|
+
"name": "setCustomDeveloperFee",
|
|
325
|
+
"outputs": [],
|
|
326
|
+
"stateMutability": "nonpayable",
|
|
327
|
+
"type": "function"
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
"inputs": [
|
|
331
|
+
{
|
|
332
|
+
"internalType": "uint256",
|
|
333
|
+
"name": "newFeeBps",
|
|
334
|
+
"type": "uint256"
|
|
335
|
+
}
|
|
336
|
+
],
|
|
337
|
+
"name": "setDefaultPlatformFee",
|
|
338
|
+
"outputs": [],
|
|
339
|
+
"stateMutability": "nonpayable",
|
|
340
|
+
"type": "function"
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
"inputs": [
|
|
344
|
+
{
|
|
345
|
+
"internalType": "address",
|
|
346
|
+
"name": "newTreasury",
|
|
347
|
+
"type": "address"
|
|
348
|
+
}
|
|
349
|
+
],
|
|
350
|
+
"name": "setPlatformTreasury",
|
|
351
|
+
"outputs": [],
|
|
352
|
+
"stateMutability": "nonpayable",
|
|
353
|
+
"type": "function"
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
"inputs": [
|
|
357
|
+
{
|
|
358
|
+
"internalType": "address",
|
|
359
|
+
"name": "newOwner",
|
|
360
|
+
"type": "address"
|
|
361
|
+
}
|
|
362
|
+
],
|
|
363
|
+
"name": "transferOwnership",
|
|
364
|
+
"outputs": [],
|
|
365
|
+
"stateMutability": "nonpayable",
|
|
366
|
+
"type": "function"
|
|
367
|
+
}
|
|
368
|
+
];
|
|
369
|
+
export const TOOLPAY_ROUTER_BYTECODE = '0x60803461012357601f610b1638819003918201601f19168301916001600160401b038311848410176101275780849260409485528339810103126101235780516001600160a01b038116919082900361012357602001519080156100de576107d08211610099575f80546001600160a01b03199081163317909155600180549091169190911790556002556040516109da908161013c8239f35b60405162461bcd60e51b815260206004820152601560248201527f4665652063616e6e6f74206578636565642032302500000000000000000000006044820152606490fd5b60405162461bcd60e51b815260206004820152601860248201527f496e76616c6964207472656173757279206164647265737300000000000000006044820152606490fd5b5f80fd5b634e487b7160e01b5f52604160045260245ffdfe6080806040526004361015610012575f80fd5b5f3560e01c908163126082cf146108045750806329fcce401461076157806363ac95c514610729578063721eaecd146106ec5780637cd86d60146106295780638da5cb5b14610602578063ae8a095814610240578063e138818c14610218578063e67d03bb146101e9578063ed3b7e9f146101cc578063f2fde38b146101115763fdd950c1146100a0575f80fd5b3461010d57602036600319011261010d576004356100c860018060a01b035f54163314610862565b6100d66107d08211156108f2565b7fd347e206f25a89b917fc9482f1a2d294d749baa4dc9bde7fb495ee11fe49164360406002548151908152836020820152a1600255005b5f80fd5b3461010d57602036600319011261010d5761012a61081e565b5f546001600160a01b03811691610142338414610862565b6001600160a01b03169182156101875782907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a36001600160a01b031916175f55005b60405162461bcd60e51b815260206004820152601960248201527f496e76616c6964206e6577206f776e65722061646472657373000000000000006044820152606490fd5b3461010d575f36600319011261010d576020600254604051908152f35b3461010d57602036600319011261010d576004355f526003602052602060ff60405f2054166040519015158152f35b3461010d575f36600319011261010d576001546040516001600160a01b039091168152602090f35b3461010d5760c036600319011261010d5761025961081e565b6024356001600160a01b038116919082810361010d576064359060443560843567ffffffffffffffff811161010d57610296903690600401610834565b929060a43567ffffffffffffffff811161010d576102b8903690600401610834565b9190966102c68915156108a6565b84156105be57865f52600360205260ff60405f20541661056d57865f52600360205260405f20600160ff19825416179055885f52600560205260ff60405f2054165f1461056557885f52600460205260405f20545b808602908682040361055157612710900480860391868311610551576001600160a01b031694829082880361049c575b5050806103c5575b917f01bd537b97c774f1a1806401229bfb33cbba0d3a0673bf43cc273b7ef060c705966103a7926103b79594604051988998895260208901526040880152606087015260c0608087015260c0860191610984565b9083820360a08501523397610984565b0390a4602060405160018152f35b6001546040516323b872dd60e01b81523360048201526001600160a01b0390911660248201526044810182905291939290916020816064815f8a5af1908115610491575f91610462575b501561041d57919290610353565b60405162461bcd60e51b815260206004820152601860248201527f5472656173757279207472616e73666572206661696c656400000000000000006044820152606490fd5b610484915060203d60201161048a575b61047c8183610936565b81019061096c565b8b61040f565b503d610472565b6040513d5f823e3d90fd5b6040516323b872dd60e01b81523360048201526001600160a01b0391909116602482015260448101919091526020816064815f8a5af1908115610491575f91610532575b50156104ed57818b61034b565b60405162461bcd60e51b815260206004820152601960248201527f446576656c6f706572207472616e73666572206661696c6564000000000000006044820152606490fd5b61054b915060203d60201161048a5761047c8183610936565b8b6104e0565b634e487b7160e01b5f52601160045260245ffd5b60025461031b565b60405162461bcd60e51b8152602060048201526024808201527f4e6f6e636520616c726561647920657870656e6465642028616e74692d7265706044820152636c61792960e01b6064820152608490fd5b606460405162461bcd60e51b815260206004820152602060248201527f416d6f756e74206d7573742062652067726561746572207468616e207a65726f6044820152fd5b3461010d575f36600319011261010d575f546040516001600160a01b039091168152602090f35b3461010d57602036600319011261010d5761064261081e565b61065660018060a01b035f54163314610862565b6001600160a01b031680156106a757600154816001600160a01b0382167f4ab5be82436d353e61ca18726e984e561f5c1cc7c6d38b29d2553c790434705a5f80a36001600160a01b03191617600155005b60405162461bcd60e51b815260206004820152601860248201527f496e76616c6964207472656173757279206164647265737300000000000000006044820152606490fd5b3461010d57602036600319011261010d576001600160a01b0361070d61081e565b165f526005602052602060ff60405f2054166040519015158152f35b3461010d57602036600319011261010d576001600160a01b0361074a61081e565b165f526004602052602060405f2054604051908152f35b3461010d57604036600319011261010d5761077a61081e565b7f4bf35bdb30378ec45195e205e56c03a10f89b4ccde934846b966b834fa72d5ce6020602435926107b560018060a01b035f54163314610862565b6001600160a01b0316926107ca8415156108a6565b6107d86107d08211156108f2565b835f52600482528060405f2055835f526005825260405f20600160ff19825416179055604051908152a2005b3461010d575f36600319011261010d578061271060209252f35b600435906001600160a01b038216820361010d57565b9181601f8401121561010d5782359167ffffffffffffffff831161010d576020838186019501011161010d57565b1561086957565b60405162461bcd60e51b815260206004820152601560248201527413db9b1e481bdddb995c88185d5d1a1bdc9a5e9959605a1b6044820152606490fd5b156108ad57565b60405162461bcd60e51b815260206004820152601960248201527f496e76616c696420646576656c6f7065722061646472657373000000000000006044820152606490fd5b156108f957565b60405162461bcd60e51b81526020600482015260156024820152744665652063616e6e6f74206578636565642032302560581b6044820152606490fd5b90601f8019910116810190811067ffffffffffffffff82111761095857604052565b634e487b7160e01b5f52604160045260245ffd5b9081602091031261010d5751801515810361010d5790565b908060209392818452848401375f828201840152601f01601f191601019056fea26469706673582212204b78f84a749ee8b8eba8489375d6741ef7cc49f2715bdef3b5d054088113f6aa64736f6c63430008250033';
|
|
370
|
+
//# sourceMappingURL=ToolPayRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolPayRouter.js","sourceRoot":"","sources":["../../src/contracts/ToolPayRouter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC;QACE,QAAQ,EAAE;YACR;gBACE,cAAc,EAAE,SAAS;gBACzB,MAAM,EAAE,mBAAmB;gBAC3B,MAAM,EAAE,SAAS;aAClB;YACD;gBACE,cAAc,EAAE,SAAS;gBACzB,MAAM,EAAE,gBAAgB;gBACxB,MAAM,EAAE,SAAS;aAClB;SACF;QACD,iBAAiB,EAAE,YAAY;QAC/B,MAAM,EAAE,aAAa;KACtB;IACD;QACE,WAAW,EAAE,KAAK;QAClB,QAAQ,EAAE;YACR;gBACE,SAAS,EAAE,IAAI;gBACf,cAAc,EAAE,SAAS;gBACzB,MAAM,EAAE,WAAW;gBACnB,MAAM,EAAE,SAAS;aAClB;YACD;gBACE,SAAS,EAAE,KAAK;gBAChB,cAAc,EAAE,SAAS;gBACzB,MAAM,EAAE,QAAQ;gBAChB,MAAM,EAAE,SAAS;aAClB;SACF;QACD,MAAM,EAAE,cAAc;QACtB,MAAM,EAAE,OAAO;KAChB;IACD;QACE,WAAW,EAAE,KAAK;QAClB,QAAQ,EAAE;YACR;gBACE,SAAS,EAAE,IAAI;gBACf,cAAc,EAAE,SAAS;gBACzB,MAAM,EAAE,UAAU;gBAClB,MAAM,EAAE,SAAS;aAClB;YACD;gBACE,SAAS,EAAE,IAAI;gBACf,cAAc,EAAE,SAAS;gBACzB,MAAM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,cAAc,EAAE,SAAS;gBACzB,MAAM,EAAE,aAAa;gBACrB,MAAM,EAAE,SAAS;aAClB;SACF;QACD,MAAM,EAAE,qBAAqB;QAC7B,SAAS,EAAE,EAAE;QACb,iBAAiB,EAAE,YAAY;QAC/B,MAAM,EAAE,UAAU;KACnB;IACD;QACE,QAAQ,EAAE;YACR;gBACE,cAAc,EAAE,SAAS;gBACzB,MAAM,EAAE,UAAU;gBAClB,MAAM,EAAE,SAAS;aAClB;SACF;QACD,MAAM,EAAE,mBAAmB;QAC3B,SAAS,EAAE,EAAE;QACb,iBAAiB,EAAE,YAAY;QAC/B,MAAM,EAAE,UAAU;KACnB;CACO,CAAC;AACX,MAAM,CAAC,MAAM,uBAAuB,GAAG,gjLAAyjL,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Official MCPaid router registry.
|
|
3
|
+
*
|
|
4
|
+
* The hosted mcpaid.dev network settles through the official ToolPayRouter
|
|
5
|
+
* contracts below, which atomically route the 3% protocol cut to the
|
|
6
|
+
* official treasury. Self-hosted gateways deploy their own router and are
|
|
7
|
+
* NOT part of the hosted network (see OPERATOR-LICENSE.md / SELF-HOSTING.md).
|
|
8
|
+
*
|
|
9
|
+
* Technical note: this registry is a trust signal, not a trust root. Any
|
|
10
|
+
* operator can change these constants in a fork — enforcement against
|
|
11
|
+
* production self-hosts is via the operator license, plus delisting from
|
|
12
|
+
* hosted discovery. Clients warn (not hard-fail) on non-official routers
|
|
13
|
+
* so testnets and legitimate self-hosts keep working.
|
|
14
|
+
*/
|
|
15
|
+
export declare const OFFICIAL_ROUTER_ADDRESS_BASE: "0x406240a9af02596a20ef9779aa214143c794ecee";
|
|
16
|
+
export declare const OFFICIAL_TREASURY_ADDRESS: "0x49E9fEc4e08310Fb106de24711aBCe51028ECbad";
|
|
17
|
+
export declare const OFFICIAL_DEFAULT_FEE_BPS = 300;
|
|
18
|
+
export declare function isOfficialRouter(address: string | undefined, chainId?: number): boolean;
|
|
19
|
+
//# sourceMappingURL=router-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-registry.d.ts","sourceRoot":"","sources":["../../src/contracts/router-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,4BAA4B,EAAG,4CAAqD,CAAC;AAClG,eAAO,MAAM,yBAAyB,EAAG,4CAAqD,CAAC;AAC/F,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAE5C,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAQvF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Official MCPaid router registry.
|
|
3
|
+
*
|
|
4
|
+
* The hosted mcpaid.dev network settles through the official ToolPayRouter
|
|
5
|
+
* contracts below, which atomically route the 3% protocol cut to the
|
|
6
|
+
* official treasury. Self-hosted gateways deploy their own router and are
|
|
7
|
+
* NOT part of the hosted network (see OPERATOR-LICENSE.md / SELF-HOSTING.md).
|
|
8
|
+
*
|
|
9
|
+
* Technical note: this registry is a trust signal, not a trust root. Any
|
|
10
|
+
* operator can change these constants in a fork — enforcement against
|
|
11
|
+
* production self-hosts is via the operator license, plus delisting from
|
|
12
|
+
* hosted discovery. Clients warn (not hard-fail) on non-official routers
|
|
13
|
+
* so testnets and legitimate self-hosts keep working.
|
|
14
|
+
*/
|
|
15
|
+
export const OFFICIAL_ROUTER_ADDRESS_BASE = '0x406240a9af02596a20ef9779aa214143c794ecee';
|
|
16
|
+
export const OFFICIAL_TREASURY_ADDRESS = '0x49E9fEc4e08310Fb106de24711aBCe51028ECbad';
|
|
17
|
+
export const OFFICIAL_DEFAULT_FEE_BPS = 300;
|
|
18
|
+
export function isOfficialRouter(address, chainId) {
|
|
19
|
+
if (!address)
|
|
20
|
+
return false;
|
|
21
|
+
const a = address.toLowerCase();
|
|
22
|
+
if (chainId === 84532) {
|
|
23
|
+
// Base Sepolia official router not yet declared — treat any router as unofficial there.
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return a === OFFICIAL_ROUTER_ADDRESS_BASE.toLowerCase();
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=router-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-registry.js","sourceRoot":"","sources":["../../src/contracts/router-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,CAAC,MAAM,4BAA4B,GAAG,4CAAqD,CAAC;AAClG,MAAM,CAAC,MAAM,yBAAyB,GAAG,4CAAqD,CAAC;AAC/F,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAE5C,MAAM,UAAU,gBAAgB,CAAC,OAA2B,EAAE,OAAgB;IAC5E,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAC3B,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAChC,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;QACtB,wFAAwF;QACxF,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,CAAC,KAAK,4BAA4B,CAAC,WAAW,EAAE,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolPay Fee Calculator
|
|
3
|
+
* Implements exact percentage cut logic with micro-cent precision.
|
|
4
|
+
*/
|
|
5
|
+
import { PlatformFeeConfig } from '../types/pricing.js';
|
|
6
|
+
export declare const DEFAULT_PLATFORM_FEE_BPS = 300;
|
|
7
|
+
export declare const DEFAULT_PLATFORM_TREASURY_WALLET = "0x1001001001001001001001001001001001001001";
|
|
8
|
+
export interface FeeSplitResult {
|
|
9
|
+
grossUsd: string;
|
|
10
|
+
grossMicro: bigint;
|
|
11
|
+
platformFeeUsd: string;
|
|
12
|
+
platformFeeMicro: bigint;
|
|
13
|
+
platformFeeBasisPoints: number;
|
|
14
|
+
developerPayoutUsd: string;
|
|
15
|
+
developerPayoutMicro: bigint;
|
|
16
|
+
platformTreasuryWallet: string;
|
|
17
|
+
developerWallet: string;
|
|
18
|
+
}
|
|
19
|
+
export declare class FeeCalculator {
|
|
20
|
+
private defaultTreasuryWallet;
|
|
21
|
+
private defaultBasisPoints;
|
|
22
|
+
constructor(defaultTreasuryWallet?: string, defaultBasisPoints?: number);
|
|
23
|
+
/**
|
|
24
|
+
* Calculates the exact platform cut and developer payout for a given transaction.
|
|
25
|
+
*/
|
|
26
|
+
calculateSplit(grossAmountUsdOrMicro: string | number | bigint, developerWallet: string, customFeeConfig?: Partial<PlatformFeeConfig>): FeeSplitResult;
|
|
27
|
+
/**
|
|
28
|
+
* Validates if a proposed payment matches or exceeds the required split.
|
|
29
|
+
*/
|
|
30
|
+
validateSufficientPayment(providedMicro: bigint, requiredMicro: bigint): {
|
|
31
|
+
sufficient: boolean;
|
|
32
|
+
deficitMicro: bigint;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=fee-calculator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fee-calculator.d.ts","sourceRoot":"","sources":["../../src/fee/fee-calculator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAC5C,eAAO,MAAM,gCAAgC,+CAA+C,CAAC;AAE7F,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,kBAAkB,CAAS;gBAGjC,qBAAqB,GAAE,MAAyC,EAChE,kBAAkB,GAAE,MAAiC;IASvD;;OAEG;IACI,cAAc,CACnB,qBAAqB,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAC/C,eAAe,EAAE,MAAM,EACvB,eAAe,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAC3C,cAAc;IA+BjB;;OAEG;IACI,yBAAyB,CAC9B,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,GACpB;QAAE,UAAU,EAAE,OAAO,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE;CASjD"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolPay Fee Calculator
|
|
3
|
+
* Implements exact percentage cut logic with micro-cent precision.
|
|
4
|
+
*/
|
|
5
|
+
import { calculatePlatformCut, usdToMicro, microToUsd, MAX_PLATFORM_FEE_BPS } from '../utils/units.js';
|
|
6
|
+
export const DEFAULT_PLATFORM_FEE_BPS = 300; // 3.00%
|
|
7
|
+
export const DEFAULT_PLATFORM_TREASURY_WALLET = '0x1001001001001001001001001001001001001001';
|
|
8
|
+
export class FeeCalculator {
|
|
9
|
+
defaultTreasuryWallet;
|
|
10
|
+
defaultBasisPoints;
|
|
11
|
+
constructor(defaultTreasuryWallet = DEFAULT_PLATFORM_TREASURY_WALLET, defaultBasisPoints = DEFAULT_PLATFORM_FEE_BPS) {
|
|
12
|
+
if (!Number.isInteger(defaultBasisPoints) || defaultBasisPoints < 0 || defaultBasisPoints > MAX_PLATFORM_FEE_BPS) {
|
|
13
|
+
throw new Error(`Invalid default fee basis points: ${defaultBasisPoints}. Must be integer between 0 and ${MAX_PLATFORM_FEE_BPS}`);
|
|
14
|
+
}
|
|
15
|
+
this.defaultTreasuryWallet = defaultTreasuryWallet;
|
|
16
|
+
this.defaultBasisPoints = defaultBasisPoints;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Calculates the exact platform cut and developer payout for a given transaction.
|
|
20
|
+
*/
|
|
21
|
+
calculateSplit(grossAmountUsdOrMicro, developerWallet, customFeeConfig) {
|
|
22
|
+
const grossMicro = typeof grossAmountUsdOrMicro === 'bigint'
|
|
23
|
+
? grossAmountUsdOrMicro
|
|
24
|
+
: usdToMicro(grossAmountUsdOrMicro);
|
|
25
|
+
const bps = customFeeConfig?.platformFeeBasisPoints ?? this.defaultBasisPoints;
|
|
26
|
+
if (!Number.isInteger(bps) || bps < 0 || bps > MAX_PLATFORM_FEE_BPS) {
|
|
27
|
+
throw new Error(`Invalid fee basis points: ${bps}. Must be integer between 0 and ${MAX_PLATFORM_FEE_BPS}`);
|
|
28
|
+
}
|
|
29
|
+
const treasury = customFeeConfig?.platformTreasuryWallet || this.defaultTreasuryWallet;
|
|
30
|
+
const minFee = customFeeConfig?.minPlatformFeeMicro ?? 0n;
|
|
31
|
+
const { platformFeeMicro, developerPayoutMicro } = calculatePlatformCut(grossMicro, bps, minFee);
|
|
32
|
+
return {
|
|
33
|
+
grossUsd: microToUsd(grossMicro),
|
|
34
|
+
grossMicro,
|
|
35
|
+
platformFeeUsd: microToUsd(platformFeeMicro),
|
|
36
|
+
platformFeeMicro,
|
|
37
|
+
platformFeeBasisPoints: bps,
|
|
38
|
+
developerPayoutUsd: microToUsd(developerPayoutMicro),
|
|
39
|
+
developerPayoutMicro,
|
|
40
|
+
platformTreasuryWallet: treasury,
|
|
41
|
+
developerWallet,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Validates if a proposed payment matches or exceeds the required split.
|
|
46
|
+
*/
|
|
47
|
+
validateSufficientPayment(providedMicro, requiredMicro) {
|
|
48
|
+
if (providedMicro >= requiredMicro) {
|
|
49
|
+
return { sufficient: true, deficitMicro: 0n };
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
sufficient: false,
|
|
53
|
+
deficitMicro: requiredMicro - providedMicro,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=fee-calculator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fee-calculator.js","sourceRoot":"","sources":["../../src/fee/fee-calculator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,UAAU,EAAwB,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAG7H,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC,CAAC,QAAQ;AACrD,MAAM,CAAC,MAAM,gCAAgC,GAAG,4CAA4C,CAAC;AAc7F,MAAM,OAAO,aAAa;IAChB,qBAAqB,CAAS;IAC9B,kBAAkB,CAAS;IAEnC,YACE,wBAAgC,gCAAgC,EAChE,qBAA6B,wBAAwB;QAErD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,kBAAkB,CAAC,IAAI,kBAAkB,GAAG,CAAC,IAAI,kBAAkB,GAAG,oBAAoB,EAAE,CAAC;YACjH,MAAM,IAAI,KAAK,CAAC,qCAAqC,kBAAkB,mCAAmC,oBAAoB,EAAE,CAAC,CAAC;QACpI,CAAC;QACD,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;QACnD,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IAC/C,CAAC;IAED;;OAEG;IACI,cAAc,CACnB,qBAA+C,EAC/C,eAAuB,EACvB,eAA4C;QAE5C,MAAM,UAAU,GAAG,OAAO,qBAAqB,KAAK,QAAQ;YAC1D,CAAC,CAAC,qBAAqB;YACvB,CAAC,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC;QAEtC,MAAM,GAAG,GAAG,eAAe,EAAE,sBAAsB,IAAI,IAAI,CAAC,kBAAkB,CAAC;QAC/E,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,GAAG,GAAG,oBAAoB,EAAE,CAAC;YACpE,MAAM,IAAI,KAAK,CAAC,6BAA6B,GAAG,mCAAmC,oBAAoB,EAAE,CAAC,CAAC;QAC7G,CAAC;QACD,MAAM,QAAQ,GAAG,eAAe,EAAE,sBAAsB,IAAI,IAAI,CAAC,qBAAqB,CAAC;QACvF,MAAM,MAAM,GAAG,eAAe,EAAE,mBAAmB,IAAI,EAAE,CAAC;QAE1D,MAAM,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,GAAG,oBAAoB,CACrE,UAAU,EACV,GAAG,EACH,MAAM,CACP,CAAC;QAEF,OAAO;YACL,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC;YAChC,UAAU;YACV,cAAc,EAAE,UAAU,CAAC,gBAAgB,CAAC;YAC5C,gBAAgB;YAChB,sBAAsB,EAAE,GAAG;YAC3B,kBAAkB,EAAE,UAAU,CAAC,oBAAoB,CAAC;YACpD,oBAAoB;YACpB,sBAAsB,EAAE,QAAQ;YAChC,eAAe;SAChB,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,yBAAyB,CAC9B,aAAqB,EACrB,aAAqB;QAErB,IAAI,aAAa,IAAI,aAAa,EAAE,CAAC;YACnC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;QAChD,CAAC;QACD,OAAO;YACL,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,aAAa,GAAG,aAAa;SAC5C,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolPay In-Memory Financial Ledger & Fee Tracking Engine
|
|
3
|
+
* Records all transaction events, splits, developer balances, and platform cuts.
|
|
4
|
+
*/
|
|
5
|
+
import { TransactionRecord, DeveloperAccountBalance, PlatformTreasurySummary } from '../types/ledger.js';
|
|
6
|
+
import { PaymentScheme } from '../types/x402.js';
|
|
7
|
+
export declare class FeeLedger {
|
|
8
|
+
private transactions;
|
|
9
|
+
private idempotencyMap;
|
|
10
|
+
private developerBalances;
|
|
11
|
+
private platformTreasuryWallet;
|
|
12
|
+
constructor(platformTreasuryWallet: string);
|
|
13
|
+
/**
|
|
14
|
+
* Records a confirmed transaction and updates developer & platform balances.
|
|
15
|
+
* Ensures idempotency: duplicate records with the same idempotency key are safely ignored.
|
|
16
|
+
*/
|
|
17
|
+
recordTransaction(params: {
|
|
18
|
+
transactionId: string;
|
|
19
|
+
serverId: string;
|
|
20
|
+
toolName: string;
|
|
21
|
+
agentWallet: string;
|
|
22
|
+
developerWallet: string;
|
|
23
|
+
scheme: PaymentScheme;
|
|
24
|
+
grossAmountMicro: bigint;
|
|
25
|
+
platformFeeMicro: bigint;
|
|
26
|
+
developerPayoutMicro: bigint;
|
|
27
|
+
platformFeeBasisPoints: number;
|
|
28
|
+
settlementRef?: string;
|
|
29
|
+
idempotencyKey?: string;
|
|
30
|
+
platformTreasuryWallet?: string;
|
|
31
|
+
timestamp?: number;
|
|
32
|
+
}): TransactionRecord;
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves a developer's financial balance.
|
|
35
|
+
*/
|
|
36
|
+
getDeveloperBalance(developerWallet: string): DeveloperAccountBalance;
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves an aggregated summary of the ToolPay Platform Treasury.
|
|
39
|
+
*/
|
|
40
|
+
getPlatformTreasurySummary(): PlatformTreasurySummary;
|
|
41
|
+
/**
|
|
42
|
+
* Processes a developer payout withdrawal.
|
|
43
|
+
*/
|
|
44
|
+
withdrawDeveloperBalance(developerWallet: string, amountMicro?: bigint): {
|
|
45
|
+
withdrawnMicro: bigint;
|
|
46
|
+
remainingBalanceMicro: bigint;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Queries transaction history with filters.
|
|
50
|
+
*/
|
|
51
|
+
queryTransactions(filters?: {
|
|
52
|
+
serverId?: string;
|
|
53
|
+
toolName?: string;
|
|
54
|
+
developerWallet?: string;
|
|
55
|
+
agentWallet?: string;
|
|
56
|
+
}): TransactionRecord[];
|
|
57
|
+
/**
|
|
58
|
+
* Retrieves a transaction record by its unique transaction ID.
|
|
59
|
+
*/
|
|
60
|
+
getTransaction(transactionId: string): TransactionRecord | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Reverses a transaction and updates developer account balance.
|
|
63
|
+
*/
|
|
64
|
+
refundTransaction(transactionId: string): boolean;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=fee-ledger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fee-ledger.d.ts","sourceRoot":"","sources":["../../src/fee/fee-ledger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EAExB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,qBAAa,SAAS;IACpB,OAAO,CAAC,YAAY,CAA6C;IACjE,OAAO,CAAC,cAAc,CAAkC;IACxD,OAAO,CAAC,iBAAiB,CAAmD;IAC5E,OAAO,CAAC,sBAAsB,CAAS;gBAE3B,sBAAsB,EAAE,MAAM;IAI1C;;;OAGG;IACI,iBAAiB,CAAC,MAAM,EAAE;QAC/B,aAAa,EAAE,MAAM,CAAC;QACtB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;QACxB,MAAM,EAAE,aAAa,CAAC;QACtB,gBAAgB,EAAE,MAAM,CAAC;QACzB,gBAAgB,EAAE,MAAM,CAAC;QACzB,oBAAoB,EAAE,MAAM,CAAC;QAC7B,sBAAsB,EAAE,MAAM,CAAC;QAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,cAAc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