@snapshot-labs/snapshot.js 0.8.0-beta.0 → 0.8.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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var ofetch = require('ofetch');
3
+ var fetch = require('cross-fetch');
4
4
  var address = require('@ethersproject/address');
5
5
  var abi = require('@ethersproject/abi');
6
6
  var contracts = require('@ethersproject/contracts');
@@ -16,6 +16,7 @@ var wallet = require('@ethersproject/wallet');
16
16
 
17
17
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
18
 
19
+ var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
19
20
  var Ajv__default = /*#__PURE__*/_interopDefaultLegacy(Ajv);
20
21
  var addFormats__default = /*#__PURE__*/_interopDefaultLegacy(addFormats);
21
22
  var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
@@ -370,35 +371,29 @@ var Client = /** @class */ (function () {
370
371
  });
371
372
  };
372
373
  Client.prototype.send = function (envelop) {
373
- var _a, _b;
374
374
  return __awaiter(this, void 0, void 0, function () {
375
- var address, init, e_1, isSequencerError;
376
- return __generator(this, function (_c) {
377
- switch (_c.label) {
378
- case 0:
379
- address = this.address;
380
- if (envelop.sig === '0x' && this.options.relayerURL)
381
- address = this.options.relayerURL;
382
- init = {
383
- method: 'POST',
384
- headers: {
385
- Accept: 'application/json',
386
- 'Content-Type': 'application/json'
387
- },
388
- timeout: this.options.timeout || 20e3,
389
- body: envelop
390
- };
391
- _c.label = 1;
392
- case 1:
393
- _c.trys.push([1, 3, , 4]);
394
- return [4 /*yield*/, ofetch.ofetch(address, init)];
395
- case 2: return [2 /*return*/, _c.sent()];
396
- case 3:
397
- e_1 = _c.sent();
398
- isSequencerError = ((_a = e_1.data) === null || _a === void 0 ? void 0 : _a.hasOwnProperty('error')) && ((_b = e_1.data) === null || _b === void 0 ? void 0 : _b.hasOwnProperty('error_description'));
399
- return [2 /*return*/, Promise.reject(isSequencerError ? e_1.data : e_1)];
400
- case 4: return [2 /*return*/];
401
- }
375
+ var address, init;
376
+ return __generator(this, function (_a) {
377
+ address = this.address;
378
+ if (envelop.sig === '0x' && this.options.relayerURL)
379
+ address = this.options.relayerURL;
380
+ init = {
381
+ method: 'POST',
382
+ headers: {
383
+ Accept: 'application/json',
384
+ 'Content-Type': 'application/json'
385
+ },
386
+ body: JSON.stringify(envelop)
387
+ };
388
+ return [2 /*return*/, new Promise(function (resolve, reject) {
389
+ fetch__default['default'](address, init)
390
+ .then(function (res) {
391
+ if (res.ok)
392
+ return resolve(res.json());
393
+ throw res;
394
+ })
395
+ .catch(function (e) { return e.json().then(function (json) { return reject(json); }); });
396
+ })];
402
397
  });
403
398
  });
404
399
  };
@@ -1876,7 +1871,7 @@ var networks = {
1876
1871
  name: "XDC Apothem.network",
1877
1872
  shortName: "XDC",
1878
1873
  chainId: 51,
1879
- network: "testnet",
1874
+ network: "xdc",
1880
1875
  multicall: "0x3b353b02a8b42ee4222ea4be0836629b1f40c8db",
1881
1876
  rpc: [
1882
1877
  "https://apothemrpc.blocksscan.io"
@@ -2032,6 +2027,21 @@ var networks = {
2032
2027
  },
2033
2028
  start: 10780012,
2034
2029
  logo: "ipfs://QmXAKaNsyv6ctuRenYRJuZ1V4kn1eFwkUtjrjzX6jiKTqe"
2030
+ },
2031
+ "75": {
2032
+ key: "75",
2033
+ name: "Decimal",
2034
+ shortName: "mainnet",
2035
+ chainId: 75,
2036
+ network: "mainnet",
2037
+ multicall: "0x949d1A0757803C51F2EfFFEb5472C861A898B8E8",
2038
+ rpc: [
2039
+ ],
2040
+ explorer: {
2041
+ url: "https://explorer.decimalchain.com"
2042
+ },
2043
+ start: 16031065,
2044
+ logo: "ipfs://bafkreihkdhbce5rkogl63xegaarlirjrvbfarxbtbf5mqme3s5grvbjyxm"
2035
2045
  },
2036
2046
  "80": {
2037
2047
  key: "80",
@@ -2264,7 +2274,7 @@ var networks = {
2264
2274
  },
2265
2275
  "137": {
2266
2276
  key: "137",
2267
- name: "Polygon Mainnet",
2277
+ name: "Polygon PoS",
2268
2278
  shortName: "Polygon",
2269
2279
  chainId: 137,
2270
2280
  network: "mainnet",
@@ -2283,7 +2293,7 @@ var networks = {
2283
2293
  apiUrl: "https://api.polygonscan.com"
2284
2294
  },
2285
2295
  start: 9834491,
2286
- logo: "ipfs://QmaGokGqgjknfa4xnXKnnwC5ZyXzUjQ7p6KEe4D8G5uFFE"
2296
+ logo: "ipfs://bafkreihgr7zy7vi5kqddybfaezwuhvssg57qluwmyan4qq7l57nr7w7wey"
2287
2297
  },
2288
2298
  "144": {
2289
2299
  key: "144",
@@ -2331,6 +2341,21 @@ var networks = {
2331
2341
  },
2332
2342
  start: 4720651,
2333
2343
  logo: "ipfs://bafkreiabhsxuq35pp4kmrbptdeypd6clhcy3ue7ydpppo6onoo4igcjqia"
2344
+ },
2345
+ "204": {
2346
+ key: "204",
2347
+ name: "opBNB",
2348
+ shortName: "mainnet",
2349
+ chainId: 204,
2350
+ network: "mainnet",
2351
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
2352
+ rpc: [
2353
+ ],
2354
+ explorer: {
2355
+ url: "http://opbnbscan.com/"
2356
+ },
2357
+ start: 512881,
2358
+ logo: "ipfs://bafkreibll4la7wqerzs7zwxjne2j7ayynbg2wlenemssoahxxj5rbt6c64"
2334
2359
  },
2335
2360
  "246": {
2336
2361
  key: "246",
@@ -2392,7 +2417,6 @@ var networks = {
2392
2417
  shortName: "HPB",
2393
2418
  chainId: 269,
2394
2419
  network: "mainnet",
2395
- testnet: false,
2396
2420
  multicall: "0x67D0f263aef2F6167FA77353695D75b582Ff4Bca",
2397
2421
  rpc: [
2398
2422
  "https://hpbnode.com"
@@ -2438,6 +2462,21 @@ var networks = {
2438
2462
  },
2439
2463
  start: 74,
2440
2464
  logo: "ipfs://QmNc7QZFpPDue3Ef4SsuX55RHkqXxUxSyTCpoASeg2hW6d"
2465
+ },
2466
+ "314": {
2467
+ key: "314",
2468
+ name: "Filecoin",
2469
+ shortName: "mainnet",
2470
+ chainId: 314,
2471
+ network: "mainnet",
2472
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
2473
+ rpc: [
2474
+ ],
2475
+ explorer: {
2476
+ url: "https://filfox.io"
2477
+ },
2478
+ start: 3328594,
2479
+ logo: "ipfs://bafybeibyvjfmk6aqlfdrczvth55jkmnoadtrch7ht3rdmvqmy2bfxynecm"
2441
2480
  },
2442
2481
  "321": {
2443
2482
  key: "321",
@@ -2729,6 +2768,7 @@ var networks = {
2729
2768
  shortName: "pulsechain",
2730
2769
  chainId: 940,
2731
2770
  network: "Testnet",
2771
+ testnet: true,
2732
2772
  multicall: "0x5e67901C2Dd1915E9Ef49aF39B62C28DF8C2c529",
2733
2773
  rpc: [
2734
2774
  "https://rpc.testnet.pulsedisco.net"
@@ -2748,6 +2788,7 @@ var networks = {
2748
2788
  shortName: "pulsechain",
2749
2789
  chainId: 941,
2750
2790
  network: "Testnet v2B",
2791
+ testnet: true,
2751
2792
  multicall: "0x959a437F1444DaDaC8aF997E71EAF0479c810267",
2752
2793
  rpc: [
2753
2794
  "https://rpc.testnet.pulsedisco.net"
@@ -2767,6 +2808,7 @@ var networks = {
2767
2808
  shortName: "Boabab",
2768
2809
  chainId: 1001,
2769
2810
  network: "testnet",
2811
+ testnet: true,
2770
2812
  multicall: "0x40643B8Aeaaca0b87Ea1A1E596e64a0e14B1d244",
2771
2813
  rpc: [
2772
2814
  "https://archive-en.baobab.klaytn.net"
@@ -2775,7 +2817,7 @@ var networks = {
2775
2817
  "wss://archive-en.baobab.klaytn.net/ws"
2776
2818
  ],
2777
2819
  explorer: {
2778
- url: "https://baobab.scope.klaytn.com/"
2820
+ url: "https://baobab.scope.klaytn.com"
2779
2821
  },
2780
2822
  logo: "ipfs://QmYACyZcidcFtMo4Uf9H6ZKUxTP2TQPjGzNjcUjqYa64dt"
2781
2823
  },
@@ -2826,6 +2868,21 @@ var networks = {
2826
2868
  },
2827
2869
  start: 451,
2828
2870
  logo: "ipfs://QmYeskHqrEvWHqeAuqett64LxfH52HUXZi2T9BAMmgKvBF"
2871
+ },
2872
+ "1101": {
2873
+ key: "1101",
2874
+ name: "Polygon zkEVM",
2875
+ shortName: "mainnet",
2876
+ chainId: 1101,
2877
+ network: "mainnet",
2878
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
2879
+ rpc: [
2880
+ ],
2881
+ explorer: {
2882
+ url: "https://zkevm.polygonscan.com"
2883
+ },
2884
+ start: 57746,
2885
+ logo: "ipfs://bafkreibfiyvhqnme2vbxxfcku7qkxgjpkg6ywdkplxh4oxlkqsbznyorfm"
2829
2886
  },
2830
2887
  "1116": {
2831
2888
  key: "1116",
@@ -2945,6 +3002,7 @@ var networks = {
2945
3002
  shortName: "Gobi",
2946
3003
  chainId: 1663,
2947
3004
  network: "testnet",
3005
+ testnet: true,
2948
3006
  multicall: "0xC743e4910Bdd4e5aBacCA38F74cdA270281C5eef",
2949
3007
  rpc: [
2950
3008
  "https://gobi-testnet.horizenlabs.io/ethv1"
@@ -2977,7 +3035,6 @@ var networks = {
2977
3035
  shortName: "cube",
2978
3036
  chainId: 1818,
2979
3037
  network: "mainnet",
2980
- testnet: false,
2981
3038
  multicall: "0x28d2ebdb36369db1c51355cdc0898754d1a1c3c5",
2982
3039
  rpc: [
2983
3040
  "https://http-mainnet-archive.cube.network"
@@ -3117,6 +3174,21 @@ var networks = {
3117
3174
  },
3118
3175
  start: 2607889,
3119
3176
  logo: "ipfs://QmPXPCBho3kGLt5rhG9JGkKmzdtLvqZmJqGzzijVCuggWY"
3177
+ },
3178
+ "4337": {
3179
+ key: "4337",
3180
+ name: "Beam",
3181
+ shortName: "Beam",
3182
+ chainId: 4337,
3183
+ network: "mainnet",
3184
+ multicall: "0x4956F15eFdc3dC16645e90Cc356eAFA65fFC65Ec",
3185
+ rpc: [
3186
+ ],
3187
+ explorer: {
3188
+ url: "https://subnets.avax.network/beam/"
3189
+ },
3190
+ start: 1,
3191
+ logo: "ipfs://QmaKRLxXPdeTsLx7MFLS3CJbhpSbResgoeL4fCgHB1mTsF"
3120
3192
  },
3121
3193
  "4689": {
3122
3194
  key: "4689",
@@ -3202,6 +3274,7 @@ var networks = {
3202
3274
  name: "Ontology Testnet",
3203
3275
  chainId: 5851,
3204
3276
  network: "testnet",
3277
+ testnet: true,
3205
3278
  multicall: "0x381445710b5e73d34aF196c53A3D5cDa58EDBf7A",
3206
3279
  rpc: [
3207
3280
  "https://polaris1.ont.io:10339",
@@ -3254,7 +3327,6 @@ var networks = {
3254
3327
  shortName: "Shyft",
3255
3328
  chainId: 7341,
3256
3329
  network: "mainnet",
3257
- testnet: false,
3258
3330
  multicall: "0xceb10e9133D771cA93c8002Be527A465E85381a2",
3259
3331
  rpc: [
3260
3332
  "https://rpc.shyft.network"
@@ -3311,7 +3383,7 @@ var networks = {
3311
3383
  "wss://archive-en.cypress.klaytn.net/ws"
3312
3384
  ],
3313
3385
  explorer: {
3314
- url: "https://scope.klaytn.com/"
3386
+ url: "https://scope.klaytn.com"
3315
3387
  },
3316
3388
  logo: "ipfs://QmYACyZcidcFtMo4Uf9H6ZKUxTP2TQPjGzNjcUjqYa64dt"
3317
3389
  },
@@ -3356,7 +3428,6 @@ var networks = {
3356
3428
  shortName: "Evmos",
3357
3429
  chainId: 9001,
3358
3430
  network: "mainnet",
3359
- testnet: false,
3360
3431
  multicall: "0x37763d16f8dBf6F185368E0f256350cAb7E24b26",
3361
3432
  rpc: [
3362
3433
  "https://eth.bd.evmos.org:8545"
@@ -3468,6 +3539,22 @@ var networks = {
3468
3539
  },
3469
3540
  start: 79516,
3470
3541
  logo: "ipfs://QmTogMDLmDgJjDjUKDHDuc2KVTVDbXf8bXJLFiVe8PRxgo"
3542
+ },
3543
+ "13337": {
3544
+ key: "13337",
3545
+ name: "Beam Testnet",
3546
+ shortName: "testnet",
3547
+ chainId: 13337,
3548
+ network: "testnet",
3549
+ multicall: "0x9BF49b704EE2A095b95c1f2D4EB9010510c41C9E",
3550
+ rpc: [
3551
+ ],
3552
+ explorer: {
3553
+ url: "https://subnets-test.avax.network/beam/"
3554
+ },
3555
+ start: 3,
3556
+ logo: "ipfs://QmaKRLxXPdeTsLx7MFLS3CJbhpSbResgoeL4fCgHB1mTsF",
3557
+ testnet: true
3471
3558
  },
3472
3559
  "16718": {
3473
3560
  key: "16718",
@@ -3708,6 +3795,7 @@ var networks = {
3708
3795
  shortName: "ThinkiumTest1",
3709
3796
  chainId: 60001,
3710
3797
  network: "thinkiumtest1",
3798
+ testnet: true,
3711
3799
  multicall: "0xc49bc485d4f943b287edadbce45eb1a1220ffdfe",
3712
3800
  rpc: [
3713
3801
  "https://test1.thinkiumrpc.net"
@@ -3805,7 +3893,7 @@ var networks = {
3805
3893
  },
3806
3894
  "80001": {
3807
3895
  key: "80001",
3808
- name: "Matic Mumbai",
3896
+ name: "Polygon Mumbai",
3809
3897
  chainId: 80001,
3810
3898
  network: "testnet",
3811
3899
  testnet: true,
@@ -3822,7 +3910,7 @@ var networks = {
3822
3910
  apiUrl: "https://api-mumbai.polygonscan.com"
3823
3911
  },
3824
3912
  start: 12011090,
3825
- logo: "ipfs://QmaGokGqgjknfa4xnXKnnwC5ZyXzUjQ7p6KEe4D8G5uFFE"
3913
+ logo: "ipfs://bafkreihgr7zy7vi5kqddybfaezwuhvssg57qluwmyan4qq7l57nr7w7wey"
3826
3914
  },
3827
3915
  "84531": {
3828
3916
  key: "84531",
@@ -3878,6 +3966,7 @@ var networks = {
3878
3966
  shortName: "Vpioneer",
3879
3967
  chainId: 666666,
3880
3968
  network: "testnet",
3969
+ testnet: true,
3881
3970
  multicall: "0xb6E748D6632305E1c12D8369CC6B3eF4AA8A3c85",
3882
3971
  rpc: [
3883
3972
  "https://vpioneer.infragrid.v.network/ethereum/compatible"
@@ -4600,50 +4689,32 @@ function multicall(network, provider, abi$1, calls, options) {
4600
4689
  });
4601
4690
  }
4602
4691
  function subgraphRequest(url, query, options) {
4603
- var _a;
4692
+ if (options === void 0) { options = {}; }
4604
4693
  return __awaiter(this, void 0, void 0, function () {
4605
- var init, body, e_3;
4606
- return __generator(this, function (_b) {
4607
- switch (_b.label) {
4608
- case 0:
4609
- _b.trys.push([0, 2, , 3]);
4610
- init = {
4694
+ var res, responseData, data;
4695
+ return __generator(this, function (_a) {
4696
+ switch (_a.label) {
4697
+ case 0: return [4 /*yield*/, fetch__default['default'](url, {
4611
4698
  method: 'POST',
4612
4699
  headers: __assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers),
4613
- timeout: (options === null || options === void 0 ? void 0 : options.timeout) || 20e3,
4614
- body: { query: jsonToGraphqlQuery.jsonToGraphQLQuery({ query: query }) }
4615
- };
4616
- return [4 /*yield*/, ofetch.ofetch(url, init)];
4700
+ body: JSON.stringify({ query: jsonToGraphqlQuery.jsonToGraphQLQuery({ query: query }) })
4701
+ })];
4617
4702
  case 1:
4618
- body = _b.sent();
4619
- if (typeof body === 'string') {
4620
- return [2 /*return*/, Promise.reject({
4621
- errors: [
4622
- {
4623
- message: 'Body is not a JSON object',
4624
- extensions: { code: 'INVALID_JSON' }
4625
- }
4626
- ]
4627
- })];
4703
+ res = _a.sent();
4704
+ return [4 /*yield*/, res.text()];
4705
+ case 2:
4706
+ responseData = _a.sent();
4707
+ try {
4708
+ responseData = JSON.parse(responseData);
4628
4709
  }
4629
- if (body.errors) {
4630
- return [2 /*return*/, Promise.reject(body)];
4710
+ catch (e) {
4711
+ throw new Error("Errors found in subgraphRequest: URL: " + url + ", Status: " + res.status + ", Response: " + responseData.substring(0, 400));
4631
4712
  }
4632
- return [2 /*return*/, body.data];
4633
- case 2:
4634
- e_3 = _b.sent();
4635
- return [2 /*return*/, Promise.reject(((_a = e_3.data) === null || _a === void 0 ? void 0 : _a.errors) ? e_3.data
4636
- : {
4637
- errors: [
4638
- {
4639
- message: e_3.statusText || e_3.toString(),
4640
- extensions: {
4641
- code: e_3.status || 0
4642
- }
4643
- }
4644
- ]
4645
- })];
4646
- case 3: return [2 /*return*/];
4713
+ if (responseData.errors) {
4714
+ throw new Error("Errors found in subgraphRequest: URL: " + url + ", Status: " + res.status + ", Response: " + JSON.stringify(responseData.errors).substring(0, 400));
4715
+ }
4716
+ data = responseData.data;
4717
+ return [2 /*return*/, data || {}];
4647
4718
  }
4648
4719
  });
4649
4720
  });
@@ -4668,39 +4739,20 @@ function getUrl(uri, gateway) {
4668
4739
  function getJSON(uri, options) {
4669
4740
  if (options === void 0) { options = {}; }
4670
4741
  return __awaiter(this, void 0, void 0, function () {
4671
- var url, body;
4742
+ var url;
4672
4743
  return __generator(this, function (_a) {
4673
- switch (_a.label) {
4674
- case 0:
4675
- url = getUrl(uri, options.gateways) || '';
4676
- return [4 /*yield*/, ofetch.ofetch(url, {
4677
- timeout: options.timeout || 30e3,
4678
- headers: __assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers)
4679
- })];
4680
- case 1:
4681
- body = _a.sent();
4682
- return [2 /*return*/, typeof body === 'string' ? JSON.parse(body) : body];
4683
- }
4744
+ url = getUrl(uri, options.gateways);
4745
+ return [2 /*return*/, fetch__default['default'](url).then(function (res) { return res.json(); })];
4684
4746
  });
4685
4747
  });
4686
4748
  }
4687
- function ipfsGet(gateway, ipfsHash, protocolType, options) {
4749
+ function ipfsGet(gateway, ipfsHash, protocolType) {
4688
4750
  if (protocolType === void 0) { protocolType = 'ipfs'; }
4689
- if (options === void 0) { options = {}; }
4690
4751
  return __awaiter(this, void 0, void 0, function () {
4691
- var url, body;
4752
+ var url;
4692
4753
  return __generator(this, function (_a) {
4693
- switch (_a.label) {
4694
- case 0:
4695
- url = "https://" + gateway + "/" + protocolType + "/" + ipfsHash;
4696
- return [4 /*yield*/, ofetch.ofetch(url, {
4697
- timeout: options.timeout || 20e3,
4698
- headers: __assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, options.headers)
4699
- })];
4700
- case 1:
4701
- body = _a.sent();
4702
- return [2 /*return*/, typeof body === 'string' ? JSON.parse(body) : body];
4703
- }
4754
+ url = "https://" + gateway + "/" + protocolType + "/" + ipfsHash;
4755
+ return [2 /*return*/, fetch__default['default'](url).then(function (res) { return res.json(); })];
4704
4756
  });
4705
4757
  });
4706
4758
  }
@@ -4726,18 +4778,17 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl,
4726
4778
  if (snapshot === void 0) { snapshot = 'latest'; }
4727
4779
  if (scoreApiUrl === void 0) { scoreApiUrl = 'https://score.snapshot.org'; }
4728
4780
  if (options === void 0) { options = {}; }
4729
- var _a;
4730
4781
  return __awaiter(this, void 0, void 0, function () {
4731
- var url, params, body, e_4;
4732
- return __generator(this, function (_b) {
4733
- switch (_b.label) {
4782
+ var url, params, res, obj, e_3;
4783
+ return __generator(this, function (_a) {
4784
+ switch (_a.label) {
4734
4785
  case 0:
4735
4786
  url = new URL(scoreApiUrl);
4736
- url.pathname = options.pathname || '/api/scores';
4787
+ url.pathname = '/api/scores';
4737
4788
  scoreApiUrl = url.toString();
4738
- _b.label = 1;
4789
+ _a.label = 1;
4739
4790
  case 1:
4740
- _b.trys.push([1, 3, , 4]);
4791
+ _a.trys.push([1, 4, , 5]);
4741
4792
  params = {
4742
4793
  space: space,
4743
4794
  network: network,
@@ -4745,43 +4796,47 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl,
4745
4796
  strategies: strategies,
4746
4797
  addresses: addresses
4747
4798
  };
4748
- return [4 /*yield*/, ofetch.ofetch(scoreApiUrl, {
4799
+ return [4 /*yield*/, fetch__default['default'](scoreApiUrl, {
4749
4800
  method: 'POST',
4750
4801
  headers: scoreApiHeaders,
4751
- timeout: options.timeout || 60e3,
4752
- body: { params: params }
4802
+ body: JSON.stringify({ params: params })
4753
4803
  })];
4754
4804
  case 2:
4755
- body = _b.sent();
4756
- return [2 /*return*/, options.returnValue === 'all'
4757
- ? body.result
4758
- : body.result[options.returnValue || 'scores']];
4805
+ res = _a.sent();
4806
+ return [4 /*yield*/, res.json()];
4759
4807
  case 3:
4760
- e_4 = _b.sent();
4761
- return [2 /*return*/, Promise.reject(((_a = e_4.data) === null || _a === void 0 ? void 0 : _a.error) || {
4762
- code: e_4.status || 0,
4763
- message: e_4.statusText || e_4.toString(),
4764
- data: e_4.data || ''
4765
- })];
4766
- case 4: return [2 /*return*/];
4808
+ obj = _a.sent();
4809
+ if (obj.error) {
4810
+ return [2 /*return*/, Promise.reject(obj.error)];
4811
+ }
4812
+ return [2 /*return*/, options.returnValue === 'all'
4813
+ ? obj.result
4814
+ : obj.result[options.returnValue || 'scores']];
4815
+ case 4:
4816
+ e_3 = _a.sent();
4817
+ if (e_3.errno) {
4818
+ return [2 /*return*/, Promise.reject({ code: e_3.errno, message: e_3.toString(), data: '' })];
4819
+ }
4820
+ return [2 /*return*/, Promise.reject(e_3)];
4821
+ case 5: return [2 /*return*/];
4767
4822
  }
4768
4823
  });
4769
4824
  });
4770
4825
  }
4771
4826
  function getVp(address, network, strategies, snapshot, space, delegation, options) {
4772
- if (options === void 0) { options = {}; }
4773
- var _a;
4774
4827
  return __awaiter(this, void 0, void 0, function () {
4775
- var url, init, body, e_5;
4776
- return __generator(this, function (_b) {
4777
- switch (_b.label) {
4828
+ var init, res, json, e_4;
4829
+ return __generator(this, function (_a) {
4830
+ switch (_a.label) {
4778
4831
  case 0:
4779
- url = options.url || 'https://score.snapshot.org';
4832
+ if (!options)
4833
+ options = {};
4834
+ if (!options.url)
4835
+ options.url = 'https://score.snapshot.org';
4780
4836
  init = {
4781
4837
  method: 'POST',
4782
4838
  headers: scoreApiHeaders,
4783
- timeout: options.timeout || 60e3,
4784
- body: {
4839
+ body: JSON.stringify({
4785
4840
  jsonrpc: '2.0',
4786
4841
  method: 'get_vp',
4787
4842
  params: {
@@ -4792,41 +4847,47 @@ function getVp(address, network, strategies, snapshot, space, delegation, option
4792
4847
  space: space,
4793
4848
  delegation: delegation
4794
4849
  }
4795
- }
4850
+ })
4796
4851
  };
4797
- _b.label = 1;
4852
+ _a.label = 1;
4798
4853
  case 1:
4799
- _b.trys.push([1, 3, , 4]);
4800
- return [4 /*yield*/, ofetch.ofetch(url, init)];
4854
+ _a.trys.push([1, 4, , 5]);
4855
+ return [4 /*yield*/, fetch__default['default'](options.url, init)];
4801
4856
  case 2:
4802
- body = _b.sent();
4803
- return [2 /*return*/, body.result];
4857
+ res = _a.sent();
4858
+ return [4 /*yield*/, res.json()];
4804
4859
  case 3:
4805
- e_5 = _b.sent();
4806
- return [2 /*return*/, Promise.reject(((_a = e_5.data) === null || _a === void 0 ? void 0 : _a.error) || {
4807
- code: e_5.status || 0,
4808
- message: e_5.statusText || e_5.toString(),
4809
- data: e_5.data || ''
4810
- })];
4811
- case 4: return [2 /*return*/];
4860
+ json = _a.sent();
4861
+ if (json.error)
4862
+ return [2 /*return*/, Promise.reject(json.error)];
4863
+ if (json.result)
4864
+ return [2 /*return*/, json.result];
4865
+ return [3 /*break*/, 5];
4866
+ case 4:
4867
+ e_4 = _a.sent();
4868
+ if (e_4.errno) {
4869
+ return [2 /*return*/, Promise.reject({ code: e_4.errno, message: e_4.toString(), data: '' })];
4870
+ }
4871
+ return [2 /*return*/, Promise.reject(e_4)];
4872
+ case 5: return [2 /*return*/];
4812
4873
  }
4813
4874
  });
4814
4875
  });
4815
4876
  }
4816
4877
  function validate(validation, author, space, network, snapshot, params, options) {
4817
- if (options === void 0) { options = {}; }
4818
- var _a;
4819
4878
  return __awaiter(this, void 0, void 0, function () {
4820
- var url, init, body, e_6;
4821
- return __generator(this, function (_b) {
4822
- switch (_b.label) {
4879
+ var init, res, json, e_5;
4880
+ return __generator(this, function (_a) {
4881
+ switch (_a.label) {
4823
4882
  case 0:
4824
- url = options.url || 'https://score.snapshot.org';
4883
+ if (!options)
4884
+ options = {};
4885
+ if (!options.url)
4886
+ options.url = 'https://score.snapshot.org';
4825
4887
  init = {
4826
4888
  method: 'POST',
4827
4889
  headers: scoreApiHeaders,
4828
- timeout: options.timeout || 30e3,
4829
- body: {
4890
+ body: JSON.stringify({
4830
4891
  jsonrpc: '2.0',
4831
4892
  method: 'validate',
4832
4893
  params: {
@@ -4837,23 +4898,27 @@ function validate(validation, author, space, network, snapshot, params, options)
4837
4898
  snapshot: snapshot,
4838
4899
  params: params
4839
4900
  }
4840
- }
4901
+ })
4841
4902
  };
4842
- _b.label = 1;
4903
+ _a.label = 1;
4843
4904
  case 1:
4844
- _b.trys.push([1, 3, , 4]);
4845
- return [4 /*yield*/, ofetch.ofetch(url, init)];
4905
+ _a.trys.push([1, 4, , 5]);
4906
+ return [4 /*yield*/, fetch__default['default'](options.url, init)];
4846
4907
  case 2:
4847
- body = _b.sent();
4848
- return [2 /*return*/, body.result];
4908
+ res = _a.sent();
4909
+ return [4 /*yield*/, res.json()];
4849
4910
  case 3:
4850
- e_6 = _b.sent();
4851
- return [2 /*return*/, Promise.reject(((_a = e_6.data) === null || _a === void 0 ? void 0 : _a.error) || {
4852
- code: e_6.status || 0,
4853
- message: e_6.statusText || e_6.toString(),
4854
- data: e_6.data || ''
4855
- })];
4856
- case 4: return [2 /*return*/];
4911
+ json = _a.sent();
4912
+ if (json.error)
4913
+ return [2 /*return*/, Promise.reject(json.error)];
4914
+ return [2 /*return*/, json.result];
4915
+ case 4:
4916
+ e_5 = _a.sent();
4917
+ if (e_5.errno) {
4918
+ return [2 /*return*/, Promise.reject({ code: e_5.errno, message: e_5.toString(), data: '' })];
4919
+ }
4920
+ return [2 /*return*/, Promise.reject(e_5)];
4921
+ case 5: return [2 /*return*/];
4857
4922
  }
4858
4923
  });
4859
4924
  });
@@ -4889,7 +4954,7 @@ function getSpaceUri(id, network, options) {
4889
4954
  if (network === void 0) { network = '1'; }
4890
4955
  if (options === void 0) { options = {}; }
4891
4956
  return __awaiter(this, void 0, void 0, function () {
4892
- var e_7;
4957
+ var e_6;
4893
4958
  return __generator(this, function (_a) {
4894
4959
  switch (_a.label) {
4895
4960
  case 0:
@@ -4897,8 +4962,8 @@ function getSpaceUri(id, network, options) {
4897
4962
  return [4 /*yield*/, getEnsTextRecord(id, 'snapshot', network, options)];
4898
4963
  case 1: return [2 /*return*/, _a.sent()];
4899
4964
  case 2:
4900
- e_7 = _a.sent();
4901
- console.log(e_7);
4965
+ e_6 = _a.sent();
4966
+ console.log(e_6);
4902
4967
  return [2 /*return*/, null];
4903
4968
  case 3: return [2 /*return*/];
4904
4969
  }