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

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.1",
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,11 +28,15 @@ 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
  ];
35
34
 
35
+ const scoreApiHeaders = {
36
+ Accept: 'application/json',
37
+ 'Content-Type': 'application/json'
38
+ };
39
+
36
40
  const ajv = new Ajv({ allErrors: true, allowUnionTypes: true, $data: true });
37
41
  // @ts-ignore
38
42
  addFormats(ajv);
@@ -215,7 +219,8 @@ export async function getScores(
215
219
  network: string,
216
220
  addresses: string[],
217
221
  snapshot: number | string = 'latest',
218
- scoreApiUrl = 'https://score.snapshot.org/api/scores'
222
+ scoreApiUrl = 'https://score.snapshot.org/api/scores',
223
+ options: any = { returnValue: 'scores' }
219
224
  ) {
220
225
  try {
221
226
  const params = {
@@ -227,11 +232,11 @@ export async function getScores(
227
232
  };
228
233
  const res = await fetch(scoreApiUrl, {
229
234
  method: 'POST',
230
- headers: { 'Content-Type': 'application/json' },
235
+ headers: scoreApiHeaders,
231
236
  body: JSON.stringify({ params })
232
237
  });
233
238
  const obj = await res.json();
234
- return obj.result.scores;
239
+ return options.returnValue ? obj.result[options.returnValue] : obj.result;
235
240
  } catch (e) {
236
241
  return Promise.reject(e);
237
242
  }
@@ -250,10 +255,7 @@ export async function getVp(
250
255
  if (!options.url) options.url = 'https://score.snapshot.org';
251
256
  const init = {
252
257
  method: 'POST',
253
- headers: {
254
- Accept: 'application/json',
255
- 'Content-Type': 'application/json'
256
- },
258
+ headers: scoreApiHeaders,
257
259
  body: JSON.stringify({
258
260
  jsonrpc: '2.0',
259
261
  method: 'get_vp',
@@ -264,8 +266,7 @@ export async function getVp(
264
266
  snapshot,
265
267
  space,
266
268
  delegation
267
- },
268
- id: null
269
+ }
269
270
  })
270
271
  };
271
272
  const res = await fetch(options.url, init);
@@ -287,10 +288,7 @@ export async function validate(
287
288
  if (!options.url) options.url = 'https://score.snapshot.org';
288
289
  const init = {
289
290
  method: 'POST',
290
- headers: {
291
- Accept: 'application/json',
292
- 'Content-Type': 'application/json'
293
- },
291
+ headers: scoreApiHeaders,
294
292
  body: JSON.stringify({
295
293
  jsonrpc: '2.0',
296
294
  method: 'validate',
@@ -301,8 +299,7 @@ export async function validate(
301
299
  network,
302
300
  snapshot,
303
301
  params
304
- },
305
- id: null
302
+ }
306
303
  })
307
304
  };
308
305
  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;