diff --git a/backend/README.md b/backend/README.md index 2b25105..9b53a3a 100644 --- a/backend/README.md +++ b/backend/README.md @@ -47,6 +47,8 @@ import { OpToJSON } from "userop/dist/utils"; interface EtherspotPaymasterResult { paymasterAndData: string; verificationGasLimit: string; + preVerificationGas: string; + callGasLimit: string; } export const etherspotPaymaster = @@ -58,6 +60,8 @@ export const etherspotPaymaster = body: JSON.stringify({ userOp: OpToJSON(ctx.op), entryPoint: ctx.entryPoint, + context: ctx.context, + chainId: 80001 }) }).then(res => res.json()); @@ -67,19 +71,23 @@ export const etherspotPaymaster = ctx.op.paymasterAndData = pm.paymasterAndData; ctx.op.verificationGasLimit = pm.verificationGasLimit; + ctx.op.preVerificationGas = pm.preVerificationGas; + ctx.op.callGasLimit = pm.callGasLimit; }; ``` Config file should look like this: ```json { - "rpcUrl": "http://127.0.0.1:14337/1", + "rpcUrl": "http://127.0.0.1:14337/80001", "signingKey": "0x...", "entryPoint": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", "EtherspotWalletFactory": "0x27f11918740060bd9Be146086F6836e18eedBB8C", "paymaster": { - "rpcUrl": "http://127.0.0.1:5050", - "context": {} + "rpcUrl": "http://127.0.0.1:5050?apiKey=apiKey&chainId=80001", + "context": { + "mode": "sponsor", + } } } diff --git a/backend/package.json b/backend/package.json index 80b5bc0..33f5736 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "arka", - "version": "1.1.3", + "version": "1.1.4", "description": "This project was bootstrapped with Fastify-CLI.", "type": "module", "directories": { diff --git a/backend/src/routes/index.ts b/backend/src/routes/index.ts index b5d2bde..54521f2 100644 --- a/backend/src/routes/index.ts +++ b/backend/src/routes/index.ts @@ -51,17 +51,17 @@ const routes: FastifyPluginAsync = async (server) => { "/", async function (request, reply) { try { + const query: any = request.query; const body: any = request.body; - const date = new Date(); if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.EMPTY_BODY }); const userOp = body.params[0]; const entryPoint = body.params[1]; const context = body.params[2]; const gasToken = context?.token ? context.token : null; const mode = context?.mode ? String(context.mode) : null; - const chainId = body.params[3]; - const api_key = body.params[4]; - if (!api_key) + const chainId = query['chainId']; + const api_key = query['apiKey']; + if (!api_key) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY }) const AWSresponse = await client.send( new GetSecretValueCommand({ @@ -88,8 +88,8 @@ const routes: FastifyPluginAsync = async (server) => { return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK }); } if ( - mode.toLowerCase() == 'erc20' && - !(TOKEN_ADDRESS[chainId] && TOKEN_ADDRESS[chainId][gasToken]) && + mode.toLowerCase() == 'erc20' && + !(TOKEN_ADDRESS[chainId] && TOKEN_ADDRESS[chainId][gasToken]) && !(customPaymasters[chainId] && customPaymasters[chainId][gasToken]) ) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK_TOKEN }) const networkConfig = getNetworkConfig(chainId, secrets['SUPPORTED_NETWORKS'] ?? ''); @@ -97,13 +97,22 @@ const routes: FastifyPluginAsync = async (server) => { let result; switch (mode.toLowerCase()) { case 'sponsor': { - const hex = (Number((date.valueOf() / 1000).toFixed(0)) + 600).toString(16); + const date = new Date(); + const validUntil = context.validUntil ? new Date(context.validUntil) : date; + const validAfter = context.validAfter ? new Date(context.validAfter) : date; + const hex = (Number((validUntil.valueOf() / 1000).toFixed(0)) + 600).toString(16); + const hex1 = (Number((validAfter.valueOf() / 1000).toFixed(0))).toString(16); let str = '0x' + let str1 = '0x' for (let i = 0; i < 14 - hex.length; i++) { str += '0'; } + for (let i = 0; i < 14 - hex1.length; i++) { + str1 += '0'; + } str += hex; - result = await paymaster.sign(userOp, str, "0x0000000000001234", entryPoint, networkConfig.contracts.etherspotPaymasterAddress, networkConfig.bundler, secrets['PRIVATE_KEY']); + str1 += hex1; + result = await paymaster.sign(userOp, str, str1, entryPoint, networkConfig.contracts.etherspotPaymasterAddress, networkConfig.bundler, secrets['PRIVATE_KEY']); break; } case 'erc20': { @@ -131,13 +140,14 @@ const routes: FastifyPluginAsync = async (server) => { whitelistResponseSchema, async function (request, reply) { try { + const query: any = request.query; const body: any = request.body; const entryPoint = body.params[0]; const context = body.params[1]; const gasToken = context ? context.token : null; - const chainId = body.params[2]; - const api_key = body.params[3]; - if (!api_key) + const chainId = query['chainId']; + const api_key = query['apiKey']; + if (!api_key) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY }) const AWSresponse = await client.send( new GetSecretValueCommand({ @@ -165,7 +175,7 @@ const routes: FastifyPluginAsync = async (server) => { customPaymasters = JSON.parse(buffer.toString()); } let result; - if (customPaymasters[chainId] && customPaymasters[chainId][gasToken]) result = { message: customPaymasters[chainId][gasToken]} + if (customPaymasters[chainId] && customPaymasters[chainId][gasToken]) result = { message: customPaymasters[chainId][gasToken] } else { if (!(TOKEN_ADDRESS[chainId] && TOKEN_ADDRESS[chainId][gasToken])) return reply.code(ReturnCode.FAILURE).send({ error: "Invalid network/token" }) result = await paymaster.pimlicoAddress(gasToken, networkConfig.bundler, entryPoint); @@ -187,13 +197,13 @@ const routes: FastifyPluginAsync = async (server) => { async function (request, reply) { try { const body: any = request.body; - + const query: any = request.query; const userOp = body.params[0]; const entryPoint = body.params[1]; const context = body.params[2]; const gasToken = context ? context.token : null; - const api_key = body.params[3]; - if (!api_key) + const api_key = query['apiKey']; + if (!api_key) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY }) const AWSresponse = await client.send( new GetSecretValueCommand({ @@ -227,11 +237,11 @@ const routes: FastifyPluginAsync = async (server) => { async function (request, reply) { try { const body: any = request.body; - + const query: any = request.query; const address = body.params[0]; - const chainId = body.params[1]; - const api_key = body.params[2]; - if (!api_key) + const chainId = query['chainId']; + const api_key = query['apiKey']; + if (!api_key) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY }) const AWSresponse = await client.send( new GetSecretValueCommand({ @@ -273,12 +283,12 @@ const routes: FastifyPluginAsync = async (server) => { async function (request, reply) { try { const body: any = request.body; - + const query: any = request.query; const sponsorAddress = body.params[0]; const accountAddress = body.params[1]; - const chainId = body.params[2]; - const api_key = body.params[3]; - if (!api_key) + const chainId = query['chainId']; + const api_key = query['apiKey']; + if (!api_key) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY }) const AWSresponse = await client.send( new GetSecretValueCommand({ @@ -321,11 +331,11 @@ const routes: FastifyPluginAsync = async (server) => { async function (request, reply) { try { const body: any = request.body; - + const query: any = request.query; const amount = body.params[0]; - const chainId = body.params[1]; - const api_key = body.params[2]; - if (!api_key) + const chainId = query['chainId']; + const api_key = query['apiKey']; + if (!api_key) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY }) const AWSresponse = await client.send( new GetSecretValueCommand({