t402 1.7.1__py3-none-any.whl → 1.9.1__py3-none-any.whl
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.
- t402/__init__.py +2 -1
- t402/bridge/client.py +13 -5
- t402/bridge/constants.py +3 -1
- t402/bridge/router.py +1 -1
- t402/bridge/scan.py +3 -1
- t402/chains.py +268 -1
- t402/cli.py +31 -9
- t402/common.py +2 -0
- t402/cosmos_paywall_template.py +2 -0
- t402/encoding.py +9 -3
- t402/erc4337/accounts.py +56 -51
- t402/erc4337/bundlers.py +105 -99
- t402/erc4337/paymasters.py +100 -109
- t402/erc4337/types.py +39 -26
- t402/evm_paywall_template.py +1 -1
- t402/fastapi/middleware.py +1 -3
- t402/mcp/server.py +79 -46
- t402/near_paywall_template.py +2 -0
- t402/networks.py +34 -1
- t402/paywall.py +1 -3
- t402/schemes/__init__.py +164 -1
- t402/schemes/aptos/__init__.py +70 -0
- t402/schemes/aptos/constants.py +349 -0
- t402/schemes/aptos/exact_direct/__init__.py +44 -0
- t402/schemes/aptos/exact_direct/client.py +202 -0
- t402/schemes/aptos/exact_direct/facilitator.py +426 -0
- t402/schemes/aptos/exact_direct/server.py +272 -0
- t402/schemes/aptos/types.py +237 -0
- t402/schemes/evm/__init__.py +67 -1
- t402/schemes/evm/exact/__init__.py +11 -0
- t402/schemes/evm/exact/client.py +3 -1
- t402/schemes/evm/exact/facilitator.py +894 -0
- t402/schemes/evm/exact/server.py +1 -1
- t402/schemes/evm/exact_legacy/__init__.py +38 -0
- t402/schemes/evm/exact_legacy/client.py +291 -0
- t402/schemes/evm/exact_legacy/facilitator.py +777 -0
- t402/schemes/evm/exact_legacy/server.py +231 -0
- t402/schemes/evm/upto/__init__.py +70 -0
- t402/schemes/evm/upto/client.py +244 -0
- t402/schemes/evm/upto/facilitator.py +625 -0
- t402/schemes/evm/upto/server.py +243 -0
- t402/schemes/evm/upto/types.py +307 -0
- t402/schemes/interfaces.py +6 -2
- t402/schemes/near/__init__.py +112 -0
- t402/schemes/near/constants.py +189 -0
- t402/schemes/near/exact_direct/__init__.py +21 -0
- t402/schemes/near/exact_direct/client.py +204 -0
- t402/schemes/near/exact_direct/facilitator.py +455 -0
- t402/schemes/near/exact_direct/server.py +303 -0
- t402/schemes/near/types.py +419 -0
- t402/schemes/polkadot/__init__.py +72 -0
- t402/schemes/polkadot/constants.py +155 -0
- t402/schemes/polkadot/exact_direct/__init__.py +43 -0
- t402/schemes/polkadot/exact_direct/client.py +235 -0
- t402/schemes/polkadot/exact_direct/facilitator.py +428 -0
- t402/schemes/polkadot/exact_direct/server.py +292 -0
- t402/schemes/polkadot/types.py +385 -0
- t402/schemes/registry.py +6 -2
- t402/schemes/stacks/__init__.py +68 -0
- t402/schemes/stacks/constants.py +122 -0
- t402/schemes/stacks/exact_direct/__init__.py +43 -0
- t402/schemes/stacks/exact_direct/client.py +222 -0
- t402/schemes/stacks/exact_direct/facilitator.py +424 -0
- t402/schemes/stacks/exact_direct/server.py +292 -0
- t402/schemes/stacks/types.py +380 -0
- t402/schemes/svm/__init__.py +29 -0
- t402/schemes/svm/exact/__init__.py +35 -0
- t402/schemes/svm/exact/client.py +23 -0
- t402/schemes/svm/exact/facilitator.py +24 -0
- t402/schemes/svm/exact/server.py +20 -0
- t402/schemes/tezos/__init__.py +84 -0
- t402/schemes/tezos/constants.py +372 -0
- t402/schemes/tezos/exact_direct/__init__.py +22 -0
- t402/schemes/tezos/exact_direct/client.py +226 -0
- t402/schemes/tezos/exact_direct/facilitator.py +491 -0
- t402/schemes/tezos/exact_direct/server.py +277 -0
- t402/schemes/tezos/types.py +220 -0
- t402/schemes/ton/__init__.py +9 -2
- t402/schemes/ton/exact/__init__.py +7 -0
- t402/schemes/ton/exact/facilitator.py +730 -0
- t402/schemes/ton/exact/server.py +1 -1
- t402/schemes/tron/__init__.py +11 -2
- t402/schemes/tron/exact/__init__.py +9 -0
- t402/schemes/tron/exact/facilitator.py +673 -0
- t402/schemes/tron/exact/server.py +1 -1
- t402/schemes/upto/__init__.py +80 -0
- t402/schemes/upto/types.py +376 -0
- t402/stacks_paywall_template.py +2 -0
- t402/svm.py +45 -11
- t402/svm_paywall_template.py +1 -1
- t402/ton.py +5 -1
- t402/ton_paywall_template.py +1 -192
- t402/tron.py +2 -0
- t402/tron_paywall_template.py +2 -0
- t402/types.py +4 -2
- t402/wdk/errors.py +15 -5
- t402/wdk/signer.py +11 -2
- {t402-1.7.1.dist-info → t402-1.9.1.dist-info}/METADATA +42 -1
- t402-1.9.1.dist-info/RECORD +125 -0
- t402-1.7.1.dist-info/RECORD +0 -67
- {t402-1.7.1.dist-info → t402-1.9.1.dist-info}/WHEEL +0 -0
- {t402-1.7.1.dist-info → t402-1.9.1.dist-info}/entry_points.txt +0 -0
t402/fastapi/middleware.py
CHANGED
|
@@ -266,9 +266,7 @@ class PaymentMiddleware:
|
|
|
266
266
|
|
|
267
267
|
return self
|
|
268
268
|
|
|
269
|
-
async def _dispatch(
|
|
270
|
-
self, request: Request, call_next: Callable
|
|
271
|
-
) -> Response:
|
|
269
|
+
async def _dispatch(self, request: Request, call_next: Callable) -> Response:
|
|
272
270
|
"""Process request through payment middleware.
|
|
273
271
|
|
|
274
272
|
Args:
|
t402/mcp/server.py
CHANGED
|
@@ -170,7 +170,10 @@ class T402McpServer:
|
|
|
170
170
|
else:
|
|
171
171
|
result = self._error_result(f"Unknown tool: {tool_name}")
|
|
172
172
|
|
|
173
|
-
return {
|
|
173
|
+
return {
|
|
174
|
+
"content": [asdict(c) for c in result.content],
|
|
175
|
+
"isError": result.isError,
|
|
176
|
+
}
|
|
174
177
|
|
|
175
178
|
async def _handle_get_balance(self, args: dict[str, Any]) -> ToolResult:
|
|
176
179
|
"""Handle t402/getBalance tool."""
|
|
@@ -255,7 +258,9 @@ class T402McpServer:
|
|
|
255
258
|
)
|
|
256
259
|
return self._text_result(self._format_payment_result(result))
|
|
257
260
|
|
|
258
|
-
return self._error_result(
|
|
261
|
+
return self._error_result(
|
|
262
|
+
"Real transactions require private key configuration"
|
|
263
|
+
)
|
|
259
264
|
|
|
260
265
|
except Exception as e:
|
|
261
266
|
return self._error_result(str(e))
|
|
@@ -266,7 +271,9 @@ class T402McpServer:
|
|
|
266
271
|
network = args.get("network", "")
|
|
267
272
|
|
|
268
273
|
if not is_gasless_network(network):
|
|
269
|
-
return self._error_result(
|
|
274
|
+
return self._error_result(
|
|
275
|
+
f"Network {network} does not support gasless payments"
|
|
276
|
+
)
|
|
270
277
|
|
|
271
278
|
if not self.config.bundler_url and not self.config.demo_mode:
|
|
272
279
|
return self._error_result(
|
|
@@ -300,11 +307,17 @@ class T402McpServer:
|
|
|
300
307
|
amount = args.get("amount", "")
|
|
301
308
|
|
|
302
309
|
if not is_bridgeable_chain(from_chain):
|
|
303
|
-
return self._error_result(
|
|
310
|
+
return self._error_result(
|
|
311
|
+
f"Chain {from_chain} does not support USDT0 bridging"
|
|
312
|
+
)
|
|
304
313
|
if not is_bridgeable_chain(to_chain):
|
|
305
|
-
return self._error_result(
|
|
314
|
+
return self._error_result(
|
|
315
|
+
f"Chain {to_chain} does not support USDT0 bridging"
|
|
316
|
+
)
|
|
306
317
|
if from_chain == to_chain:
|
|
307
|
-
return self._error_result(
|
|
318
|
+
return self._error_result(
|
|
319
|
+
"Source and destination chains must be different"
|
|
320
|
+
)
|
|
308
321
|
|
|
309
322
|
result = BridgeFeeResult(
|
|
310
323
|
native_fee="0.001",
|
|
@@ -327,11 +340,17 @@ class T402McpServer:
|
|
|
327
340
|
amount = args.get("amount", "")
|
|
328
341
|
|
|
329
342
|
if not is_bridgeable_chain(from_chain):
|
|
330
|
-
return self._error_result(
|
|
343
|
+
return self._error_result(
|
|
344
|
+
f"Chain {from_chain} does not support USDT0 bridging"
|
|
345
|
+
)
|
|
331
346
|
if not is_bridgeable_chain(to_chain):
|
|
332
|
-
return self._error_result(
|
|
347
|
+
return self._error_result(
|
|
348
|
+
f"Chain {to_chain} does not support USDT0 bridging"
|
|
349
|
+
)
|
|
333
350
|
if from_chain == to_chain:
|
|
334
|
-
return self._error_result(
|
|
351
|
+
return self._error_result(
|
|
352
|
+
"Source and destination chains must be different"
|
|
353
|
+
)
|
|
335
354
|
|
|
336
355
|
if not self.config.private_key and not self.config.demo_mode:
|
|
337
356
|
return self._error_result(
|
|
@@ -354,7 +373,9 @@ class T402McpServer:
|
|
|
354
373
|
)
|
|
355
374
|
return self._text_result(self._format_bridge_result(result))
|
|
356
375
|
|
|
357
|
-
return self._error_result(
|
|
376
|
+
return self._error_result(
|
|
377
|
+
"Bridge functionality requires private key configuration"
|
|
378
|
+
)
|
|
358
379
|
|
|
359
380
|
except Exception as e:
|
|
360
381
|
return self._error_result(str(e))
|
|
@@ -408,7 +429,9 @@ class T402McpServer:
|
|
|
408
429
|
|
|
409
430
|
lines.append(f"### {result.network}")
|
|
410
431
|
if result.native:
|
|
411
|
-
lines.append(
|
|
432
|
+
lines.append(
|
|
433
|
+
f"- Native ({result.native.token}): {result.native.balance}"
|
|
434
|
+
)
|
|
412
435
|
for token in result.tokens:
|
|
413
436
|
lines.append(f"- {token.token}: {token.balance}")
|
|
414
437
|
lines.append("")
|
|
@@ -420,58 +443,68 @@ class T402McpServer:
|
|
|
420
443
|
lines = []
|
|
421
444
|
|
|
422
445
|
if result.demo_mode:
|
|
423
|
-
lines.extend(
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
446
|
+
lines.extend(
|
|
447
|
+
[
|
|
448
|
+
"## Payment (Demo Mode)",
|
|
449
|
+
"",
|
|
450
|
+
"⚠️ This is a simulated transaction. No actual tokens were transferred.",
|
|
451
|
+
"",
|
|
452
|
+
]
|
|
453
|
+
)
|
|
429
454
|
else:
|
|
430
455
|
lines.extend(["## Payment Successful", ""])
|
|
431
456
|
|
|
432
|
-
lines.extend(
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
457
|
+
lines.extend(
|
|
458
|
+
[
|
|
459
|
+
f"- **Amount:** {result.amount} {result.token}",
|
|
460
|
+
f"- **To:** {result.to}",
|
|
461
|
+
f"- **Network:** {result.network}",
|
|
462
|
+
f"- **Transaction:** [{self._truncate_hash(result.tx_hash)}]({result.explorer_url})",
|
|
463
|
+
]
|
|
464
|
+
)
|
|
438
465
|
|
|
439
466
|
return "\n".join(lines)
|
|
440
467
|
|
|
441
468
|
def _format_bridge_fee_result(self, result: BridgeFeeResult) -> str:
|
|
442
469
|
"""Format bridge fee result as markdown."""
|
|
443
|
-
return "\n".join(
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
470
|
+
return "\n".join(
|
|
471
|
+
[
|
|
472
|
+
"## Bridge Fee Quote",
|
|
473
|
+
"",
|
|
474
|
+
f"- **From:** {result.from_chain}",
|
|
475
|
+
f"- **To:** {result.to_chain}",
|
|
476
|
+
f"- **Amount:** {result.amount} USDT0",
|
|
477
|
+
f"- **Fee:** {result.native_fee} {result.native_symbol}",
|
|
478
|
+
f"- **Estimated Time:** ~{result.estimated_time} seconds",
|
|
479
|
+
]
|
|
480
|
+
)
|
|
452
481
|
|
|
453
482
|
def _format_bridge_result(self, result: BridgeResultData) -> str:
|
|
454
483
|
"""Format bridge result as markdown."""
|
|
455
484
|
lines = []
|
|
456
485
|
|
|
457
486
|
if result.demo_mode:
|
|
458
|
-
lines.extend(
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
487
|
+
lines.extend(
|
|
488
|
+
[
|
|
489
|
+
"## Bridge (Demo Mode)",
|
|
490
|
+
"",
|
|
491
|
+
"⚠️ This is a simulated bridge. No actual tokens were transferred.",
|
|
492
|
+
"",
|
|
493
|
+
]
|
|
494
|
+
)
|
|
464
495
|
else:
|
|
465
496
|
lines.extend(["## Bridge Initiated", ""])
|
|
466
497
|
|
|
467
|
-
lines.extend(
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
498
|
+
lines.extend(
|
|
499
|
+
[
|
|
500
|
+
f"- **Amount:** {result.amount} USDT0",
|
|
501
|
+
f"- **From:** {result.from_chain}",
|
|
502
|
+
f"- **To:** {result.to_chain}",
|
|
503
|
+
f"- **Transaction:** [{self._truncate_hash(result.tx_hash)}]({result.explorer_url})",
|
|
504
|
+
f"- **Track:** [LayerZero Scan]({result.tracking_url})",
|
|
505
|
+
f"- **Estimated Delivery:** ~{result.estimated_time} seconds",
|
|
506
|
+
]
|
|
507
|
+
)
|
|
475
508
|
|
|
476
509
|
return "\n".join(lines)
|
|
477
510
|
|