t402 1.1.0__py3-none-any.whl → 1.3.0__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 +85 -0
- t402/common.py +26 -1
- t402/erc4337/__init__.py +188 -0
- t402/erc4337/accounts.py +434 -0
- t402/erc4337/bundlers.py +458 -0
- t402/erc4337/paymasters.py +532 -0
- t402/erc4337/types.py +315 -0
- t402/networks.py +33 -3
- t402/tron.py +578 -0
- t402/types.py +41 -1
- {t402-1.1.0.dist-info → t402-1.3.0.dist-info}/METADATA +2 -2
- {t402-1.1.0.dist-info → t402-1.3.0.dist-info}/RECORD +13 -7
- {t402-1.1.0.dist-info → t402-1.3.0.dist-info}/WHEEL +0 -0
t402/__init__.py
CHANGED
|
@@ -7,6 +7,7 @@ from t402.common import (
|
|
|
7
7
|
)
|
|
8
8
|
from t402.networks import (
|
|
9
9
|
is_ton_network,
|
|
10
|
+
is_tron_network,
|
|
10
11
|
is_evm_network,
|
|
11
12
|
get_network_type,
|
|
12
13
|
)
|
|
@@ -17,6 +18,8 @@ from t402.types import (
|
|
|
17
18
|
SettleResponse,
|
|
18
19
|
TonAuthorization,
|
|
19
20
|
TonPaymentPayload,
|
|
21
|
+
TronAuthorization,
|
|
22
|
+
TronPaymentPayload,
|
|
20
23
|
)
|
|
21
24
|
from t402.facilitator import FacilitatorClient, FacilitatorConfig
|
|
22
25
|
from t402.exact import (
|
|
@@ -40,11 +43,54 @@ from t402.ton import (
|
|
|
40
43
|
validate_boc,
|
|
41
44
|
is_testnet as is_ton_testnet,
|
|
42
45
|
)
|
|
46
|
+
from t402.tron import (
|
|
47
|
+
TRON_MAINNET,
|
|
48
|
+
TRON_NILE,
|
|
49
|
+
TRON_SHASTA,
|
|
50
|
+
USDT_MAINNET_ADDRESS as TRON_USDT_MAINNET_ADDRESS,
|
|
51
|
+
USDT_NILE_ADDRESS as TRON_USDT_NILE_ADDRESS,
|
|
52
|
+
USDT_SHASTA_ADDRESS as TRON_USDT_SHASTA_ADDRESS,
|
|
53
|
+
validate_tron_address,
|
|
54
|
+
get_usdt_address as get_tron_usdt_address,
|
|
55
|
+
get_network_config as get_tron_network_config,
|
|
56
|
+
get_default_asset as get_tron_default_asset,
|
|
57
|
+
prepare_tron_payment_header,
|
|
58
|
+
parse_amount as parse_tron_amount,
|
|
59
|
+
format_amount as format_tron_amount,
|
|
60
|
+
is_testnet as is_tron_testnet,
|
|
61
|
+
)
|
|
43
62
|
from t402.paywall import (
|
|
44
63
|
get_paywall_html,
|
|
45
64
|
get_paywall_template,
|
|
46
65
|
is_browser_request,
|
|
47
66
|
)
|
|
67
|
+
from t402.erc4337 import (
|
|
68
|
+
# Constants
|
|
69
|
+
ENTRYPOINT_V07_ADDRESS,
|
|
70
|
+
ENTRYPOINT_V06_ADDRESS,
|
|
71
|
+
SAFE_4337_ADDRESSES,
|
|
72
|
+
SUPPORTED_CHAINS as ERC4337_SUPPORTED_CHAINS,
|
|
73
|
+
# Types
|
|
74
|
+
UserOperation,
|
|
75
|
+
PackedUserOperation,
|
|
76
|
+
PaymasterData,
|
|
77
|
+
GasEstimate,
|
|
78
|
+
UserOperationReceipt,
|
|
79
|
+
# Bundlers
|
|
80
|
+
GenericBundlerClient,
|
|
81
|
+
PimlicoBundlerClient,
|
|
82
|
+
AlchemyBundlerClient,
|
|
83
|
+
create_bundler_client,
|
|
84
|
+
# Paymasters
|
|
85
|
+
PimlicoPaymaster,
|
|
86
|
+
BiconomyPaymaster,
|
|
87
|
+
StackupPaymaster,
|
|
88
|
+
create_paymaster,
|
|
89
|
+
# Accounts
|
|
90
|
+
SafeSmartAccount,
|
|
91
|
+
SafeAccountConfig,
|
|
92
|
+
create_smart_account,
|
|
93
|
+
)
|
|
48
94
|
|
|
49
95
|
def hello() -> str:
|
|
50
96
|
return "Hello from t402!"
|
|
@@ -60,6 +106,7 @@ __all__ = [
|
|
|
60
106
|
"find_matching_payment_requirements",
|
|
61
107
|
# Network utilities
|
|
62
108
|
"is_ton_network",
|
|
109
|
+
"is_tron_network",
|
|
63
110
|
"is_evm_network",
|
|
64
111
|
"get_network_type",
|
|
65
112
|
# Types
|
|
@@ -69,6 +116,8 @@ __all__ = [
|
|
|
69
116
|
"SettleResponse",
|
|
70
117
|
"TonAuthorization",
|
|
71
118
|
"TonPaymentPayload",
|
|
119
|
+
"TronAuthorization",
|
|
120
|
+
"TronPaymentPayload",
|
|
72
121
|
# Facilitator
|
|
73
122
|
"FacilitatorClient",
|
|
74
123
|
"FacilitatorConfig",
|
|
@@ -91,8 +140,44 @@ __all__ = [
|
|
|
91
140
|
"format_ton_amount",
|
|
92
141
|
"validate_boc",
|
|
93
142
|
"is_ton_testnet",
|
|
143
|
+
# TRON utilities
|
|
144
|
+
"TRON_MAINNET",
|
|
145
|
+
"TRON_NILE",
|
|
146
|
+
"TRON_SHASTA",
|
|
147
|
+
"TRON_USDT_MAINNET_ADDRESS",
|
|
148
|
+
"TRON_USDT_NILE_ADDRESS",
|
|
149
|
+
"TRON_USDT_SHASTA_ADDRESS",
|
|
150
|
+
"validate_tron_address",
|
|
151
|
+
"get_tron_usdt_address",
|
|
152
|
+
"get_tron_network_config",
|
|
153
|
+
"get_tron_default_asset",
|
|
154
|
+
"prepare_tron_payment_header",
|
|
155
|
+
"parse_tron_amount",
|
|
156
|
+
"format_tron_amount",
|
|
157
|
+
"is_tron_testnet",
|
|
94
158
|
# Paywall
|
|
95
159
|
"get_paywall_html",
|
|
96
160
|
"get_paywall_template",
|
|
97
161
|
"is_browser_request",
|
|
162
|
+
# ERC-4337 Account Abstraction
|
|
163
|
+
"ENTRYPOINT_V07_ADDRESS",
|
|
164
|
+
"ENTRYPOINT_V06_ADDRESS",
|
|
165
|
+
"SAFE_4337_ADDRESSES",
|
|
166
|
+
"ERC4337_SUPPORTED_CHAINS",
|
|
167
|
+
"UserOperation",
|
|
168
|
+
"PackedUserOperation",
|
|
169
|
+
"PaymasterData",
|
|
170
|
+
"GasEstimate",
|
|
171
|
+
"UserOperationReceipt",
|
|
172
|
+
"GenericBundlerClient",
|
|
173
|
+
"PimlicoBundlerClient",
|
|
174
|
+
"AlchemyBundlerClient",
|
|
175
|
+
"create_bundler_client",
|
|
176
|
+
"PimlicoPaymaster",
|
|
177
|
+
"BiconomyPaymaster",
|
|
178
|
+
"StackupPaymaster",
|
|
179
|
+
"create_paymaster",
|
|
180
|
+
"SafeSmartAccount",
|
|
181
|
+
"SafeAccountConfig",
|
|
182
|
+
"create_smart_account",
|
|
98
183
|
]
|
t402/common.py
CHANGED
|
@@ -8,7 +8,7 @@ from t402.chains import (
|
|
|
8
8
|
get_token_version,
|
|
9
9
|
get_default_token_address,
|
|
10
10
|
)
|
|
11
|
-
from t402.networks import is_ton_network
|
|
11
|
+
from t402.networks import is_ton_network, is_tron_network
|
|
12
12
|
from t402.types import Price, TokenAmount, PaymentRequirements, PaymentPayload
|
|
13
13
|
|
|
14
14
|
|
|
@@ -27,6 +27,10 @@ def parse_money(amount: str | int, address: str, network: str) -> int:
|
|
|
27
27
|
if is_ton_network(network):
|
|
28
28
|
from t402.ton import DEFAULT_DECIMALS
|
|
29
29
|
decimals = DEFAULT_DECIMALS # USDT on TON uses 6 decimals
|
|
30
|
+
# Handle TRON networks
|
|
31
|
+
elif is_tron_network(network):
|
|
32
|
+
from t402.tron import DEFAULT_DECIMALS
|
|
33
|
+
decimals = DEFAULT_DECIMALS # USDT on TRON uses 6 decimals
|
|
30
34
|
else:
|
|
31
35
|
chain_id = get_chain_id(network)
|
|
32
36
|
decimals = get_token_decimals(chain_id, address)
|
|
@@ -81,6 +85,27 @@ def process_price_to_atomic_amount(
|
|
|
81
85
|
|
|
82
86
|
return str(atomic_amount), asset_address, extra_info
|
|
83
87
|
|
|
88
|
+
# Handle TRON networks
|
|
89
|
+
if is_tron_network(network):
|
|
90
|
+
from t402.tron import (
|
|
91
|
+
get_usdt_address as get_tron_usdt_address,
|
|
92
|
+
get_default_asset as get_tron_default_asset,
|
|
93
|
+
DEFAULT_DECIMALS,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
asset_address = get_tron_usdt_address(network)
|
|
97
|
+
decimals = DEFAULT_DECIMALS
|
|
98
|
+
atomic_amount = int(amount * Decimal(10**decimals))
|
|
99
|
+
|
|
100
|
+
# For TRON, return TRC20 metadata
|
|
101
|
+
asset_info = get_tron_default_asset(network)
|
|
102
|
+
extra_info = {
|
|
103
|
+
"name": asset_info["name"] if asset_info else "Tether USD",
|
|
104
|
+
"symbol": asset_info["symbol"] if asset_info else "USDT",
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return str(atomic_amount), asset_address, extra_info
|
|
108
|
+
|
|
84
109
|
# Handle EVM networks
|
|
85
110
|
chain_id = get_chain_id(network)
|
|
86
111
|
asset_address = get_usdc_address(chain_id)
|
t402/erc4337/__init__.py
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ERC-4337 Account Abstraction Module for T402
|
|
3
|
+
|
|
4
|
+
This module provides complete ERC-4337 v0.7 support including:
|
|
5
|
+
- UserOperation building and signing
|
|
6
|
+
- Bundler clients (generic, Pimlico, Alchemy)
|
|
7
|
+
- Paymaster integration (Pimlico, Biconomy, Stackup)
|
|
8
|
+
- Smart account implementations (Safe)
|
|
9
|
+
|
|
10
|
+
Example usage:
|
|
11
|
+
|
|
12
|
+
from t402.erc4337 import (
|
|
13
|
+
UserOperation,
|
|
14
|
+
create_bundler_client,
|
|
15
|
+
create_paymaster,
|
|
16
|
+
SafeSmartAccount,
|
|
17
|
+
SafeAccountConfig,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
# Create a Safe smart account
|
|
21
|
+
account = SafeSmartAccount(SafeAccountConfig(
|
|
22
|
+
owner_private_key="0x...",
|
|
23
|
+
chain_id=84532, # Base Sepolia
|
|
24
|
+
))
|
|
25
|
+
|
|
26
|
+
# Create a bundler client
|
|
27
|
+
bundler = create_bundler_client(
|
|
28
|
+
provider="pimlico",
|
|
29
|
+
api_key="your-api-key",
|
|
30
|
+
chain_id=84532,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# Create a paymaster
|
|
34
|
+
paymaster = create_paymaster(
|
|
35
|
+
provider="pimlico",
|
|
36
|
+
api_key="your-api-key",
|
|
37
|
+
chain_id=84532,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# Build and submit a UserOperation
|
|
41
|
+
user_op = UserOperation(
|
|
42
|
+
sender=account.get_address(),
|
|
43
|
+
call_data=account.encode_execute(
|
|
44
|
+
target="0x...",
|
|
45
|
+
value=0,
|
|
46
|
+
data=b"...",
|
|
47
|
+
),
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# Get gas estimates and paymaster data
|
|
51
|
+
gas = bundler.estimate_user_operation_gas(user_op)
|
|
52
|
+
pm_data = paymaster.get_paymaster_data(user_op, 84532, ENTRYPOINT_V07_ADDRESS)
|
|
53
|
+
|
|
54
|
+
# Update user_op with estimates and sign
|
|
55
|
+
user_op.verification_gas_limit = gas.verification_gas_limit
|
|
56
|
+
user_op.call_gas_limit = gas.call_gas_limit
|
|
57
|
+
user_op.pre_verification_gas = gas.pre_verification_gas
|
|
58
|
+
user_op.paymaster_and_data = pm_data.to_bytes()
|
|
59
|
+
user_op.signature = account.sign_user_op_hash(user_op_hash)
|
|
60
|
+
|
|
61
|
+
# Submit
|
|
62
|
+
user_op_hash = bundler.send_user_operation(user_op)
|
|
63
|
+
receipt = bundler.wait_for_receipt(user_op_hash)
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
# Types
|
|
67
|
+
from .types import (
|
|
68
|
+
# Constants
|
|
69
|
+
ENTRYPOINT_V07_ADDRESS,
|
|
70
|
+
ENTRYPOINT_V06_ADDRESS,
|
|
71
|
+
SAFE_4337_ADDRESSES,
|
|
72
|
+
SUPPORTED_CHAINS,
|
|
73
|
+
ALCHEMY_NETWORKS,
|
|
74
|
+
PIMLICO_NETWORKS,
|
|
75
|
+
DEFAULT_GAS_LIMITS,
|
|
76
|
+
BUNDLER_METHODS,
|
|
77
|
+
# Enums
|
|
78
|
+
PaymasterType,
|
|
79
|
+
# Dataclasses
|
|
80
|
+
UserOperation,
|
|
81
|
+
PackedUserOperation,
|
|
82
|
+
PaymasterData,
|
|
83
|
+
GasEstimate,
|
|
84
|
+
UserOperationReceipt,
|
|
85
|
+
BundlerConfig,
|
|
86
|
+
PaymasterConfig,
|
|
87
|
+
TokenQuote,
|
|
88
|
+
AssetChange,
|
|
89
|
+
SimulationResult,
|
|
90
|
+
# Functions
|
|
91
|
+
pack_account_gas_limits,
|
|
92
|
+
unpack_account_gas_limits,
|
|
93
|
+
pack_gas_fees,
|
|
94
|
+
unpack_gas_fees,
|
|
95
|
+
is_supported_chain,
|
|
96
|
+
get_alchemy_network,
|
|
97
|
+
get_pimlico_network,
|
|
98
|
+
get_dummy_signature,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
# Bundlers
|
|
102
|
+
from .bundlers import (
|
|
103
|
+
BundlerError,
|
|
104
|
+
GenericBundlerClient,
|
|
105
|
+
PimlicoBundlerClient,
|
|
106
|
+
PimlicoGasPrice,
|
|
107
|
+
AlchemyBundlerClient,
|
|
108
|
+
AlchemyPolicyConfig,
|
|
109
|
+
GasAndPaymasterResult,
|
|
110
|
+
create_bundler_client,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
# Paymasters
|
|
114
|
+
from .paymasters import (
|
|
115
|
+
PaymasterError,
|
|
116
|
+
PaymasterClient,
|
|
117
|
+
PimlicoPaymaster,
|
|
118
|
+
BiconomyPaymaster,
|
|
119
|
+
StackupPaymaster,
|
|
120
|
+
UnifiedPaymaster,
|
|
121
|
+
create_paymaster,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
# Accounts
|
|
125
|
+
from .accounts import (
|
|
126
|
+
SmartAccountError,
|
|
127
|
+
SmartAccountSigner,
|
|
128
|
+
SafeSmartAccount,
|
|
129
|
+
SafeAccountConfig,
|
|
130
|
+
create_smart_account,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
__all__ = [
|
|
134
|
+
# Constants
|
|
135
|
+
"ENTRYPOINT_V07_ADDRESS",
|
|
136
|
+
"ENTRYPOINT_V06_ADDRESS",
|
|
137
|
+
"SAFE_4337_ADDRESSES",
|
|
138
|
+
"SUPPORTED_CHAINS",
|
|
139
|
+
"ALCHEMY_NETWORKS",
|
|
140
|
+
"PIMLICO_NETWORKS",
|
|
141
|
+
"DEFAULT_GAS_LIMITS",
|
|
142
|
+
"BUNDLER_METHODS",
|
|
143
|
+
# Enums
|
|
144
|
+
"PaymasterType",
|
|
145
|
+
# Types
|
|
146
|
+
"UserOperation",
|
|
147
|
+
"PackedUserOperation",
|
|
148
|
+
"PaymasterData",
|
|
149
|
+
"GasEstimate",
|
|
150
|
+
"UserOperationReceipt",
|
|
151
|
+
"BundlerConfig",
|
|
152
|
+
"PaymasterConfig",
|
|
153
|
+
"TokenQuote",
|
|
154
|
+
"AssetChange",
|
|
155
|
+
"SimulationResult",
|
|
156
|
+
# Functions
|
|
157
|
+
"pack_account_gas_limits",
|
|
158
|
+
"unpack_account_gas_limits",
|
|
159
|
+
"pack_gas_fees",
|
|
160
|
+
"unpack_gas_fees",
|
|
161
|
+
"is_supported_chain",
|
|
162
|
+
"get_alchemy_network",
|
|
163
|
+
"get_pimlico_network",
|
|
164
|
+
"get_dummy_signature",
|
|
165
|
+
# Bundlers
|
|
166
|
+
"BundlerError",
|
|
167
|
+
"GenericBundlerClient",
|
|
168
|
+
"PimlicoBundlerClient",
|
|
169
|
+
"PimlicoGasPrice",
|
|
170
|
+
"AlchemyBundlerClient",
|
|
171
|
+
"AlchemyPolicyConfig",
|
|
172
|
+
"GasAndPaymasterResult",
|
|
173
|
+
"create_bundler_client",
|
|
174
|
+
# Paymasters
|
|
175
|
+
"PaymasterError",
|
|
176
|
+
"PaymasterClient",
|
|
177
|
+
"PimlicoPaymaster",
|
|
178
|
+
"BiconomyPaymaster",
|
|
179
|
+
"StackupPaymaster",
|
|
180
|
+
"UnifiedPaymaster",
|
|
181
|
+
"create_paymaster",
|
|
182
|
+
# Accounts
|
|
183
|
+
"SmartAccountError",
|
|
184
|
+
"SmartAccountSigner",
|
|
185
|
+
"SafeSmartAccount",
|
|
186
|
+
"SafeAccountConfig",
|
|
187
|
+
"create_smart_account",
|
|
188
|
+
]
|