Skip to content

Commit

Permalink
Release 11-02-2025 (#183)
Browse files Browse the repository at this point in the history
* ft: using skandha for gas data

* Empty Body Fix (#180)

---------

Co-authored-by: Nikhil Kumar <[email protected]>
  • Loading branch information
vignesha22 and nikhilkumar1612 authored Feb 12, 2025
1 parent d8c24cc commit c01bff3
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function up({ context: queryInterface }) {

async function down({ context: queryInterface }) {
await queryInterface.sequelize.query(
`UPDATE ${process.env.DATABASE_SCHEMA_NAME}."api_keys" SET "VERIFYING_PAYMASTERS_V2"=${null} WHERE "API_KEYS"='arka_public_key'`
`UPDATE ${process.env.DATABASE_SCHEMA_NAME}."api_keys" SET "VERIFYING_PAYMASTERS_V2"=${null} WHERE "API_KEY"='arka_public_key'`
);
}

Expand Down
20 changes: 20 additions & 0 deletions backend/migrations/20250203163722-update-public-key.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require('dotenv').config();
const publicKey = 'etherspot_public_key';
const oldPublicKey = 'arka_public_key';
async function up({ context: queryInterface }) {
await queryInterface.sequelize.query(
`UPDATE ${process.env.DATABASE_SCHEMA_NAME}."api_keys" SET "API_KEY"='${publicKey}' WHERE "API_KEY"='${oldPublicKey}'`
);
await queryInterface.sequelize.query(
`UPDATE ${process.env.DATABASE_SCHEMA_NAME}."arka_whitelist" SET "API_KEY"='${publicKey}' WHERE "API_KEY"='${oldPublicKey}'`
);
}
async function down({ context: queryInterface }) {
await queryInterface.sequelize.query(
`UPDATE ${process.env.DATABASE_SCHEMA_NAME}."api_keys" SET "API_KEY"='${oldPublicKey}' WHERE "API_KEY"='${publicKey}'`
)
await queryInterface.sequelize.query(
`UPDATE ${process.env.DATABASE_SCHEMA_NAME}."arka_whitelist" SET "API_KEY"='${oldPublicKey}' WHERE "API_KEY"='${publicKey}'`
)
}
module.exports = {up, down};
2 changes: 1 addition & 1 deletion backend/src/constants/ErrorMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
API_KEY_NOT_CONFIGURED_IN_DATABASE: 'Api Key not configured in database',
UNSUPPORTED_NETWORK: 'Unsupported network',
UNSUPPORTED_NETWORK_TOKEN: 'Unsupported network/token',
EMPTY_BODY: 'Empty Body received',
MISSING_PARAMS: 'You have not supplied the required input parameters for this function/endpoint',
API_KEY_IS_REQUIRED_IN_HEADER: 'Api Key is required in header',
API_KEY_DOES_NOT_EXIST_FOR_THE_WALLET_ADDRESS: 'Api Key does not exist for the wallet address',
WALLET_ADDRESS_DOES_NOT_MATCH_FOR_THE_API_KEY: 'Wallet address does not match for the Api Key',
Expand Down
12 changes: 6 additions & 6 deletions backend/src/paymaster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import EtherspotAbiV07 from "../abi/EtherspotVerifyingSignerAbi.js";
import { PimlicoPaymaster } from './pimlico.js';
import ErrorMessage from '../constants/ErrorMessage.js';
import { PAYMASTER_ADDRESS } from '../constants/Pimlico.js';
import { getEtherscanFee } from '../utils/common.js';
import { getGasFee } from '../utils/common.js';
import MultiTokenPaymasterAbi from '../abi/MultiTokenPaymasterAbi.js';
import OrochiOracleAbi from '../abi/OrochiOracleAbi.js';
import ChainlinkOracleAbi from '../abi/ChainlinkOracleAbi.js';
Expand Down Expand Up @@ -846,7 +846,7 @@ export class Paymaster {
}
const encodedData = paymasterContract.interface.encodeFunctionData('addBatchToWhitelist', [address]);

const etherscanFeeData = await getEtherscanFee(chainId);
const etherscanFeeData = await getGasFee(chainId, bundlerRpc, log);
let feeData;
if (etherscanFeeData) {
feeData = etherscanFeeData;
Expand Down Expand Up @@ -899,7 +899,7 @@ export class Paymaster {
}

const encodedData = paymasterContract.interface.encodeFunctionData('removeBatchFromWhitelist', [address]);
const etherscanFeeData = await getEtherscanFee(chainId);
const etherscanFeeData = await getGasFee(chainId, bundlerRpc, log);
let feeData;
if (etherscanFeeData) {
feeData = etherscanFeeData;
Expand Down Expand Up @@ -963,7 +963,7 @@ export class Paymaster {

const encodedData = paymasterContract.interface.encodeFunctionData(isEpv06 ? 'depositFunds' : 'deposit', []);

const etherscanFeeData = await getEtherscanFee(chainId);
const etherscanFeeData = await getGasFee(chainId, bundlerRpc, log);
let feeData;
if (etherscanFeeData) {
feeData = etherscanFeeData;
Expand Down Expand Up @@ -1024,7 +1024,7 @@ export class Paymaster {
contract = new ethers.ContractFactory(verifyingPaymasterV2Abi, verifyingPaymasterV2ByteCode, signer);
}

const etherscanFeeData = await getEtherscanFee(chainId);
const etherscanFeeData = await getGasFee(chainId, bundlerRpcUrl, log);
let feeData;
if (etherscanFeeData) {
feeData = etherscanFeeData;
Expand Down Expand Up @@ -1071,7 +1071,7 @@ export class Paymaster {

const contract = new ethers.Contract(paymasterAddress, verifyingPaymasterAbi, signer);

const etherscanFeeData = await getEtherscanFee(chainId);
const etherscanFeeData = await getGasFee(chainId, bundlerRpcUrl, log);
let feeData;
if (etherscanFeeData) {
feeData = etherscanFeeData;
Expand Down
7 changes: 5 additions & 2 deletions backend/src/plugins/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const ConfigSchema = Type.Strict(
MULTI_TOKEN_PAYMASTERS: Type.String(),
MULTI_TOKEN_ORACLES: Type.String(),
MTP_VGL_MARKUP: Type.String() || '30000',
USE_SKANDHA_FOR_GAS_DATA: Type.Boolean() || true
})
);

Expand Down Expand Up @@ -75,7 +76,8 @@ const configPlugin: FastifyPluginAsync = async (server) => {
DEFAULT_BUNDLER_API_KEY: process.env.DEFAULT_BUNDLER_API_KEY,
MULTI_TOKEN_PAYMASTERS: process.env.MULTI_TOKEN_PAYMASTERS,
MULTI_TOKEN_ORACLES: process.env.MULTI_TOKEN_ORACLES,
MTP_VGL_MARKUP: process.env.MTP_VGL_MARKUP
MTP_VGL_MARKUP: process.env.MTP_VGL_MARKUP,
USE_SKANDHA_FOR_GAS_DATA: process.env.USE_SKANDHA_FOR_GAS_DATA
}

const valid = validate(envVar);
Expand Down Expand Up @@ -111,7 +113,8 @@ const configPlugin: FastifyPluginAsync = async (server) => {
DEFAULT_BUNDLER_API_KEY: process.env.DEFAULT_BUNDLER_API_KEY ?? '',
MULTI_TOKEN_PAYMASTERS: process.env.MULTI_TOKEN_PAYMASTERS ?? '',
MULTI_TOKEN_ORACLES: process.env.MULTI_TOKEN_ORACLES ?? '',
MTP_VGL_MARKUP: process.env.MTP_VGL_MARKUP ?? '30000'
MTP_VGL_MARKUP: process.env.MTP_VGL_MARKUP ?? '30000',
USE_SKANDHA_FOR_GAS_DATA: process.env.USE_SKANDHA_FOR_GAS_DATA === 'false' ? false : true
}

server.log.info(config, "config:");
Expand Down
20 changes: 10 additions & 10 deletions backend/src/routes/admin-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const adminRoutes: FastifyPluginAsync = async (server) => {
return reply.code(ReturnCode.NOT_AUTHORIZED).send({ error: ErrorMessage.NOT_AUTHORIZED });
}
const body: any = JSON.parse(request.body as string);
if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.EMPTY_BODY });
if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.MISSING_PARAMS });
if (!body.walletAddress) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_DATA });
if (ethers.utils.getAddress(body.walletAddress) === ethers.utils.getAddress(server.config.ADMIN_WALLET_ADDRESS)) return reply.code(ReturnCode.SUCCESS).send({ error: null, message: "Successfully Logged in" });
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_USER });
Expand Down Expand Up @@ -75,7 +75,7 @@ const adminRoutes: FastifyPluginAsync = async (server) => {
return reply.code(ReturnCode.NOT_AUTHORIZED).send({ error: ErrorMessage.NOT_AUTHORIZED });
}
const body: ArkaConfigUpdateData = JSON.parse(request.body as string);
if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.EMPTY_BODY });
if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.MISSING_PARAMS });
if (Object.values(body).every(value => value)) {
try {
const result = await server.arkaConfigRepository.updateConfig(body);
Expand All @@ -102,7 +102,7 @@ const adminRoutes: FastifyPluginAsync = async (server) => {
server.post('/saveKey', async function (request, reply) {
try {
const body = JSON.parse(request.body as string) as ApiKeyDto;
if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.EMPTY_BODY });
if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.MISSING_PARAMS });
if (!body.apiKey)
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_DATA });

Expand Down Expand Up @@ -196,7 +196,7 @@ const adminRoutes: FastifyPluginAsync = async (server) => {
return reply.code(ReturnCode.NOT_AUTHORIZED).send({ error: ErrorMessage.NOT_AUTHORIZED });
}
const body = JSON.parse(request.body as string) as ApiKeyDto;
if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.EMPTY_BODY });
if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.MISSING_PARAMS });
if (!body.apiKey)
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_DATA });
if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*-_&])[A-Za-z\d@$!%*-_&]{8,}$/.test(body.apiKey))
Expand Down Expand Up @@ -244,7 +244,7 @@ const adminRoutes: FastifyPluginAsync = async (server) => {
try {
const body: any = JSON.parse(request.body as string);
if (!body)
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.EMPTY_BODY });
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.MISSING_PARAMS });
if (!body.apiKey)
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_DATA });
if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*-_&])[A-Za-z\d@$!%*-_&]{8,}$/.test(body.apiKey))
Expand Down Expand Up @@ -347,7 +347,7 @@ const adminRoutes: FastifyPluginAsync = async (server) => {
server.post('/getSupportedNetworks', async (request, reply) => {
try {
const body: any = JSON.parse(request.body as string);
if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.EMPTY_BODY });
if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.MISSING_PARAMS });
if (!body.walletAddress) {
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_DATA });
}
Expand All @@ -372,7 +372,7 @@ const adminRoutes: FastifyPluginAsync = async (server) => {

server.post('/deployVerifyingPaymaster', async (request, reply) => {
try {
if (!request.body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.EMPTY_BODY });
if (!request.body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.MISSING_PARAMS });

const body: any = request.body;
const query: any = request.query;
Expand Down Expand Up @@ -471,14 +471,14 @@ const adminRoutes: FastifyPluginAsync = async (server) => {

server.post('/addStake', async (request, reply) => {
try {
if (!request.body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.EMPTY_BODY });
if (!request.body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.MISSING_PARAMS });

const body: any = request.body;
const query: any = request.query;
const chainId = query['chainId'];
const apiKey = query['apiKey'];
const epVersion = body.params[0];
const amount = body.params[1];
const epVersion = body.params?.[0];
const amount = body.params?.[1];

if (!chainId || isNaN(chainId) || !apiKey) {
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_DATA });
Expand Down
12 changes: 6 additions & 6 deletions backend/src/routes/deposit-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ const depositRoutes: FastifyPluginAsync = async (server) => {
printRequest("/deposit", request, server.log);
const body: any = request.body;
const query: any = request.query;
const amount = body.params[0];
const amount = body.params?.[0];
const useVp = query['useVp'] ?? false;
const chainId = query['chainId'] ?? body.params[1];
const api_key = query['apiKey'] ?? body.params[2];
const chainId = query['chainId'] ?? body.params?.[1];
const api_key = query['apiKey'] ?? body.params?.[2];

if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
Expand Down Expand Up @@ -117,9 +117,9 @@ const depositRoutes: FastifyPluginAsync = async (server) => {
printRequest("/deposit/v2", request, server.log);
const body: any = request.body;
const query: any = request.query;
const amount = body.params[0];
const chainId = query['chainId'] ?? body.params[1];
const api_key = query['apiKey'] ?? body.params[2];
const amount = body.params?.[0];
const chainId = query['chainId'] ?? body.params?.[1];
const api_key = query['apiKey'] ?? body.params?.[2];
const useVp = query['useVp'] ?? false;
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
Expand Down
24 changes: 14 additions & 10 deletions backend/src/routes/paymaster-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ const paymasterRoutes: FastifyPluginAsync<PaymasterRoutesOpts> = async (server,
printRequest("/", request, server.log);
const query: any = request.query;
const body: any = request.body;
if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.EMPTY_BODY });
const userOp = body.params[0];
const entryPoint = body.params[1];
let context = body.params[2];
if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.MISSING_PARAMS });
const userOp = body.params?.[0];
const entryPoint = body.params?.[1];
let context = body.params?.[2];
let gasToken = context?.token ? context.token : null;
let mode = context?.mode ? String(context.mode) : "sponsor";
let chainId = query['chainId'] ?? body.params[3];
const api_key = query['apiKey'] ?? body.params[4];
let chainId = query['chainId'] ?? body.params?.[3];
const api_key = query['apiKey'] ?? body.params?.[4];
let epVersion: EPVersions = DEFAULT_EP_VERSION;
let tokens_list: string[] = [];
let sponsorDetails = false, estimate = true, tokenQuotes = false;
Expand All @@ -60,10 +60,14 @@ const paymasterRoutes: FastifyPluginAsync<PaymasterRoutesOpts> = async (server,
}
// eslint-disable-next-line no-fallthrough
case 'pm_getPaymasterStubData': {
chainId = BigNumber.from(body.params[2]).toNumber();
context = body.params[3];
gasToken = context?.token ? context.token : null;
mode = context?.mode ? String(context.mode) : "sponsor";
if (body.params && Array.isArray(body.params) && body.params.length >= 3) {
chainId = BigNumber.from(body.params[2]).toNumber();
context = body.params?.[3] ?? null;
gasToken = context?.token ? context.token : null;
mode = context?.mode ? String(context.mode) : "sponsor";
} else {
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.MISSING_PARAMS });
}
break;
}
case 'pm_sponsorUserOperation': {
Expand Down
9 changes: 5 additions & 4 deletions backend/src/routes/pimlico-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ const pimlicoRoutes: FastifyPluginAsync = async (server) => {
printRequest("/tokenPaymasterAddress", request, server.log);
const query: any = request.query;
const body: any = request.body;
const entryPoint = body.params[0];
const context = body.params[1];
if (!body) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.MISSING_PARAMS });
const entryPoint = body.params?.[0];
const context = body.params?.[1];
const gasToken = context ? context.token : null;
const chainId = query['chainId'] ?? body.params[2];
const api_key = query['apiKey'] ?? body.params[3];
const chainId = query['chainId'] ?? body.params?.[2];
const api_key = query['apiKey'] ?? body.params?.[3];
if (!api_key || typeof(api_key) !== "string")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
const apiKeyData = await server.apiKeyRepository.findOneByApiKey(api_key);
Expand Down
2 changes: 1 addition & 1 deletion backend/src/routes/sponsorship-policy-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ const sponsorshipPolicyRoutes: FastifyPluginAsync = async (server) => {
try {
// parse the request body as JSON
const sponsorshipPolicyDto: SponsorshipPolicyDto = JSON.parse(JSON.stringify(request.body)) as SponsorshipPolicyDto;
if (!sponsorshipPolicyDto) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.EMPTY_BODY });
if (!sponsorshipPolicyDto) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.MISSING_PARAMS });

// id is to be null
if (sponsorshipPolicyDto.id || sponsorshipPolicyDto.id as number > 0 ||
Expand Down
Loading

0 comments on commit c01bff3

Please sign in to comment.