Skip to content

Commit f405e4f

Browse files
add eth_getApproveAmount
1 parent 0a728da commit f405e4f

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

bundler/paymaster.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,32 @@ def eth_paymaster(request, token) -> Result:
6666
result.append(paymasterData)
6767
return Success(result)
6868

69+
@method
70+
def eth_getApproveAmount(request, token) -> Result:
71+
token_object = ERC20ApprovedToken.objects.filter(address = token)
72+
73+
if(len(token_object) < 1 or not token_object.first().isActive):
74+
return Error(2, "Unsupported token", data="")
75+
76+
token = token_object.first()
77+
78+
total = 0
79+
for op in request:
80+
callGas = int(op['callGas'])
81+
verificationGas = int(op['verificationGas'])
82+
preVerificationGas = int(op['preVerificationGas'])
83+
maxFeePerGas = int(op['maxFeePerGas'])
84+
85+
operationMaxEthCostUsingPaymaster = (callGas + verificationGas * 3 + preVerificationGas) * maxFeePerGas
86+
87+
tokenToEthPrice = token.tokenToEthPrice #tokenToEthPrice conversionRate
88+
maxTokenCost = int(operationMaxEthCostUsingPaymaster * (tokenToEthPrice / 10**18))
89+
90+
total = total + maxTokenCost
91+
92+
#todo: fetch and substract the contract allowance to the paymaster for the final result
93+
return Success(total)
94+
6995
@method
7096
def eth_paymaster_approved_tokens() -> Result:
7197
aprrovedTokens = ERC20ApprovedToken.objects.filter(isActive = True)

0 commit comments

Comments
 (0)