@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/LICENSE CHANGED
File without changes
@@ -335,7 +335,6 @@ var Client = /** @class */ (function () {
335
335
  var address, init;
336
336
  return __generator(this, function (_a) {
337
337
  address = this.address;
338
- console.log('sig', envelop.sig);
339
338
  if (envelop.sig === '0x' && this.options.relayerURL)
340
339
  address = this.options.relayerURL;
341
340
  init = {
@@ -4257,10 +4256,18 @@ var voting = {
4257
4256
  basic: SingleChoiceVoting
4258
4257
  };
4259
4258
 
4259
+ var _a;
4260
4260
  var SNAPSHOT_SUBGRAPH_URL = delegationSubgraphs;
4261
4261
  var ENS_RESOLVER_ABI = [
4262
4262
  'function text(bytes32 node, string calldata key) external view returns (string memory)'
4263
4263
  ];
4264
+ var SCORE_API_KEY = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.KEYCARD_SECRET) || '';
4265
+ var scoreApiHeaders = {
4266
+ Accept: 'application/json',
4267
+ 'Content-Type': 'application/json'
4268
+ };
4269
+ if (SCORE_API_KEY)
4270
+ scoreApiHeaders['X-API-KEY'] = SCORE_API_KEY;
4264
4271
  var ajv = new Ajv__default['default']({ allErrors: true, allowUnionTypes: true, $data: true });
4265
4272
  // @ts-ignore
4266
4273
  addFormats__default['default'](ajv);
@@ -4454,9 +4461,10 @@ function sendTransaction(web3, contractAddress, abi, action, params, overrides)
4454
4461
  });
4455
4462
  });
4456
4463
  }
4457
- function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl) {
4464
+ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl, options) {
4458
4465
  if (snapshot === void 0) { snapshot = 'latest'; }
4459
4466
  if (scoreApiUrl === void 0) { scoreApiUrl = 'https://score.snapshot.org/api/scores'; }
4467
+ if (options === void 0) { options = { returnValue: 'scores' }; }
4460
4468
  return __awaiter(this, void 0, void 0, function () {
4461
4469
  var params, res, obj, e_3;
4462
4470
  return __generator(this, function (_a) {
@@ -4472,7 +4480,7 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl)
4472
4480
  };
4473
4481
  return [4 /*yield*/, fetch__default['default'](scoreApiUrl, {
4474
4482
  method: 'POST',
4475
- headers: { 'Content-Type': 'application/json' },
4483
+ headers: scoreApiHeaders,
4476
4484
  body: JSON.stringify({ params: params })
4477
4485
  })];
4478
4486
  case 1:
@@ -4480,7 +4488,7 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl)
4480
4488
  return [4 /*yield*/, res.json()];
4481
4489
  case 2:
4482
4490
  obj = _a.sent();
4483
- return [2 /*return*/, obj.result.scores];
4491
+ return [2 /*return*/, options.returnValue ? obj.result[options.returnValue] : obj.result];
4484
4492
  case 3:
4485
4493
  e_3 = _a.sent();
4486
4494
  return [2 /*return*/, Promise.reject(e_3)];
@@ -4501,10 +4509,7 @@ function getVp(address, network, strategies, snapshot, space, delegation, option
4501
4509
  options.url = 'https://score.snapshot.org';
4502
4510
  init = {
4503
4511
  method: 'POST',
4504
- headers: {
4505
- Accept: 'application/json',
4506
- 'Content-Type': 'application/json'
4507
- },
4512
+ headers: scoreApiHeaders,
4508
4513
  body: JSON.stringify({
4509
4514
  jsonrpc: '2.0',
4510
4515
  method: 'get_vp',
@@ -4515,8 +4520,7 @@ function getVp(address, network, strategies, snapshot, space, delegation, option
4515
4520
  snapshot: snapshot,
4516
4521
  space: space,
4517
4522
  delegation: delegation
4518
- },
4519
- id: null
4523
+ }
4520
4524
  })
4521
4525
  };
4522
4526
  return [4 /*yield*/, fetch__default['default'](options.url, init)];
@@ -4546,10 +4550,7 @@ function validate(validation, author, space, network, snapshot, params, options)
4546
4550
  options.url = 'https://score.snapshot.org';
4547
4551
  init = {
4548
4552
  method: 'POST',
4549
- headers: {
4550
- Accept: 'application/json',
4551
- 'Content-Type': 'application/json'
4552
- },
4553
+ headers: scoreApiHeaders,
4553
4554
  body: JSON.stringify({
4554
4555
  jsonrpc: '2.0',
4555
4556
  method: 'validate',
@@ -4560,8 +4561,7 @@ function validate(validation, author, space, network, snapshot, params, options)
4560
4561
  network: network,
4561
4562
  snapshot: snapshot,
4562
4563
  params: params
4563
- },
4564
- id: null
4564
+ }
4565
4565
  })
4566
4566
  };
4567
4567
  return [4 /*yield*/, fetch__default['default'](options.url, init)];
@@ -326,7 +326,6 @@ var Client = /** @class */ (function () {
326
326
  var address, init;
327
327
  return __generator(this, function (_a) {
328
328
  address = this.address;
329
- console.log('sig', envelop.sig);
330
329
  if (envelop.sig === '0x' && this.options.relayerURL)
331
330
  address = this.options.relayerURL;
332
331
  init = {
@@ -4248,10 +4247,18 @@ var voting = {
4248
4247
  basic: SingleChoiceVoting
4249
4248
  };
4250
4249
 
4250
+ var _a;
4251
4251
  var SNAPSHOT_SUBGRAPH_URL = delegationSubgraphs;
4252
4252
  var ENS_RESOLVER_ABI = [
4253
4253
  'function text(bytes32 node, string calldata key) external view returns (string memory)'
4254
4254
  ];
4255
+ var SCORE_API_KEY = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.KEYCARD_SECRET) || '';
4256
+ var scoreApiHeaders = {
4257
+ Accept: 'application/json',
4258
+ 'Content-Type': 'application/json'
4259
+ };
4260
+ if (SCORE_API_KEY)
4261
+ scoreApiHeaders['X-API-KEY'] = SCORE_API_KEY;
4255
4262
  var ajv = new Ajv({ allErrors: true, allowUnionTypes: true, $data: true });
4256
4263
  // @ts-ignore
4257
4264
  addFormats(ajv);
@@ -4445,9 +4452,10 @@ function sendTransaction(web3, contractAddress, abi, action, params, overrides)
4445
4452
  });
4446
4453
  });
4447
4454
  }
4448
- function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl) {
4455
+ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl, options) {
4449
4456
  if (snapshot === void 0) { snapshot = 'latest'; }
4450
4457
  if (scoreApiUrl === void 0) { scoreApiUrl = 'https://score.snapshot.org/api/scores'; }
4458
+ if (options === void 0) { options = { returnValue: 'scores' }; }
4451
4459
  return __awaiter(this, void 0, void 0, function () {
4452
4460
  var params, res, obj, e_3;
4453
4461
  return __generator(this, function (_a) {
@@ -4463,7 +4471,7 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl)
4463
4471
  };
4464
4472
  return [4 /*yield*/, fetch(scoreApiUrl, {
4465
4473
  method: 'POST',
4466
- headers: { 'Content-Type': 'application/json' },
4474
+ headers: scoreApiHeaders,
4467
4475
  body: JSON.stringify({ params: params })
4468
4476
  })];
4469
4477
  case 1:
@@ -4471,7 +4479,7 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl)
4471
4479
  return [4 /*yield*/, res.json()];
4472
4480
  case 2:
4473
4481
  obj = _a.sent();
4474
- return [2 /*return*/, obj.result.scores];
4482
+ return [2 /*return*/, options.returnValue ? obj.result[options.returnValue] : obj.result];
4475
4483
  case 3:
4476
4484
  e_3 = _a.sent();
4477
4485
  return [2 /*return*/, Promise.reject(e_3)];
@@ -4492,10 +4500,7 @@ function getVp(address, network, strategies, snapshot, space, delegation, option
4492
4500
  options.url = 'https://score.snapshot.org';
4493
4501
  init = {
4494
4502
  method: 'POST',
4495
- headers: {
4496
- Accept: 'application/json',
4497
- 'Content-Type': 'application/json'
4498
- },
4503
+ headers: scoreApiHeaders,
4499
4504
  body: JSON.stringify({
4500
4505
  jsonrpc: '2.0',
4501
4506
  method: 'get_vp',
@@ -4506,8 +4511,7 @@ function getVp(address, network, strategies, snapshot, space, delegation, option
4506
4511
  snapshot: snapshot,
4507
4512
  space: space,
4508
4513
  delegation: delegation
4509
- },
4510
- id: null
4514
+ }
4511
4515
  })
4512
4516
  };
4513
4517
  return [4 /*yield*/, fetch(options.url, init)];
@@ -4537,10 +4541,7 @@ function validate(validation, author, space, network, snapshot, params, options)
4537
4541
  options.url = 'https://score.snapshot.org';
4538
4542
  init = {
4539
4543
  method: 'POST',
4540
- headers: {
4541
- Accept: 'application/json',
4542
- 'Content-Type': 'application/json'
4543
- },
4544
+ headers: scoreApiHeaders,
4544
4545
  body: JSON.stringify({
4545
4546
  jsonrpc: '2.0',
4546
4547
  method: 'validate',
@@ -4551,8 +4552,7 @@ function validate(validation, author, space, network, snapshot, params, options)
4551
4552
  network: network,
4552
4553
  snapshot: snapshot,
4553
4554
  params: params
4554
- },
4555
- id: null
4555
+ }
4556
4556
  })
4557
4557
  };
4558
4558
  return [4 /*yield*/, fetch(options.url, init)];