11import * as Sentry from '@sentry/nextjs'
22import { NextApiRequest , NextApiResponse } from 'next'
3- import { decodeFunctionData , getAbiItem } from 'viem'
3+ import { decodeFunctionData , getAbiItem , isHex } from 'viem'
44
55import { CACHE_TIMES } from 'src/constants/cacheTimes'
66import { getContractABIByAddress } from 'src/services/abiService'
@@ -14,20 +14,24 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
1414 if ( ! calldata ) return res . status ( 404 ) . json ( { error : 'no calldata request' } )
1515 if ( ! chain ) return res . status ( 404 ) . json ( { error : 'no chain request' } )
1616
17+ if ( ! isHex ( calldata , { strict : true } ) )
18+ return res . status ( 400 ) . json ( { error : 'bad calldata input' } )
19+
1720 const chainInt = parseInt ( chain )
1821
1922 try {
20- const { abi } = await getContractABIByAddress ( chainInt as CHAIN_ID , contract )
21- const decodeResult = decodeFunctionData ( { abi : JSON . parse ( abi ) , data : calldata } )
23+ const { abi : abiJsonString } = await getContractABIByAddress (
24+ chainInt as CHAIN_ID ,
25+ contract
26+ )
27+ const abi = JSON . parse ( abiJsonString )
28+ const decodeResult = decodeFunctionData ( { abi, data : calldata } )
29+ const functionSig = calldata . slice ( 0 , 10 )
2230 const functionInfo = getAbiItem ( {
23- abi : JSON . parse ( abi ) ,
24- name :
25- decodeResult . functionName !== 'release'
26- ? decodeResult . functionName
27- : '0x37bdc99b' , // manually set function signature for release(_milestone) instead of release()
31+ abi,
32+ name : functionSig ,
2833 } )
2934
30-
3135 const argMapping = functionInfo . inputs . reduce (
3236 ( last : any , input : any , index : number ) => {
3337 last [ input . name ] = {
@@ -50,6 +54,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
5054 res . status ( 200 ) . json ( {
5155 args : argMapping ,
5256 functionName : decodeResult . functionName ,
57+ functionSig : functionSig ,
5358 decoded : decodeResult . args . map ( ( x : any ) => x . toString ( ) ) ,
5459 } )
5560 } catch ( error ) {
0 commit comments