@snapshot-labs/snapshot.js 0.5.0-beta.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils.d.ts CHANGED
@@ -28,7 +28,7 @@ export declare function getUrl(uri: any, gateway?: string): any;
28
28
  export declare function getJSON(uri: any): Promise<any>;
29
29
  export declare function ipfsGet(gateway: string, ipfsHash: string, protocolType?: string): Promise<any>;
30
30
  export declare function sendTransaction(web3: any, contractAddress: string, abi: any[], action: string, params: any[], overrides?: {}): Promise<any>;
31
- export declare function getScores(space: string, strategies: Strategy[], network: string, addresses: string[], snapshot?: number | string, scoreApiUrl?: string): Promise<any>;
31
+ export declare function getScores(space: string, strategies: Strategy[], network: string, addresses: string[], snapshot?: number | string, scoreApiUrl?: string, options?: any): Promise<any>;
32
32
  export declare function getVp(address: string, network: string, strategies: Strategy[], snapshot: number | 'latest', space: string, delegation: boolean, options?: Options): Promise<any>;
33
33
  export declare function validate(validation: string, author: string, space: string, network: string, snapshot: number | 'latest', params: any, options: any): Promise<any>;
34
34
  export declare function validateSchema(schema: any, data: any): true | import("ajv").ErrorObject<string, Record<string, any>, unknown>[] | null | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapshot-labs/snapshot.js",
3
- "version": "0.5.0-beta.1",
3
+ "version": "0.5.0",
4
4
  "repository": "snapshot-labs/snapshot.js",
5
5
  "license": "MIT",
6
6
  "main": "dist/snapshot.cjs.js",
package/src/sign/index.ts CHANGED
@@ -77,7 +77,6 @@ export default class Client {
77
77
 
78
78
  async send(envelop) {
79
79
  let address = this.address;
80
- console.log('sig', envelop.sig);
81
80
  if (envelop.sig === '0x' && this.options.relayerURL)
82
81
  address = this.options.relayerURL;
83
82
  const init = {
package/src/utils.ts CHANGED
@@ -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);
@@ -1,47 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- exports.__esModule = true;
14
- exports.getBatchedProvider = void 0;
15
- var providers_1 = require("@ethersproject/providers");
16
- var networks_json_1 = require("../networks.json");
17
- var providers = {};
18
- function getProvider(network, type) {
19
- var _a;
20
- if (type === void 0) { type = 'archive'; }
21
- var url = networks_json_1["default"][network].rpc[0];
22
- if (type === 'light' && ((_a = networks_json_1["default"][network].light) === null || _a === void 0 ? void 0 : _a.length))
23
- url = networks_json_1["default"][network].light[0];
24
- var connectionInfo = typeof url === 'object'
25
- ? __assign(__assign({}, url), { timeout: 25000 }) : { url: url, timeout: 25000 };
26
- if (!providers[network] || !providers[network][type]) {
27
- providers[network] = __assign({}, providers[network]);
28
- providers[network][type] = new providers_1.StaticJsonRpcProvider(connectionInfo);
29
- }
30
- return providers[network][type];
31
- }
32
- exports["default"] = getProvider;
33
- function getBatchedProvider(network, type) {
34
- var _a;
35
- if (type === void 0) { type = 'archive'; }
36
- var url = networks_json_1["default"][network].rpc[0];
37
- if (type === 'light' && ((_a = networks_json_1["default"][network].light) === null || _a === void 0 ? void 0 : _a.length))
38
- url = networks_json_1["default"][network].light[0];
39
- var connectionInfo = typeof url === 'object'
40
- ? __assign(__assign({}, url), { timeout: 25000 }) : { url: url, timeout: 25000 };
41
- if (!providers[network] || !providers[network][type]) {
42
- providers[network] = __assign({}, providers[network]);
43
- providers[network][type] = new providers_1.JsonRpcBatchProvider(connectionInfo);
44
- }
45
- return providers[network][type];
46
- }
47
- exports.getBatchedProvider = getBatchedProvider;