@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,4 +1,4 @@
1
- import { ofetch } from 'ofetch';
1
+ import fetch from 'cross-fetch';
2
2
  import { getAddress, isAddress } from '@ethersproject/address';
3
3
  import { Interface } from '@ethersproject/abi';
4
4
  import { Contract } from '@ethersproject/contracts';
@@ -362,35 +362,29 @@ var Client = /** @class */ (function () {
362
362
  });
363
363
  };
364
364
  Client.prototype.send = function (envelop) {
365
- var _a, _b;
366
365
  return __awaiter(this, void 0, void 0, function () {
367
- var address, init, e_1, isSequencerError;
368
- return __generator(this, function (_c) {
369
- switch (_c.label) {
370
- case 0:
371
- address = this.address;
372
- if (envelop.sig === '0x' && this.options.relayerURL)
373
- address = this.options.relayerURL;
374
- init = {
375
- method: 'POST',
376
- headers: {
377
- Accept: 'application/json',
378
- 'Content-Type': 'application/json'
379
- },
380
- timeout: this.options.timeout || 20e3,
381
- body: envelop
382
- };
383
- _c.label = 1;
384
- case 1:
385
- _c.trys.push([1, 3, , 4]);
386
- return [4 /*yield*/, ofetch(address, init)];
387
- case 2: return [2 /*return*/, _c.sent()];
388
- case 3:
389
- e_1 = _c.sent();
390
- 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'));
391
- return [2 /*return*/, Promise.reject(isSequencerError ? e_1.data : e_1)];
392
- case 4: return [2 /*return*/];
393
- }
366
+ var address, init;
367
+ return __generator(this, function (_a) {
368
+ address = this.address;
369
+ if (envelop.sig === '0x' && this.options.relayerURL)
370
+ address = this.options.relayerURL;
371
+ init = {
372
+ method: 'POST',
373
+ headers: {
374
+ Accept: 'application/json',
375
+ 'Content-Type': 'application/json'
376
+ },
377
+ body: JSON.stringify(envelop)
378
+ };
379
+ return [2 /*return*/, new Promise(function (resolve, reject) {
380
+ fetch(address, init)
381
+ .then(function (res) {
382
+ if (res.ok)
383
+ return resolve(res.json());
384
+ throw res;
385
+ })
386
+ .catch(function (e) { return e.json().then(function (json) { return reject(json); }); });
387
+ })];
394
388
  });
395
389
  });
396
390
  };
@@ -1868,7 +1862,7 @@ var networks = {
1868
1862
  name: "XDC Apothem.network",
1869
1863
  shortName: "XDC",
1870
1864
  chainId: 51,
1871
- network: "testnet",
1865
+ network: "xdc",
1872
1866
  multicall: "0x3b353b02a8b42ee4222ea4be0836629b1f40c8db",
1873
1867
  rpc: [
1874
1868
  "https://apothemrpc.blocksscan.io"
@@ -2024,6 +2018,21 @@ var networks = {
2024
2018
  },
2025
2019
  start: 10780012,
2026
2020
  logo: "ipfs://QmXAKaNsyv6ctuRenYRJuZ1V4kn1eFwkUtjrjzX6jiKTqe"
2021
+ },
2022
+ "75": {
2023
+ key: "75",
2024
+ name: "Decimal",
2025
+ shortName: "mainnet",
2026
+ chainId: 75,
2027
+ network: "mainnet",
2028
+ multicall: "0x949d1A0757803C51F2EfFFEb5472C861A898B8E8",
2029
+ rpc: [
2030
+ ],
2031
+ explorer: {
2032
+ url: "https://explorer.decimalchain.com"
2033
+ },
2034
+ start: 16031065,
2035
+ logo: "ipfs://bafkreihkdhbce5rkogl63xegaarlirjrvbfarxbtbf5mqme3s5grvbjyxm"
2027
2036
  },
2028
2037
  "80": {
2029
2038
  key: "80",
@@ -2256,7 +2265,7 @@ var networks = {
2256
2265
  },
2257
2266
  "137": {
2258
2267
  key: "137",
2259
- name: "Polygon Mainnet",
2268
+ name: "Polygon PoS",
2260
2269
  shortName: "Polygon",
2261
2270
  chainId: 137,
2262
2271
  network: "mainnet",
@@ -2275,7 +2284,7 @@ var networks = {
2275
2284
  apiUrl: "https://api.polygonscan.com"
2276
2285
  },
2277
2286
  start: 9834491,
2278
- logo: "ipfs://QmaGokGqgjknfa4xnXKnnwC5ZyXzUjQ7p6KEe4D8G5uFFE"
2287
+ logo: "ipfs://bafkreihgr7zy7vi5kqddybfaezwuhvssg57qluwmyan4qq7l57nr7w7wey"
2279
2288
  },
2280
2289
  "144": {
2281
2290
  key: "144",
@@ -2323,6 +2332,21 @@ var networks = {
2323
2332
  },
2324
2333
  start: 4720651,
2325
2334
  logo: "ipfs://bafkreiabhsxuq35pp4kmrbptdeypd6clhcy3ue7ydpppo6onoo4igcjqia"
2335
+ },
2336
+ "204": {
2337
+ key: "204",
2338
+ name: "opBNB",
2339
+ shortName: "mainnet",
2340
+ chainId: 204,
2341
+ network: "mainnet",
2342
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
2343
+ rpc: [
2344
+ ],
2345
+ explorer: {
2346
+ url: "http://opbnbscan.com/"
2347
+ },
2348
+ start: 512881,
2349
+ logo: "ipfs://bafkreibll4la7wqerzs7zwxjne2j7ayynbg2wlenemssoahxxj5rbt6c64"
2326
2350
  },
2327
2351
  "246": {
2328
2352
  key: "246",
@@ -2384,7 +2408,6 @@ var networks = {
2384
2408
  shortName: "HPB",
2385
2409
  chainId: 269,
2386
2410
  network: "mainnet",
2387
- testnet: false,
2388
2411
  multicall: "0x67D0f263aef2F6167FA77353695D75b582Ff4Bca",
2389
2412
  rpc: [
2390
2413
  "https://hpbnode.com"
@@ -2430,6 +2453,21 @@ var networks = {
2430
2453
  },
2431
2454
  start: 74,
2432
2455
  logo: "ipfs://QmNc7QZFpPDue3Ef4SsuX55RHkqXxUxSyTCpoASeg2hW6d"
2456
+ },
2457
+ "314": {
2458
+ key: "314",
2459
+ name: "Filecoin",
2460
+ shortName: "mainnet",
2461
+ chainId: 314,
2462
+ network: "mainnet",
2463
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
2464
+ rpc: [
2465
+ ],
2466
+ explorer: {
2467
+ url: "https://filfox.io"
2468
+ },
2469
+ start: 3328594,
2470
+ logo: "ipfs://bafybeibyvjfmk6aqlfdrczvth55jkmnoadtrch7ht3rdmvqmy2bfxynecm"
2433
2471
  },
2434
2472
  "321": {
2435
2473
  key: "321",
@@ -2721,6 +2759,7 @@ var networks = {
2721
2759
  shortName: "pulsechain",
2722
2760
  chainId: 940,
2723
2761
  network: "Testnet",
2762
+ testnet: true,
2724
2763
  multicall: "0x5e67901C2Dd1915E9Ef49aF39B62C28DF8C2c529",
2725
2764
  rpc: [
2726
2765
  "https://rpc.testnet.pulsedisco.net"
@@ -2740,6 +2779,7 @@ var networks = {
2740
2779
  shortName: "pulsechain",
2741
2780
  chainId: 941,
2742
2781
  network: "Testnet v2B",
2782
+ testnet: true,
2743
2783
  multicall: "0x959a437F1444DaDaC8aF997E71EAF0479c810267",
2744
2784
  rpc: [
2745
2785
  "https://rpc.testnet.pulsedisco.net"
@@ -2759,6 +2799,7 @@ var networks = {
2759
2799
  shortName: "Boabab",
2760
2800
  chainId: 1001,
2761
2801
  network: "testnet",
2802
+ testnet: true,
2762
2803
  multicall: "0x40643B8Aeaaca0b87Ea1A1E596e64a0e14B1d244",
2763
2804
  rpc: [
2764
2805
  "https://archive-en.baobab.klaytn.net"
@@ -2767,7 +2808,7 @@ var networks = {
2767
2808
  "wss://archive-en.baobab.klaytn.net/ws"
2768
2809
  ],
2769
2810
  explorer: {
2770
- url: "https://baobab.scope.klaytn.com/"
2811
+ url: "https://baobab.scope.klaytn.com"
2771
2812
  },
2772
2813
  logo: "ipfs://QmYACyZcidcFtMo4Uf9H6ZKUxTP2TQPjGzNjcUjqYa64dt"
2773
2814
  },
@@ -2818,6 +2859,21 @@ var networks = {
2818
2859
  },
2819
2860
  start: 451,
2820
2861
  logo: "ipfs://QmYeskHqrEvWHqeAuqett64LxfH52HUXZi2T9BAMmgKvBF"
2862
+ },
2863
+ "1101": {
2864
+ key: "1101",
2865
+ name: "Polygon zkEVM",
2866
+ shortName: "mainnet",
2867
+ chainId: 1101,
2868
+ network: "mainnet",
2869
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
2870
+ rpc: [
2871
+ ],
2872
+ explorer: {
2873
+ url: "https://zkevm.polygonscan.com"
2874
+ },
2875
+ start: 57746,
2876
+ logo: "ipfs://bafkreibfiyvhqnme2vbxxfcku7qkxgjpkg6ywdkplxh4oxlkqsbznyorfm"
2821
2877
  },
2822
2878
  "1116": {
2823
2879
  key: "1116",
@@ -2937,6 +2993,7 @@ var networks = {
2937
2993
  shortName: "Gobi",
2938
2994
  chainId: 1663,
2939
2995
  network: "testnet",
2996
+ testnet: true,
2940
2997
  multicall: "0xC743e4910Bdd4e5aBacCA38F74cdA270281C5eef",
2941
2998
  rpc: [
2942
2999
  "https://gobi-testnet.horizenlabs.io/ethv1"
@@ -2969,7 +3026,6 @@ var networks = {
2969
3026
  shortName: "cube",
2970
3027
  chainId: 1818,
2971
3028
  network: "mainnet",
2972
- testnet: false,
2973
3029
  multicall: "0x28d2ebdb36369db1c51355cdc0898754d1a1c3c5",
2974
3030
  rpc: [
2975
3031
  "https://http-mainnet-archive.cube.network"
@@ -3109,6 +3165,21 @@ var networks = {
3109
3165
  },
3110
3166
  start: 2607889,
3111
3167
  logo: "ipfs://QmPXPCBho3kGLt5rhG9JGkKmzdtLvqZmJqGzzijVCuggWY"
3168
+ },
3169
+ "4337": {
3170
+ key: "4337",
3171
+ name: "Beam",
3172
+ shortName: "Beam",
3173
+ chainId: 4337,
3174
+ network: "mainnet",
3175
+ multicall: "0x4956F15eFdc3dC16645e90Cc356eAFA65fFC65Ec",
3176
+ rpc: [
3177
+ ],
3178
+ explorer: {
3179
+ url: "https://subnets.avax.network/beam/"
3180
+ },
3181
+ start: 1,
3182
+ logo: "ipfs://QmaKRLxXPdeTsLx7MFLS3CJbhpSbResgoeL4fCgHB1mTsF"
3112
3183
  },
3113
3184
  "4689": {
3114
3185
  key: "4689",
@@ -3194,6 +3265,7 @@ var networks = {
3194
3265
  name: "Ontology Testnet",
3195
3266
  chainId: 5851,
3196
3267
  network: "testnet",
3268
+ testnet: true,
3197
3269
  multicall: "0x381445710b5e73d34aF196c53A3D5cDa58EDBf7A",
3198
3270
  rpc: [
3199
3271
  "https://polaris1.ont.io:10339",
@@ -3246,7 +3318,6 @@ var networks = {
3246
3318
  shortName: "Shyft",
3247
3319
  chainId: 7341,
3248
3320
  network: "mainnet",
3249
- testnet: false,
3250
3321
  multicall: "0xceb10e9133D771cA93c8002Be527A465E85381a2",
3251
3322
  rpc: [
3252
3323
  "https://rpc.shyft.network"
@@ -3303,7 +3374,7 @@ var networks = {
3303
3374
  "wss://archive-en.cypress.klaytn.net/ws"
3304
3375
  ],
3305
3376
  explorer: {
3306
- url: "https://scope.klaytn.com/"
3377
+ url: "https://scope.klaytn.com"
3307
3378
  },
3308
3379
  logo: "ipfs://QmYACyZcidcFtMo4Uf9H6ZKUxTP2TQPjGzNjcUjqYa64dt"
3309
3380
  },
@@ -3348,7 +3419,6 @@ var networks = {
3348
3419
  shortName: "Evmos",
3349
3420
  chainId: 9001,
3350
3421
  network: "mainnet",
3351
- testnet: false,
3352
3422
  multicall: "0x37763d16f8dBf6F185368E0f256350cAb7E24b26",
3353
3423
  rpc: [
3354
3424
  "https://eth.bd.evmos.org:8545"
@@ -3460,6 +3530,22 @@ var networks = {
3460
3530
  },
3461
3531
  start: 79516,
3462
3532
  logo: "ipfs://QmTogMDLmDgJjDjUKDHDuc2KVTVDbXf8bXJLFiVe8PRxgo"
3533
+ },
3534
+ "13337": {
3535
+ key: "13337",
3536
+ name: "Beam Testnet",
3537
+ shortName: "testnet",
3538
+ chainId: 13337,
3539
+ network: "testnet",
3540
+ multicall: "0x9BF49b704EE2A095b95c1f2D4EB9010510c41C9E",
3541
+ rpc: [
3542
+ ],
3543
+ explorer: {
3544
+ url: "https://subnets-test.avax.network/beam/"
3545
+ },
3546
+ start: 3,
3547
+ logo: "ipfs://QmaKRLxXPdeTsLx7MFLS3CJbhpSbResgoeL4fCgHB1mTsF",
3548
+ testnet: true
3463
3549
  },
3464
3550
  "16718": {
3465
3551
  key: "16718",
@@ -3700,6 +3786,7 @@ var networks = {
3700
3786
  shortName: "ThinkiumTest1",
3701
3787
  chainId: 60001,
3702
3788
  network: "thinkiumtest1",
3789
+ testnet: true,
3703
3790
  multicall: "0xc49bc485d4f943b287edadbce45eb1a1220ffdfe",
3704
3791
  rpc: [
3705
3792
  "https://test1.thinkiumrpc.net"
@@ -3797,7 +3884,7 @@ var networks = {
3797
3884
  },
3798
3885
  "80001": {
3799
3886
  key: "80001",
3800
- name: "Matic Mumbai",
3887
+ name: "Polygon Mumbai",
3801
3888
  chainId: 80001,
3802
3889
  network: "testnet",
3803
3890
  testnet: true,
@@ -3814,7 +3901,7 @@ var networks = {
3814
3901
  apiUrl: "https://api-mumbai.polygonscan.com"
3815
3902
  },
3816
3903
  start: 12011090,
3817
- logo: "ipfs://QmaGokGqgjknfa4xnXKnnwC5ZyXzUjQ7p6KEe4D8G5uFFE"
3904
+ logo: "ipfs://bafkreihgr7zy7vi5kqddybfaezwuhvssg57qluwmyan4qq7l57nr7w7wey"
3818
3905
  },
3819
3906
  "84531": {
3820
3907
  key: "84531",
@@ -3870,6 +3957,7 @@ var networks = {
3870
3957
  shortName: "Vpioneer",
3871
3958
  chainId: 666666,
3872
3959
  network: "testnet",
3960
+ testnet: true,
3873
3961
  multicall: "0xb6E748D6632305E1c12D8369CC6B3eF4AA8A3c85",
3874
3962
  rpc: [
3875
3963
  "https://vpioneer.infragrid.v.network/ethereum/compatible"
@@ -4592,50 +4680,32 @@ function multicall(network, provider, abi, calls, options) {
4592
4680
  });
4593
4681
  }
4594
4682
  function subgraphRequest(url, query, options) {
4595
- var _a;
4683
+ if (options === void 0) { options = {}; }
4596
4684
  return __awaiter(this, void 0, void 0, function () {
4597
- var init, body, e_3;
4598
- return __generator(this, function (_b) {
4599
- switch (_b.label) {
4600
- case 0:
4601
- _b.trys.push([0, 2, , 3]);
4602
- init = {
4685
+ var res, responseData, data;
4686
+ return __generator(this, function (_a) {
4687
+ switch (_a.label) {
4688
+ case 0: return [4 /*yield*/, fetch(url, {
4603
4689
  method: 'POST',
4604
4690
  headers: __assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers),
4605
- timeout: (options === null || options === void 0 ? void 0 : options.timeout) || 20e3,
4606
- body: { query: jsonToGraphQLQuery({ query: query }) }
4607
- };
4608
- return [4 /*yield*/, ofetch(url, init)];
4691
+ body: JSON.stringify({ query: jsonToGraphQLQuery({ query: query }) })
4692
+ })];
4609
4693
  case 1:
4610
- body = _b.sent();
4611
- if (typeof body === 'string') {
4612
- return [2 /*return*/, Promise.reject({
4613
- errors: [
4614
- {
4615
- message: 'Body is not a JSON object',
4616
- extensions: { code: 'INVALID_JSON' }
4617
- }
4618
- ]
4619
- })];
4694
+ res = _a.sent();
4695
+ return [4 /*yield*/, res.text()];
4696
+ case 2:
4697
+ responseData = _a.sent();
4698
+ try {
4699
+ responseData = JSON.parse(responseData);
4620
4700
  }
4621
- if (body.errors) {
4622
- return [2 /*return*/, Promise.reject(body)];
4701
+ catch (e) {
4702
+ throw new Error("Errors found in subgraphRequest: URL: " + url + ", Status: " + res.status + ", Response: " + responseData.substring(0, 400));
4623
4703
  }
4624
- return [2 /*return*/, body.data];
4625
- case 2:
4626
- e_3 = _b.sent();
4627
- return [2 /*return*/, Promise.reject(((_a = e_3.data) === null || _a === void 0 ? void 0 : _a.errors) ? e_3.data
4628
- : {
4629
- errors: [
4630
- {
4631
- message: e_3.statusText || e_3.toString(),
4632
- extensions: {
4633
- code: e_3.status || 0
4634
- }
4635
- }
4636
- ]
4637
- })];
4638
- case 3: return [2 /*return*/];
4704
+ if (responseData.errors) {
4705
+ throw new Error("Errors found in subgraphRequest: URL: " + url + ", Status: " + res.status + ", Response: " + JSON.stringify(responseData.errors).substring(0, 400));
4706
+ }
4707
+ data = responseData.data;
4708
+ return [2 /*return*/, data || {}];
4639
4709
  }
4640
4710
  });
4641
4711
  });
@@ -4660,39 +4730,20 @@ function getUrl(uri, gateway) {
4660
4730
  function getJSON(uri, options) {
4661
4731
  if (options === void 0) { options = {}; }
4662
4732
  return __awaiter(this, void 0, void 0, function () {
4663
- var url, body;
4733
+ var url;
4664
4734
  return __generator(this, function (_a) {
4665
- switch (_a.label) {
4666
- case 0:
4667
- url = getUrl(uri, options.gateways) || '';
4668
- return [4 /*yield*/, ofetch(url, {
4669
- timeout: options.timeout || 30e3,
4670
- headers: __assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers)
4671
- })];
4672
- case 1:
4673
- body = _a.sent();
4674
- return [2 /*return*/, typeof body === 'string' ? JSON.parse(body) : body];
4675
- }
4735
+ url = getUrl(uri, options.gateways);
4736
+ return [2 /*return*/, fetch(url).then(function (res) { return res.json(); })];
4676
4737
  });
4677
4738
  });
4678
4739
  }
4679
- function ipfsGet(gateway, ipfsHash, protocolType, options) {
4740
+ function ipfsGet(gateway, ipfsHash, protocolType) {
4680
4741
  if (protocolType === void 0) { protocolType = 'ipfs'; }
4681
- if (options === void 0) { options = {}; }
4682
4742
  return __awaiter(this, void 0, void 0, function () {
4683
- var url, body;
4743
+ var url;
4684
4744
  return __generator(this, function (_a) {
4685
- switch (_a.label) {
4686
- case 0:
4687
- url = "https://" + gateway + "/" + protocolType + "/" + ipfsHash;
4688
- return [4 /*yield*/, ofetch(url, {
4689
- timeout: options.timeout || 20e3,
4690
- headers: __assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, options.headers)
4691
- })];
4692
- case 1:
4693
- body = _a.sent();
4694
- return [2 /*return*/, typeof body === 'string' ? JSON.parse(body) : body];
4695
- }
4745
+ url = "https://" + gateway + "/" + protocolType + "/" + ipfsHash;
4746
+ return [2 /*return*/, fetch(url).then(function (res) { return res.json(); })];
4696
4747
  });
4697
4748
  });
4698
4749
  }
@@ -4718,18 +4769,17 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl,
4718
4769
  if (snapshot === void 0) { snapshot = 'latest'; }
4719
4770
  if (scoreApiUrl === void 0) { scoreApiUrl = 'https://score.snapshot.org'; }
4720
4771
  if (options === void 0) { options = {}; }
4721
- var _a;
4722
4772
  return __awaiter(this, void 0, void 0, function () {
4723
- var url, params, body, e_4;
4724
- return __generator(this, function (_b) {
4725
- switch (_b.label) {
4773
+ var url, params, res, obj, e_3;
4774
+ return __generator(this, function (_a) {
4775
+ switch (_a.label) {
4726
4776
  case 0:
4727
4777
  url = new URL(scoreApiUrl);
4728
- url.pathname = options.pathname || '/api/scores';
4778
+ url.pathname = '/api/scores';
4729
4779
  scoreApiUrl = url.toString();
4730
- _b.label = 1;
4780
+ _a.label = 1;
4731
4781
  case 1:
4732
- _b.trys.push([1, 3, , 4]);
4782
+ _a.trys.push([1, 4, , 5]);
4733
4783
  params = {
4734
4784
  space: space,
4735
4785
  network: network,
@@ -4737,43 +4787,47 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl,
4737
4787
  strategies: strategies,
4738
4788
  addresses: addresses
4739
4789
  };
4740
- return [4 /*yield*/, ofetch(scoreApiUrl, {
4790
+ return [4 /*yield*/, fetch(scoreApiUrl, {
4741
4791
  method: 'POST',
4742
4792
  headers: scoreApiHeaders,
4743
- timeout: options.timeout || 60e3,
4744
- body: { params: params }
4793
+ body: JSON.stringify({ params: params })
4745
4794
  })];
4746
4795
  case 2:
4747
- body = _b.sent();
4748
- return [2 /*return*/, options.returnValue === 'all'
4749
- ? body.result
4750
- : body.result[options.returnValue || 'scores']];
4796
+ res = _a.sent();
4797
+ return [4 /*yield*/, res.json()];
4751
4798
  case 3:
4752
- e_4 = _b.sent();
4753
- return [2 /*return*/, Promise.reject(((_a = e_4.data) === null || _a === void 0 ? void 0 : _a.error) || {
4754
- code: e_4.status || 0,
4755
- message: e_4.statusText || e_4.toString(),
4756
- data: e_4.data || ''
4757
- })];
4758
- case 4: return [2 /*return*/];
4799
+ obj = _a.sent();
4800
+ if (obj.error) {
4801
+ return [2 /*return*/, Promise.reject(obj.error)];
4802
+ }
4803
+ return [2 /*return*/, options.returnValue === 'all'
4804
+ ? obj.result
4805
+ : obj.result[options.returnValue || 'scores']];
4806
+ case 4:
4807
+ e_3 = _a.sent();
4808
+ if (e_3.errno) {
4809
+ return [2 /*return*/, Promise.reject({ code: e_3.errno, message: e_3.toString(), data: '' })];
4810
+ }
4811
+ return [2 /*return*/, Promise.reject(e_3)];
4812
+ case 5: return [2 /*return*/];
4759
4813
  }
4760
4814
  });
4761
4815
  });
4762
4816
  }
4763
4817
  function getVp(address, network, strategies, snapshot, space, delegation, options) {
4764
- if (options === void 0) { options = {}; }
4765
- var _a;
4766
4818
  return __awaiter(this, void 0, void 0, function () {
4767
- var url, init, body, e_5;
4768
- return __generator(this, function (_b) {
4769
- switch (_b.label) {
4819
+ var init, res, json, e_4;
4820
+ return __generator(this, function (_a) {
4821
+ switch (_a.label) {
4770
4822
  case 0:
4771
- url = options.url || 'https://score.snapshot.org';
4823
+ if (!options)
4824
+ options = {};
4825
+ if (!options.url)
4826
+ options.url = 'https://score.snapshot.org';
4772
4827
  init = {
4773
4828
  method: 'POST',
4774
4829
  headers: scoreApiHeaders,
4775
- timeout: options.timeout || 60e3,
4776
- body: {
4830
+ body: JSON.stringify({
4777
4831
  jsonrpc: '2.0',
4778
4832
  method: 'get_vp',
4779
4833
  params: {
@@ -4784,41 +4838,47 @@ function getVp(address, network, strategies, snapshot, space, delegation, option
4784
4838
  space: space,
4785
4839
  delegation: delegation
4786
4840
  }
4787
- }
4841
+ })
4788
4842
  };
4789
- _b.label = 1;
4843
+ _a.label = 1;
4790
4844
  case 1:
4791
- _b.trys.push([1, 3, , 4]);
4792
- return [4 /*yield*/, ofetch(url, init)];
4845
+ _a.trys.push([1, 4, , 5]);
4846
+ return [4 /*yield*/, fetch(options.url, init)];
4793
4847
  case 2:
4794
- body = _b.sent();
4795
- return [2 /*return*/, body.result];
4848
+ res = _a.sent();
4849
+ return [4 /*yield*/, res.json()];
4796
4850
  case 3:
4797
- e_5 = _b.sent();
4798
- return [2 /*return*/, Promise.reject(((_a = e_5.data) === null || _a === void 0 ? void 0 : _a.error) || {
4799
- code: e_5.status || 0,
4800
- message: e_5.statusText || e_5.toString(),
4801
- data: e_5.data || ''
4802
- })];
4803
- case 4: return [2 /*return*/];
4851
+ json = _a.sent();
4852
+ if (json.error)
4853
+ return [2 /*return*/, Promise.reject(json.error)];
4854
+ if (json.result)
4855
+ return [2 /*return*/, json.result];
4856
+ return [3 /*break*/, 5];
4857
+ case 4:
4858
+ e_4 = _a.sent();
4859
+ if (e_4.errno) {
4860
+ return [2 /*return*/, Promise.reject({ code: e_4.errno, message: e_4.toString(), data: '' })];
4861
+ }
4862
+ return [2 /*return*/, Promise.reject(e_4)];
4863
+ case 5: return [2 /*return*/];
4804
4864
  }
4805
4865
  });
4806
4866
  });
4807
4867
  }
4808
4868
  function validate(validation, author, space, network, snapshot, params, options) {
4809
- if (options === void 0) { options = {}; }
4810
- var _a;
4811
4869
  return __awaiter(this, void 0, void 0, function () {
4812
- var url, init, body, e_6;
4813
- return __generator(this, function (_b) {
4814
- switch (_b.label) {
4870
+ var init, res, json, e_5;
4871
+ return __generator(this, function (_a) {
4872
+ switch (_a.label) {
4815
4873
  case 0:
4816
- url = options.url || 'https://score.snapshot.org';
4874
+ if (!options)
4875
+ options = {};
4876
+ if (!options.url)
4877
+ options.url = 'https://score.snapshot.org';
4817
4878
  init = {
4818
4879
  method: 'POST',
4819
4880
  headers: scoreApiHeaders,
4820
- timeout: options.timeout || 30e3,
4821
- body: {
4881
+ body: JSON.stringify({
4822
4882
  jsonrpc: '2.0',
4823
4883
  method: 'validate',
4824
4884
  params: {
@@ -4829,23 +4889,27 @@ function validate(validation, author, space, network, snapshot, params, options)
4829
4889
  snapshot: snapshot,
4830
4890
  params: params
4831
4891
  }
4832
- }
4892
+ })
4833
4893
  };
4834
- _b.label = 1;
4894
+ _a.label = 1;
4835
4895
  case 1:
4836
- _b.trys.push([1, 3, , 4]);
4837
- return [4 /*yield*/, ofetch(url, init)];
4896
+ _a.trys.push([1, 4, , 5]);
4897
+ return [4 /*yield*/, fetch(options.url, init)];
4838
4898
  case 2:
4839
- body = _b.sent();
4840
- return [2 /*return*/, body.result];
4899
+ res = _a.sent();
4900
+ return [4 /*yield*/, res.json()];
4841
4901
  case 3:
4842
- e_6 = _b.sent();
4843
- return [2 /*return*/, Promise.reject(((_a = e_6.data) === null || _a === void 0 ? void 0 : _a.error) || {
4844
- code: e_6.status || 0,
4845
- message: e_6.statusText || e_6.toString(),
4846
- data: e_6.data || ''
4847
- })];
4848
- case 4: return [2 /*return*/];
4902
+ json = _a.sent();
4903
+ if (json.error)
4904
+ return [2 /*return*/, Promise.reject(json.error)];
4905
+ return [2 /*return*/, json.result];
4906
+ case 4:
4907
+ e_5 = _a.sent();
4908
+ if (e_5.errno) {
4909
+ return [2 /*return*/, Promise.reject({ code: e_5.errno, message: e_5.toString(), data: '' })];
4910
+ }
4911
+ return [2 /*return*/, Promise.reject(e_5)];
4912
+ case 5: return [2 /*return*/];
4849
4913
  }
4850
4914
  });
4851
4915
  });
@@ -4881,7 +4945,7 @@ function getSpaceUri(id, network, options) {
4881
4945
  if (network === void 0) { network = '1'; }
4882
4946
  if (options === void 0) { options = {}; }
4883
4947
  return __awaiter(this, void 0, void 0, function () {
4884
- var e_7;
4948
+ var e_6;
4885
4949
  return __generator(this, function (_a) {
4886
4950
  switch (_a.label) {
4887
4951
  case 0:
@@ -4889,8 +4953,8 @@ function getSpaceUri(id, network, options) {
4889
4953
  return [4 /*yield*/, getEnsTextRecord(id, 'snapshot', network, options)];
4890
4954
  case 1: return [2 /*return*/, _a.sent()];
4891
4955
  case 2:
4892
- e_7 = _a.sent();
4893
- console.log(e_7);
4956
+ e_6 = _a.sent();
4957
+ console.log(e_6);
4894
4958
  return [2 /*return*/, null];
4895
4959
  case 3: return [2 /*return*/];
4896
4960
  }