@@ -28,10 +28,16 @@ interface Strategy {
28
28
}
29
29
30
30
export const SNAPSHOT_SUBGRAPH_URL = delegationSubgraphs ;
31
-
32
31
const ENS_RESOLVER_ABI = [
33
32
'function text(bytes32 node, string calldata key) external view returns (string memory)'
34
33
] ;
34
+ const SCORE_API_KEY = process ?. env ?. KEYCARD_SECRET || '' ;
35
+
36
+ const scoreApiHeaders = {
37
+ Accept : 'application/json' ,
38
+ 'Content-Type' : 'application/json'
39
+ } ;
40
+ if ( SCORE_API_KEY ) scoreApiHeaders [ 'X-API-KEY' ] = SCORE_API_KEY ;
35
41
36
42
const ajv = new Ajv ( { allErrors : true , allowUnionTypes : true , $data : true } ) ;
37
43
// @ts -ignore
@@ -215,7 +221,8 @@ export async function getScores(
215
221
network : string ,
216
222
addresses : string [ ] ,
217
223
snapshot : number | string = 'latest' ,
218
- scoreApiUrl = 'https://score.snapshot.org/api/scores'
224
+ scoreApiUrl = 'https://score.snapshot.org/api/scores' ,
225
+ options : any = { returnValue : 'scores' }
219
226
) {
220
227
try {
221
228
const params = {
@@ -227,11 +234,11 @@ export async function getScores(
227
234
} ;
228
235
const res = await fetch ( scoreApiUrl , {
229
236
method : 'POST' ,
230
- headers : { 'Content-Type' : 'application/json' } ,
237
+ headers : scoreApiHeaders ,
231
238
body : JSON . stringify ( { params } )
232
239
} ) ;
233
240
const obj = await res . json ( ) ;
234
- return obj . result . scores ;
241
+ return options . returnValue ? obj . result [ options . returnValue ] : obj . result ;
235
242
} catch ( e ) {
236
243
return Promise . reject ( e ) ;
237
244
}
@@ -250,10 +257,7 @@ export async function getVp(
250
257
if ( ! options . url ) options . url = 'https://score.snapshot.org' ;
251
258
const init = {
252
259
method : 'POST' ,
253
- headers : {
254
- Accept : 'application/json' ,
255
- 'Content-Type' : 'application/json'
256
- } ,
260
+ headers : scoreApiHeaders ,
257
261
body : JSON . stringify ( {
258
262
jsonrpc : '2.0' ,
259
263
method : 'get_vp' ,
@@ -264,8 +268,7 @@ export async function getVp(
264
268
snapshot,
265
269
space,
266
270
delegation
267
- } ,
268
- id : null
271
+ }
269
272
} )
270
273
} ;
271
274
const res = await fetch ( options . url , init ) ;
@@ -287,10 +290,7 @@ export async function validate(
287
290
if ( ! options . url ) options . url = 'https://score.snapshot.org' ;
288
291
const init = {
289
292
method : 'POST' ,
290
- headers : {
291
- Accept : 'application/json' ,
292
- 'Content-Type' : 'application/json'
293
- } ,
293
+ headers : scoreApiHeaders ,
294
294
body : JSON . stringify ( {
295
295
jsonrpc : '2.0' ,
296
296
method : 'validate' ,
@@ -301,8 +301,7 @@ export async function validate(
301
301
network,
302
302
snapshot,
303
303
params
304
- } ,
305
- id : null
304
+ }
306
305
} )
307
306
} ;
308
307
const res = await fetch ( options . url , init ) ;
0 commit comments