@@ -22,9 +22,10 @@ def eth_paymaster(request, token) -> Result:
2222 token_object = ERC20ApprovedToken .objects .filter (address = token )
2323
2424 if (len (token_object ) < 1 or not token_object .first ().isActive ):
25- print ("No token" )
2625 return Error (2 , "Unsupported token" , data = "" )
2726
27+ token = token_object .first ()
28+
2829 serialzer = OperationSerialzer (data = request , many = True )
2930
3031 if serialzer .is_valid ():
@@ -39,11 +40,19 @@ def eth_paymaster(request, token) -> Result:
3940 for operation in ops :
4041 op = dict (operation )
4142
42- maxTokenCost = (int (op ['maxFeePerGas' ]) * (int (op ['callGas' ]) + int (op ['verificationGas' ]) * 3 + int (op ['preVerificationGas' ])))
43+ maxFeePerGas = int (op ['maxFeePerGas' ])
44+ callGas = int (op ['callGas' ])
45+ verificationGas = int (op ['verificationGas' ])
46+ preVerificationGas = int (op ['preVerificationGas' ])
47+
48+ operationMaxEthCostUsingPaymaster = (callGas + verificationGas * 3 + preVerificationGas ) * maxFeePerGas
49+
50+ tokenAddress = token .address
51+ tokenToEthPrice = token .tokenToEthPrice #tokenToEthPrice conversionRate
52+ maxTokenCost = int (operationMaxEthCostUsingPaymaster * (tokenToEthPrice / 10 ** 18 ))
4353 maxTokenCostHex = str ("{0:0{1}x}" .format (maxTokenCost ,40 ))
4454
45- #TODO : compute dynamically
46- costOfPost = 10 ** 10
55+ costOfPost = verificationGas * maxFeePerGas
4756 costOfPostHex = str ("{0:0{1}x}" .format (costOfPost ,40 ))
4857
4958 abiEncoded = eth_abi .encode_abi (
@@ -58,12 +67,12 @@ def eth_paymaster(request, token) -> Result:
5867 w3 .solidityKeccak (['bytes' ], [op ['callData' ]]),
5968 op ['callGas' ],op ['verificationGas' ],op ['preVerificationGas' ],op ['maxFeePerGas' ],
6069 op ['maxPriorityFeePerGas' ], op ['paymaster' ],
61- maxTokenCost , costOfPost , token ])
70+ maxTokenCost , costOfPost , tokenAddress ])
6271 hash = w3 .solidityKeccak (['bytes' ], ['0x' + abiEncoded .hex ()])
6372 sig = bundlerSigner .signHash (hash )
64- paymasterData = maxTokenCostHex + costOfPostHex + token [2 :] + sig .signature .hex ()[2 :]
65- print ('\033 [92m' + "Paymaster data : " + paymasterData + '\033 [4m' )
73+ paymasterData = maxTokenCostHex + costOfPostHex + tokenAddress [2 :] + sig .signature .hex ()[2 :]
6674 result .append (paymasterData )
75+
6776 return Success (result )
6877
6978@method
0 commit comments