Skip to content

Commit

Permalink
PRO-1967 - Github Issues (#27)
Browse files Browse the repository at this point in the history
* Updated chainId and apiKey as queryString
  • Loading branch information
vignesha22 authored Nov 13, 2023
1 parent 8f8a126 commit 69e103b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 31 deletions.
14 changes: 11 additions & 3 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import { OpToJSON } from "userop/dist/utils";
interface EtherspotPaymasterResult {
paymasterAndData: string;
verificationGasLimit: string;
preVerificationGas: string;
callGasLimit: string;
}

export const etherspotPaymaster =
Expand All @@ -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());

Expand All @@ -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",
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
64 changes: 37 additions & 27 deletions backend/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -88,22 +88,31 @@ 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'] ?? '');
if (!networkConfig) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK });
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': {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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);
Expand All @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 69e103b

Please sign in to comment.