@snapshot-labs/snapshot.js 0.8.0-beta.0 → 0.8.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
@@ -9,20 +9,20 @@ export default class Client {
9
9
  readonly address: string;
10
10
  readonly options: any;
11
11
  constructor(address?: string, options?: {});
12
- sign(web3: Web3Provider | Wallet, address: string, message: any, types: any): Promise<any>;
13
- send(envelop: any): Promise<any>;
14
- space(web3: Web3Provider | Wallet, address: string, message: Space): Promise<any>;
15
- proposal(web3: Web3Provider | Wallet, address: string, message: Proposal): Promise<any>;
16
- updateProposal(web3: Web3Provider | Wallet, address: string, message: UpdateProposal): Promise<any>;
17
- flagProposal(web3: Web3Provider | Wallet, address: string, message: FlagProposal): Promise<any>;
18
- cancelProposal(web3: Web3Provider | Wallet, address: string, message: CancelProposal): Promise<any>;
19
- vote(web3: Web3Provider | Wallet, address: string, message: Vote): Promise<any>;
20
- follow(web3: Web3Provider | Wallet, address: string, message: Follow): Promise<any>;
21
- unfollow(web3: Web3Provider | Wallet, address: string, message: Unfollow): Promise<any>;
22
- subscribe(web3: Web3Provider | Wallet, address: string, message: Subscribe): Promise<any>;
23
- unsubscribe(web3: Web3Provider | Wallet, address: string, message: Unsubscribe): Promise<any>;
24
- profile(web3: Web3Provider | Wallet, address: string, message: Profile): Promise<any>;
25
- statement(web3: Web3Provider | Wallet, address: string, message: Statement): Promise<any>;
26
- alias(web3: Web3Provider | Wallet, address: string, message: Alias): Promise<any>;
27
- deleteSpace(web3: Web3Provider | Wallet, address: string, message: DeleteSpace): Promise<any>;
12
+ sign(web3: Web3Provider | Wallet, address: string, message: any, types: any): Promise<unknown>;
13
+ send(envelop: any): Promise<unknown>;
14
+ space(web3: Web3Provider | Wallet, address: string, message: Space): Promise<unknown>;
15
+ proposal(web3: Web3Provider | Wallet, address: string, message: Proposal): Promise<unknown>;
16
+ updateProposal(web3: Web3Provider | Wallet, address: string, message: UpdateProposal): Promise<unknown>;
17
+ flagProposal(web3: Web3Provider | Wallet, address: string, message: FlagProposal): Promise<unknown>;
18
+ cancelProposal(web3: Web3Provider | Wallet, address: string, message: CancelProposal): Promise<unknown>;
19
+ vote(web3: Web3Provider | Wallet, address: string, message: Vote): Promise<unknown>;
20
+ follow(web3: Web3Provider | Wallet, address: string, message: Follow): Promise<unknown>;
21
+ unfollow(web3: Web3Provider | Wallet, address: string, message: Unfollow): Promise<unknown>;
22
+ subscribe(web3: Web3Provider | Wallet, address: string, message: Subscribe): Promise<unknown>;
23
+ unsubscribe(web3: Web3Provider | Wallet, address: string, message: Unsubscribe): Promise<unknown>;
24
+ profile(web3: Web3Provider | Wallet, address: string, message: Profile): Promise<unknown>;
25
+ statement(web3: Web3Provider | Wallet, address: string, message: Statement): Promise<unknown>;
26
+ alias(web3: Web3Provider | Wallet, address: string, message: Alias): Promise<unknown>;
27
+ deleteSpace(web3: Web3Provider | Wallet, address: string, message: DeleteSpace): Promise<unknown>;
28
28
  }
@@ -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
  };
@@ -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",
@@ -2775,7 +2800,7 @@ var networks = {
2775
2800
  "wss://archive-en.baobab.klaytn.net/ws"
2776
2801
  ],
2777
2802
  explorer: {
2778
- url: "https://baobab.scope.klaytn.com/"
2803
+ url: "https://baobab.scope.klaytn.com"
2779
2804
  },
2780
2805
  logo: "ipfs://QmYACyZcidcFtMo4Uf9H6ZKUxTP2TQPjGzNjcUjqYa64dt"
2781
2806
  },
@@ -2826,6 +2851,21 @@ var networks = {
2826
2851
  },
2827
2852
  start: 451,
2828
2853
  logo: "ipfs://QmYeskHqrEvWHqeAuqett64LxfH52HUXZi2T9BAMmgKvBF"
2854
+ },
2855
+ "1101": {
2856
+ key: "1101",
2857
+ name: "Polygon zkEVM",
2858
+ shortName: "mainnet",
2859
+ chainId: 1101,
2860
+ network: "mainnet",
2861
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
2862
+ rpc: [
2863
+ ],
2864
+ explorer: {
2865
+ url: "https://zkevm.polygonscan.com"
2866
+ },
2867
+ start: 57746,
2868
+ logo: "ipfs://bafkreibfiyvhqnme2vbxxfcku7qkxgjpkg6ywdkplxh4oxlkqsbznyorfm"
2829
2869
  },
2830
2870
  "1116": {
2831
2871
  key: "1116",
@@ -3117,6 +3157,21 @@ var networks = {
3117
3157
  },
3118
3158
  start: 2607889,
3119
3159
  logo: "ipfs://QmPXPCBho3kGLt5rhG9JGkKmzdtLvqZmJqGzzijVCuggWY"
3160
+ },
3161
+ "4337": {
3162
+ key: "4337",
3163
+ name: "Beam",
3164
+ shortName: "Beam",
3165
+ chainId: 4337,
3166
+ network: "mainnet",
3167
+ multicall: "0x4956F15eFdc3dC16645e90Cc356eAFA65fFC65Ec",
3168
+ rpc: [
3169
+ ],
3170
+ explorer: {
3171
+ url: "https://subnets.avax.network/beam/"
3172
+ },
3173
+ start: 1,
3174
+ logo: "ipfs://QmaKRLxXPdeTsLx7MFLS3CJbhpSbResgoeL4fCgHB1mTsF"
3120
3175
  },
3121
3176
  "4689": {
3122
3177
  key: "4689",
@@ -3311,7 +3366,7 @@ var networks = {
3311
3366
  "wss://archive-en.cypress.klaytn.net/ws"
3312
3367
  ],
3313
3368
  explorer: {
3314
- url: "https://scope.klaytn.com/"
3369
+ url: "https://scope.klaytn.com"
3315
3370
  },
3316
3371
  logo: "ipfs://QmYACyZcidcFtMo4Uf9H6ZKUxTP2TQPjGzNjcUjqYa64dt"
3317
3372
  },
@@ -3468,6 +3523,22 @@ var networks = {
3468
3523
  },
3469
3524
  start: 79516,
3470
3525
  logo: "ipfs://QmTogMDLmDgJjDjUKDHDuc2KVTVDbXf8bXJLFiVe8PRxgo"
3526
+ },
3527
+ "13337": {
3528
+ key: "13337",
3529
+ name: "Beam Testnet",
3530
+ shortName: "testnet",
3531
+ chainId: 13337,
3532
+ network: "testnet",
3533
+ multicall: "0x9BF49b704EE2A095b95c1f2D4EB9010510c41C9E",
3534
+ rpc: [
3535
+ ],
3536
+ explorer: {
3537
+ url: "https://subnets-test.avax.network/beam/"
3538
+ },
3539
+ start: 3,
3540
+ logo: "ipfs://QmaKRLxXPdeTsLx7MFLS3CJbhpSbResgoeL4fCgHB1mTsF",
3541
+ testnet: true
3471
3542
  },
3472
3543
  "16718": {
3473
3544
  key: "16718",
@@ -3805,7 +3876,7 @@ var networks = {
3805
3876
  },
3806
3877
  "80001": {
3807
3878
  key: "80001",
3808
- name: "Matic Mumbai",
3879
+ name: "Polygon Mumbai",
3809
3880
  chainId: 80001,
3810
3881
  network: "testnet",
3811
3882
  testnet: true,
@@ -3822,7 +3893,7 @@ var networks = {
3822
3893
  apiUrl: "https://api-mumbai.polygonscan.com"
3823
3894
  },
3824
3895
  start: 12011090,
3825
- logo: "ipfs://QmaGokGqgjknfa4xnXKnnwC5ZyXzUjQ7p6KEe4D8G5uFFE"
3896
+ logo: "ipfs://bafkreihgr7zy7vi5kqddybfaezwuhvssg57qluwmyan4qq7l57nr7w7wey"
3826
3897
  },
3827
3898
  "84531": {
3828
3899
  key: "84531",
@@ -4600,50 +4671,32 @@ function multicall(network, provider, abi$1, calls, options) {
4600
4671
  });
4601
4672
  }
4602
4673
  function subgraphRequest(url, query, options) {
4603
- var _a;
4674
+ if (options === void 0) { options = {}; }
4604
4675
  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 = {
4676
+ var res, responseData, data;
4677
+ return __generator(this, function (_a) {
4678
+ switch (_a.label) {
4679
+ case 0: return [4 /*yield*/, fetch__default['default'](url, {
4611
4680
  method: 'POST',
4612
4681
  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)];
4682
+ body: JSON.stringify({ query: jsonToGraphqlQuery.jsonToGraphQLQuery({ query: query }) })
4683
+ })];
4617
4684
  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
- })];
4685
+ res = _a.sent();
4686
+ return [4 /*yield*/, res.text()];
4687
+ case 2:
4688
+ responseData = _a.sent();
4689
+ try {
4690
+ responseData = JSON.parse(responseData);
4691
+ }
4692
+ catch (e) {
4693
+ throw new Error("Errors found in subgraphRequest: URL: " + url + ", Status: " + res.status + ", Response: " + responseData.substring(0, 400));
4628
4694
  }
4629
- if (body.errors) {
4630
- return [2 /*return*/, Promise.reject(body)];
4695
+ if (responseData.errors) {
4696
+ throw new Error("Errors found in subgraphRequest: URL: " + url + ", Status: " + res.status + ", Response: " + JSON.stringify(responseData.errors).substring(0, 400));
4631
4697
  }
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*/];
4698
+ data = responseData.data;
4699
+ return [2 /*return*/, data || {}];
4647
4700
  }
4648
4701
  });
4649
4702
  });
@@ -4668,39 +4721,20 @@ function getUrl(uri, gateway) {
4668
4721
  function getJSON(uri, options) {
4669
4722
  if (options === void 0) { options = {}; }
4670
4723
  return __awaiter(this, void 0, void 0, function () {
4671
- var url, body;
4724
+ var url;
4672
4725
  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
- }
4726
+ url = getUrl(uri, options.gateways);
4727
+ return [2 /*return*/, fetch__default['default'](url).then(function (res) { return res.json(); })];
4684
4728
  });
4685
4729
  });
4686
4730
  }
4687
- function ipfsGet(gateway, ipfsHash, protocolType, options) {
4731
+ function ipfsGet(gateway, ipfsHash, protocolType) {
4688
4732
  if (protocolType === void 0) { protocolType = 'ipfs'; }
4689
- if (options === void 0) { options = {}; }
4690
4733
  return __awaiter(this, void 0, void 0, function () {
4691
- var url, body;
4734
+ var url;
4692
4735
  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
- }
4736
+ url = "https://" + gateway + "/" + protocolType + "/" + ipfsHash;
4737
+ return [2 /*return*/, fetch__default['default'](url).then(function (res) { return res.json(); })];
4704
4738
  });
4705
4739
  });
4706
4740
  }
@@ -4726,18 +4760,17 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl,
4726
4760
  if (snapshot === void 0) { snapshot = 'latest'; }
4727
4761
  if (scoreApiUrl === void 0) { scoreApiUrl = 'https://score.snapshot.org'; }
4728
4762
  if (options === void 0) { options = {}; }
4729
- var _a;
4730
4763
  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) {
4764
+ var url, params, res, obj, e_3;
4765
+ return __generator(this, function (_a) {
4766
+ switch (_a.label) {
4734
4767
  case 0:
4735
4768
  url = new URL(scoreApiUrl);
4736
- url.pathname = options.pathname || '/api/scores';
4769
+ url.pathname = '/api/scores';
4737
4770
  scoreApiUrl = url.toString();
4738
- _b.label = 1;
4771
+ _a.label = 1;
4739
4772
  case 1:
4740
- _b.trys.push([1, 3, , 4]);
4773
+ _a.trys.push([1, 4, , 5]);
4741
4774
  params = {
4742
4775
  space: space,
4743
4776
  network: network,
@@ -4745,43 +4778,47 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl,
4745
4778
  strategies: strategies,
4746
4779
  addresses: addresses
4747
4780
  };
4748
- return [4 /*yield*/, ofetch.ofetch(scoreApiUrl, {
4781
+ return [4 /*yield*/, fetch__default['default'](scoreApiUrl, {
4749
4782
  method: 'POST',
4750
4783
  headers: scoreApiHeaders,
4751
- timeout: options.timeout || 60e3,
4752
- body: { params: params }
4784
+ body: JSON.stringify({ params: params })
4753
4785
  })];
4754
4786
  case 2:
4755
- body = _b.sent();
4756
- return [2 /*return*/, options.returnValue === 'all'
4757
- ? body.result
4758
- : body.result[options.returnValue || 'scores']];
4787
+ res = _a.sent();
4788
+ return [4 /*yield*/, res.json()];
4759
4789
  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*/];
4790
+ obj = _a.sent();
4791
+ if (obj.error) {
4792
+ return [2 /*return*/, Promise.reject(obj.error)];
4793
+ }
4794
+ return [2 /*return*/, options.returnValue === 'all'
4795
+ ? obj.result
4796
+ : obj.result[options.returnValue || 'scores']];
4797
+ case 4:
4798
+ e_3 = _a.sent();
4799
+ if (e_3.errno) {
4800
+ return [2 /*return*/, Promise.reject({ code: e_3.errno, message: e_3.toString(), data: '' })];
4801
+ }
4802
+ return [2 /*return*/, Promise.reject(e_3)];
4803
+ case 5: return [2 /*return*/];
4767
4804
  }
4768
4805
  });
4769
4806
  });
4770
4807
  }
4771
4808
  function getVp(address, network, strategies, snapshot, space, delegation, options) {
4772
- if (options === void 0) { options = {}; }
4773
- var _a;
4774
4809
  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) {
4810
+ var init, res, json, e_4;
4811
+ return __generator(this, function (_a) {
4812
+ switch (_a.label) {
4778
4813
  case 0:
4779
- url = options.url || 'https://score.snapshot.org';
4814
+ if (!options)
4815
+ options = {};
4816
+ if (!options.url)
4817
+ options.url = 'https://score.snapshot.org';
4780
4818
  init = {
4781
4819
  method: 'POST',
4782
4820
  headers: scoreApiHeaders,
4783
- timeout: options.timeout || 60e3,
4784
- body: {
4821
+ body: JSON.stringify({
4785
4822
  jsonrpc: '2.0',
4786
4823
  method: 'get_vp',
4787
4824
  params: {
@@ -4792,41 +4829,47 @@ function getVp(address, network, strategies, snapshot, space, delegation, option
4792
4829
  space: space,
4793
4830
  delegation: delegation
4794
4831
  }
4795
- }
4832
+ })
4796
4833
  };
4797
- _b.label = 1;
4834
+ _a.label = 1;
4798
4835
  case 1:
4799
- _b.trys.push([1, 3, , 4]);
4800
- return [4 /*yield*/, ofetch.ofetch(url, init)];
4836
+ _a.trys.push([1, 4, , 5]);
4837
+ return [4 /*yield*/, fetch__default['default'](options.url, init)];
4801
4838
  case 2:
4802
- body = _b.sent();
4803
- return [2 /*return*/, body.result];
4839
+ res = _a.sent();
4840
+ return [4 /*yield*/, res.json()];
4804
4841
  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*/];
4842
+ json = _a.sent();
4843
+ if (json.error)
4844
+ return [2 /*return*/, Promise.reject(json.error)];
4845
+ if (json.result)
4846
+ return [2 /*return*/, json.result];
4847
+ return [3 /*break*/, 5];
4848
+ case 4:
4849
+ e_4 = _a.sent();
4850
+ if (e_4.errno) {
4851
+ return [2 /*return*/, Promise.reject({ code: e_4.errno, message: e_4.toString(), data: '' })];
4852
+ }
4853
+ return [2 /*return*/, Promise.reject(e_4)];
4854
+ case 5: return [2 /*return*/];
4812
4855
  }
4813
4856
  });
4814
4857
  });
4815
4858
  }
4816
4859
  function validate(validation, author, space, network, snapshot, params, options) {
4817
- if (options === void 0) { options = {}; }
4818
- var _a;
4819
4860
  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) {
4861
+ var init, res, json, e_5;
4862
+ return __generator(this, function (_a) {
4863
+ switch (_a.label) {
4823
4864
  case 0:
4824
- url = options.url || 'https://score.snapshot.org';
4865
+ if (!options)
4866
+ options = {};
4867
+ if (!options.url)
4868
+ options.url = 'https://score.snapshot.org';
4825
4869
  init = {
4826
4870
  method: 'POST',
4827
4871
  headers: scoreApiHeaders,
4828
- timeout: options.timeout || 30e3,
4829
- body: {
4872
+ body: JSON.stringify({
4830
4873
  jsonrpc: '2.0',
4831
4874
  method: 'validate',
4832
4875
  params: {
@@ -4837,23 +4880,27 @@ function validate(validation, author, space, network, snapshot, params, options)
4837
4880
  snapshot: snapshot,
4838
4881
  params: params
4839
4882
  }
4840
- }
4883
+ })
4841
4884
  };
4842
- _b.label = 1;
4885
+ _a.label = 1;
4843
4886
  case 1:
4844
- _b.trys.push([1, 3, , 4]);
4845
- return [4 /*yield*/, ofetch.ofetch(url, init)];
4887
+ _a.trys.push([1, 4, , 5]);
4888
+ return [4 /*yield*/, fetch__default['default'](options.url, init)];
4846
4889
  case 2:
4847
- body = _b.sent();
4848
- return [2 /*return*/, body.result];
4890
+ res = _a.sent();
4891
+ return [4 /*yield*/, res.json()];
4849
4892
  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*/];
4893
+ json = _a.sent();
4894
+ if (json.error)
4895
+ return [2 /*return*/, Promise.reject(json.error)];
4896
+ return [2 /*return*/, json.result];
4897
+ case 4:
4898
+ e_5 = _a.sent();
4899
+ if (e_5.errno) {
4900
+ return [2 /*return*/, Promise.reject({ code: e_5.errno, message: e_5.toString(), data: '' })];
4901
+ }
4902
+ return [2 /*return*/, Promise.reject(e_5)];
4903
+ case 5: return [2 /*return*/];
4857
4904
  }
4858
4905
  });
4859
4906
  });
@@ -4889,7 +4936,7 @@ function getSpaceUri(id, network, options) {
4889
4936
  if (network === void 0) { network = '1'; }
4890
4937
  if (options === void 0) { options = {}; }
4891
4938
  return __awaiter(this, void 0, void 0, function () {
4892
- var e_7;
4939
+ var e_6;
4893
4940
  return __generator(this, function (_a) {
4894
4941
  switch (_a.label) {
4895
4942
  case 0:
@@ -4897,8 +4944,8 @@ function getSpaceUri(id, network, options) {
4897
4944
  return [4 /*yield*/, getEnsTextRecord(id, 'snapshot', network, options)];
4898
4945
  case 1: return [2 /*return*/, _a.sent()];
4899
4946
  case 2:
4900
- e_7 = _a.sent();
4901
- console.log(e_7);
4947
+ e_6 = _a.sent();
4948
+ console.log(e_6);
4902
4949
  return [2 /*return*/, null];
4903
4950
  case 3: return [2 /*return*/];
4904
4951
  }