@@ -9,6 +9,7 @@ import ReturnCode from "../constants/ReturnCode.js";
99import { decode } from "../utils/crypto.js" ;
1010import { printRequest , getNetworkConfig } from "../utils/common.js" ;
1111import { APIKey } from "../models/api-key.js" ;
12+ import { ethers } from "ethers" ;
1213
1314const pimlicoRoutes : FastifyPluginAsync = async ( server ) => {
1415
@@ -105,6 +106,42 @@ const pimlicoRoutes: FastifyPluginAsync = async (server) => {
105106 }
106107 )
107108
109+ server . post ( "/getAllCommonERC20PaymasterAddress" ,
110+ ResponseSchema ,
111+ async function ( request , reply ) {
112+ try {
113+ printRequest ( "/getAllCommonERC20PaymasterAddress" , request , server . log ) ;
114+ const query : any = request . query ;
115+ const body : any = request . body ;
116+ const entryPoint = body . params [ 0 ] ;
117+ const api_key = query [ 'apiKey' ] ?? body . params [ 1 ] ;
118+ if ( ! api_key || typeof ( api_key ) !== "string" )
119+ return reply . code ( ReturnCode . FAILURE ) . send ( { error : ErrorMessage . INVALID_API_KEY } )
120+ if ( ! server . config . EPV_06 . includes ( entryPoint ?? '' ) ) return reply . code ( ReturnCode . FAILURE ) . send ( { error : ErrorMessage . UNSUPPORTED_ENTRYPOINT } )
121+ const apiKeyData = await server . apiKeyRepository . findOneByApiKey ( api_key ) ;
122+ if ( ! apiKeyData ) return reply . code ( ReturnCode . FAILURE ) . send ( { error : ErrorMessage . INVALID_API_KEY } )
123+ const multiTokenRec = await server . multiTokenPaymasterRepository . findAll ( ) ;
124+ const result = multiTokenRec . map ( ( record ) => {
125+ return {
126+ paymasterAddress : record . paymasterAddress ,
127+ gasToken : ethers . utils . getAddress ( record . tokenAddress ) ,
128+ chainId : record . chainId ,
129+ decimals : record . decimals
130+ }
131+ } ) ;
132+ server . log . info ( result , 'getAllCommonERC20PaymasterAddress Response sent: ' ) ;
133+ if ( body . jsonrpc )
134+ return reply . code ( ReturnCode . SUCCESS ) . send ( { jsonrpc : body . jsonrpc , id : body . id , message : JSON . stringify ( result ) , error : null } )
135+ return reply . code ( ReturnCode . SUCCESS ) . send ( { message : JSON . stringify ( result ) } ) ;
136+ } catch ( err : any ) {
137+ request . log . error ( err ) ;
138+ if ( err . name == "ResourceNotFoundException" )
139+ return reply . code ( ReturnCode . FAILURE ) . send ( { error : ErrorMessage . INVALID_API_KEY } ) ;
140+ return reply . code ( ReturnCode . FAILURE ) . send ( { error : err . message ?? ErrorMessage . FAILED_TO_PROCESS } ) ;
141+ }
142+ }
143+ )
144+
108145} ;
109146
110147export default pimlicoRoutes ;
0 commit comments