88 divider ,
99 image ,
1010 OnSignatureHandler ,
11- SeverityLevel
11+ SeverityLevel ,
1212} from '@metamask/snaps-sdk' ;
1313// eslint-disable-next-line import/no-extraneous-dependencies
1414import mdEscape from 'markdown-escape' ;
@@ -72,57 +72,38 @@ const fetchGraphQLData = async (variables: {
7272 // no other CAIP-10 legal string should match (since it would require having more than 2 ":" characters)
7373 // there is no "key0_nocase" query.
7474 const query = `
75- query($targetAddress: String!, $domain: String!) {
76- addressTags: litems(where:{
77- registry:"0x66260c69d03837016d88c9877e61e08ef74c59f2",
78- metadata_: {
79- key0_starts_with_nocase: $targetAddress,
80- key0_ends_with_nocase: $targetAddress,
81- },
82- status_in:[Registered, ClearingRequested]
83- }, first: 1) {
84- metadata {
85- key0
86- key1
87- key2
88- key3
89- }
75+ query ($targetAddress: String!, $domain: String!) {
76+ addressTags: LItem(
77+ where: {registry_id: {_eq: "0x66260c69d03837016d88c9877e61e08ef74c59f2"}, key0: {_ilike: $targetAddress}, status: {_in: [Registered, ClearingRequested]}}
78+ limit: 1
79+ ) {
80+ key0
81+ key1
82+ key2
83+ key3
9084 }
91- contractDomains: litems(where:{
92- registry:"0x957a53a994860be4750810131d9c876b2f52d6e1",
93- metadata_: {
94- key0_starts_with_nocase: $targetAddress,
95- key0_ends_with_nocase: $targetAddress,
96- key1: $domain,
97- },
98- status_in:[Registered, ClearingRequested]
99- }, first: 1) {
100- metadata {
101- key0
102- key1
103- }
85+ contractDomains: LItem(
86+ where: {registry_id: {_eq: "0x957a53a994860be4750810131d9c876b2f52d6e1"}, key0: {_ilike: $targetAddress}, key1: {_eq: $domain}, status: {_in: [Registered, ClearingRequested]}}
87+ limit: 1
88+ ) {
89+ key0
90+ key1
10491 }
105- tokens: litems(where:{
106- registry:"0xee1502e29795ef6c2d60f8d7120596abe3bad990",
107- metadata_: {
108- key0_starts_with_nocase: $targetAddress,
109- key0_ends_with_nocase: $targetAddress,
110- },
111- status_in:[Registered, ClearingRequested]
112- }, first: 1) {
113- metadata {
114- key0
115- key1
116- key2
117- key3
118- }
92+ tokens: LItem(
93+ where: {registry_id: {_eq: "0xee1502e29795ef6c2d60f8d7120596abe3bad990"}, key0: {_ilike: $targetAddress}, status: {_in: [Registered, ClearingRequested]}}
94+ limit: 1
95+ ) {
96+ key0
97+ key1
98+ key2
99+ key3
119100 }
120101 }
121102 ` ;
122103
123104 try {
124105 const response = await fetch (
125- " https://gateway.thegraph.com/api/b027176e14f0a073a572abe9068dd266/subgraphs/id/9hHo5MpjpC1JqfD3BsgFnojGurXRHTrHWcUcZPPCo6m8" ,
106+ ' https://indexer.hyperindex.xyz/1a2f51c/v1/graphql' ,
126107 {
127108 method : 'POST' ,
128109 headers : {
@@ -134,29 +115,39 @@ const fetchGraphQLData = async (variables: {
134115 } ,
135116 ) ;
136117
137- // Kleros Curate is a generalized registry, and is indexed by a generalized subgraph.
138- // Indexed fields are written into fields such as key0, key1...
139- // To make this code more readable, they are parsed onto the types at the beginning of this file.
118+ // Kleros Curate is a generalized registry, and is indexed by a generalized subgraph.
119+ // Indexed fields are written into fields such as key0, key1...
120+ // To make this code more readable, they are parsed onto the types at the beginning of this file.
140121 if ( ! response . ok ) return null ;
141122
142123 const result = await response . json ( ) ;
143124 if ( ! result . data ) return null ;
144125
145126 const parsedAddressTag = result . data . addressTags [ 0 ]
146- ? parseMetadata ( result . data . addressTags [ 0 ] . metadata , [ 'caipAddress' , 'publicName' , 'projectName' , 'infoLink' ] )
127+ ? parseMetadata ( result . data . addressTags [ 0 ] , [
128+ 'caipAddress' ,
129+ 'publicName' ,
130+ 'projectName' ,
131+ 'infoLink' ,
132+ ] )
147133 : undefined ;
148134
149135 const parsedContractDomain = result . data . contractDomains [ 0 ]
150- ? parseMetadata ( result . data . contractDomains [ 0 ] . metadata , [ 'caipAddress' , 'domain' ] )
136+ ? parseMetadata ( result . data . contractDomains [ 0 ] , [ 'caipAddress' , 'domain' ] )
151137 : undefined ;
152138
153139 const parsedToken = result . data . tokens [ 0 ]
154- ? parseMetadata ( result . data . tokens [ 0 ] . metadata , [ 'caipAddress' , 'name' , 'symbol' , 'website' ] )
140+ ? parseMetadata ( result . data . tokens [ 0 ] , [
141+ 'caipAddress' ,
142+ 'name' ,
143+ 'symbol' ,
144+ 'website' ,
145+ ] )
155146 : undefined ;
156147
157- return {
158- addressTag : parsedAddressTag ,
159- contractDomain : parsedContractDomain ,
148+ return {
149+ addressTag : parsedAddressTag ,
150+ contractDomain : parsedContractDomain ,
160151 token : parsedToken ,
161152 } ;
162153 } catch ( error ) {
@@ -211,7 +202,7 @@ const getInsights = async (
211202
212203 if ( result . token ) {
213204 insights . push ( `✅ **Verified token**` ) ;
214- const tokenName = result . token . website
205+ const tokenName = result . token . website
215206 ? `[${ result . token . name } ](${ result . token . website } )`
216207 : result . token . name ;
217208 insights . push ( `**Token:** ${ tokenName } (${ result . token . symbol } )` ) ;
@@ -243,7 +234,9 @@ export const onInstall: OnInstallHandler = async () => {
243234 text (
244235 '**Contract Tag:** _What is the function or tag associated with the smart contract?_' ,
245236 ) ,
246- text ( '**Domain:** _Whether this contract is known to be used on this domain?_' ) ,
237+ text (
238+ '**Domain:** _Whether this contract is known to be used on this domain?_' ,
239+ ) ,
247240 image ( InsightsDisplayImage ) ,
248241 ] ) ,
249242 } ,
@@ -288,38 +281,83 @@ export const onTransaction: OnTransactionHandler = async ({
288281 if ( result . length > 0 ) {
289282 insights . push ( ...result ) ;
290283 } else {
291- insights . push ( `No insights available for this contract. Interact at your own risk.` ) ;
284+ insights . push (
285+ `No insights available for this contract. Interact at your own risk.` ,
286+ ) ;
292287 }
293288
294289 const excludedDomains = [
295- 'etherscan.io' , 'bscscan.com' , 'gnosisscan.io' , 'polygonscan.com' ,
296- 'mempool.space' , 'explorer.solana.com' , 'basescan.org' , 'arbiscan.io' ,
297- 'moonscan.io' , 'lineascan.build' , 'optimistic.etherscan.io' , 'ftmscan.com' ,
298- 'moonriver.moonscan.io' , 'snowscan.xyz' , 'cronoscan.com' , 'bttcscan.com' ,
299- 'zkevm.polygonscan.com' , 'wemixscan.com' , 'scrollscan.com' , 'era.zksync.network' ,
300- 'celoscan.io' , 'avascan.info' , 'blastscan.io' , 'mantlescan.xyz' , 'sepolia.etherscan.io' ,
301- 'goerli.etherscan.io' , 'holesky.etherscan.io' , 'testnet.bscscan.com' , 'testnet.ftmscan.com' ,
302- 'mumbai.polygonscan.com' , 'goerli.arbiscan.io' , 'sepolia.arbiscan.io' , 'testnet.snowtrace.io' ,
303- 'explorer.testnet.mantle.xyz' , 'sepolia.basescan.org' , 'goerli.basescan.org' , 'alfajores.celoscan.io' ,
304- 'blockscout.com' , 'explorer.zksync.io' , 'layerzeroscan.com' , 'routescan.io' ,
305- 'moonbeam.moonscan.io' , 'subscan.io' , 'solscan.io' , 'explorer.near.org' ,
306- 'cardanoscan.io' , 'astar.subscan.io' , 'polkadot.subscan.io' , 'kusama.subscan.io'
290+ 'etherscan.io' ,
291+ 'bscscan.com' ,
292+ 'gnosisscan.io' ,
293+ 'polygonscan.com' ,
294+ 'mempool.space' ,
295+ 'explorer.solana.com' ,
296+ 'basescan.org' ,
297+ 'arbiscan.io' ,
298+ 'moonscan.io' ,
299+ 'lineascan.build' ,
300+ 'optimistic.etherscan.io' ,
301+ 'ftmscan.com' ,
302+ 'moonriver.moonscan.io' ,
303+ 'snowscan.xyz' ,
304+ 'cronoscan.com' ,
305+ 'bttcscan.com' ,
306+ 'zkevm.polygonscan.com' ,
307+ 'wemixscan.com' ,
308+ 'scrollscan.com' ,
309+ 'era.zksync.network' ,
310+ 'celoscan.io' ,
311+ 'avascan.info' ,
312+ 'blastscan.io' ,
313+ 'mantlescan.xyz' ,
314+ 'sepolia.etherscan.io' ,
315+ 'goerli.etherscan.io' ,
316+ 'holesky.etherscan.io' ,
317+ 'testnet.bscscan.com' ,
318+ 'testnet.ftmscan.com' ,
319+ 'mumbai.polygonscan.com' ,
320+ 'goerli.arbiscan.io' ,
321+ 'sepolia.arbiscan.io' ,
322+ 'testnet.snowtrace.io' ,
323+ 'explorer.testnet.mantle.xyz' ,
324+ 'sepolia.basescan.org' ,
325+ 'goerli.basescan.org' ,
326+ 'alfajores.celoscan.io' ,
327+ 'blockscout.com' ,
328+ 'explorer.zksync.io' ,
329+ 'layerzeroscan.com' ,
330+ 'routescan.io' ,
331+ 'moonbeam.moonscan.io' ,
332+ 'subscan.io' ,
333+ 'solscan.io' ,
334+ 'explorer.near.org' ,
335+ 'cardanoscan.io' ,
336+ 'astar.subscan.io' ,
337+ 'polkadot.subscan.io' ,
338+ 'kusama.subscan.io' ,
307339 ] ;
308340
309- if ( ! excludedDomains . includes ( domain ) && ! insights . some ( insight => insight . includes ( 'Domain' ) ) ) {
341+ if (
342+ ! excludedDomains . includes ( domain ) &&
343+ ! insights . some ( ( insight ) => insight . includes ( 'Domain' ) )
344+ ) {
310345 const cdnPathURL = `https://app.klerosscout.eth.limo/#/?registry=CDN&network=1&network=100&network=137&network=56&network=42161&network=10&network=43114&network=534352&network=42220&network=8453&network=250&network=324&status=Registered&status=RegistrationRequested&status=ClearingRequested&status=Absent&disputed=true&disputed=false&page=1&orderDirection=desc&&additem=CDN&caip10Address=${ caipAddress } &domain=${ domain } ` ;
311346
312- insights . push ( `Is this contract officially linked to **${ domain } **? If so, submit the info at [Scout App](${ cdnPathURL } ) to verify it for all users!` ) ;
347+ insights . push (
348+ `Is this contract officially linked to **${ domain } **? If so, submit the info at [Scout App](${ cdnPathURL } ) to verify it for all users!` ,
349+ ) ;
313350 }
314351
315352 return {
316- content : panel ( [
317- ...insights . map ( ( insight ) => text ( insight ) ) ,
318- ] ) ,
353+ content : panel ( [ ...insights . map ( ( insight ) => text ( insight ) ) ] ) ,
319354 } ;
320355} ;
321356
322- export const onSignature : OnSignatureHandler = async ( { signature, signatureOrigin } ) => {
357+ export const onSignature : OnSignatureHandler = async ( {
358+ signature,
359+ signatureOrigin,
360+ } ) => {
323361 const { signatureMethod, data } = signature ;
324362 const insights : string [ ] = [ ] ;
325363
@@ -329,15 +367,22 @@ export const onSignature: OnSignatureHandler = async ({ signature, signatureOrig
329367 ) {
330368 const verifyingContract = data ?. domain ?. verifyingContract ;
331369 const numericChainId = data ?. domain ?. chainId ;
332- const caipAddress = `eip155:${ numericChainId } :${ verifyingContract as string } ` ;
370+ const caipAddress = `eip155:${ numericChainId } :${
371+ verifyingContract as string
372+ } `;
333373
334374 if ( verifyingContract ) {
335- const result = await getInsights ( caipAddress , signatureOrigin || 'NO_DOMAIN' ) ;
375+ const result = await getInsights (
376+ caipAddress ,
377+ signatureOrigin || 'NO_DOMAIN' ,
378+ ) ;
336379
337380 if ( result . length > 0 ) {
338381 insights . push ( ...result ) ;
339382 } else {
340- insights . push ( 'No insights available for this contract. Interact at your own risk.' ) ;
383+ insights . push (
384+ 'No insights available for this contract. Interact at your own risk.' ,
385+ ) ;
341386 }
342387 } else {
343388 insights . push ( 'No verifying contract found in the signature data.' ) ;
0 commit comments