From ca1390acd0dde027160b67dc3cfe960c0a4b61d5 Mon Sep 17 00:00:00 2001 From: Vignesh Date: Tue, 11 Jun 2024 14:00:58 +0530 Subject: [PATCH] added fix for deposit/v2 --- backend/src/paymaster/index.ts | 6 +++--- backend/src/routes/index.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/paymaster/index.ts b/backend/src/paymaster/index.ts index b81933d..92e7ac4 100644 --- a/backend/src/paymaster/index.ts +++ b/backend/src/paymaster/index.ts @@ -417,17 +417,17 @@ export class Paymaster { } } - async deposit(amount: string, paymasterAddress: string, bundlerRpc: string, relayerKey: string, chainId: number, log?: FastifyBaseLogger) { + async deposit(amount: string, paymasterAddress: string, bundlerRpc: string, relayerKey: string, chainId: number, isEpv06: boolean, log?: FastifyBaseLogger) { try { const provider = new providers.JsonRpcProvider(bundlerRpc); - const paymasterContract = new ethers.Contract(paymasterAddress, EtherspotAbiV06, provider); + const paymasterContract = new ethers.Contract(paymasterAddress, isEpv06 ? EtherspotAbiV06 : EtherspotAbiV07, provider); const signer = new Wallet(relayerKey, provider) const balance = await signer.getBalance(); const amountInWei = ethers.utils.parseEther(amount.toString()); if (amountInWei.gte(balance)) throw new Error(`${signer.address} Balance is less than the amount to be deposited`) - const encodedData = paymasterContract.interface.encodeFunctionData('depositFunds', []); + const encodedData = paymasterContract.interface.encodeFunctionData(isEpv06 ? 'depositFunds': 'deposit', []); const etherscanFeeData = await getEtherscanFee(chainId); console.log('etherscanFeeData: ', etherscanFeeData); diff --git a/backend/src/routes/index.ts b/backend/src/routes/index.ts index 824358f..2e467a1 100644 --- a/backend/src/routes/index.ts +++ b/backend/src/routes/index.ts @@ -558,7 +558,7 @@ const routes: FastifyPluginAsync = async (server) => { } const networkConfig = getNetworkConfig(chainId, supportedNetworks ?? '', SUPPORTED_ENTRYPOINTS.EPV_06); if (!networkConfig) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK }); - return await paymaster.deposit(amount, networkConfig.contracts.etherspotPaymasterAddress, networkConfig.bundler, privateKey, chainId, server.log); + return await paymaster.deposit(amount, networkConfig.contracts.etherspotPaymasterAddress, networkConfig.bundler, privateKey, chainId, true, server.log); } catch (err: any) { request.log.error(err); if (err.name == "ResourceNotFoundException") @@ -611,7 +611,7 @@ const routes: FastifyPluginAsync = async (server) => { } const networkConfig = getNetworkConfig(chainId, supportedNetworks ?? '', SUPPORTED_ENTRYPOINTS.EPV_07); if (!networkConfig) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK }); - return await paymaster.deposit(amount, networkConfig.contracts.etherspotPaymasterAddress, networkConfig.bundler, privateKey, chainId, server.log); + return await paymaster.deposit(amount, networkConfig.contracts.etherspotPaymasterAddress, networkConfig.bundler, privateKey, chainId, false, server.log); } catch (err: any) { request.log.error(err); if (err.name == "ResourceNotFoundException")