@snapshot-labs/snapshot.js 0.7.3 → 0.8.0-beta.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 +0 -0
- package/dist/sign/index.d.ts +16 -16
- package/dist/snapshot.cjs.js +159 -130
- package/dist/snapshot.esm.js +159 -129
- package/dist/snapshot.min.js +5 -5
- package/dist/utils.d.ts +13 -6
- package/package.json +3 -3
- package/src/sign/index.ts +12 -10
- package/src/utils/dist/provider.js +47 -0
- package/src/utils.ts +117 -73
package/dist/snapshot.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ofetch } from 'ofetch';
|
|
2
2
|
import { getAddress, isAddress } from '@ethersproject/address';
|
|
3
3
|
import { Interface } from '@ethersproject/abi';
|
|
4
4
|
import { Contract } from '@ethersproject/contracts';
|
|
@@ -362,29 +362,35 @@ var Client = /** @class */ (function () {
|
|
|
362
362
|
});
|
|
363
363
|
};
|
|
364
364
|
Client.prototype.send = function (envelop) {
|
|
365
|
+
var _a, _b;
|
|
365
366
|
return __awaiter(this, void 0, void 0, function () {
|
|
366
|
-
var address, init;
|
|
367
|
-
return __generator(this, function (
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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
|
+
}
|
|
388
394
|
});
|
|
389
395
|
});
|
|
390
396
|
};
|
|
@@ -4586,32 +4592,50 @@ function multicall(network, provider, abi, calls, options) {
|
|
|
4586
4592
|
});
|
|
4587
4593
|
}
|
|
4588
4594
|
function subgraphRequest(url, query, options) {
|
|
4589
|
-
|
|
4595
|
+
var _a;
|
|
4590
4596
|
return __awaiter(this, void 0, void 0, function () {
|
|
4591
|
-
var
|
|
4592
|
-
return __generator(this, function (
|
|
4593
|
-
switch (
|
|
4594
|
-
case 0:
|
|
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 = {
|
|
4595
4603
|
method: 'POST',
|
|
4596
4604
|
headers: __assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers),
|
|
4597
|
-
|
|
4598
|
-
|
|
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)];
|
|
4599
4609
|
case 1:
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
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
|
+
})];
|
|
4606
4620
|
}
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
}
|
|
4610
|
-
if (responseData.errors) {
|
|
4611
|
-
throw new Error("Errors found in subgraphRequest: URL: " + url + ", Status: " + res.status + ", Response: " + JSON.stringify(responseData.errors).substring(0, 400));
|
|
4621
|
+
if (body.errors) {
|
|
4622
|
+
return [2 /*return*/, Promise.reject(body)];
|
|
4612
4623
|
}
|
|
4613
|
-
|
|
4614
|
-
|
|
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*/];
|
|
4615
4639
|
}
|
|
4616
4640
|
});
|
|
4617
4641
|
});
|
|
@@ -4636,20 +4660,39 @@ function getUrl(uri, gateway) {
|
|
|
4636
4660
|
function getJSON(uri, options) {
|
|
4637
4661
|
if (options === void 0) { options = {}; }
|
|
4638
4662
|
return __awaiter(this, void 0, void 0, function () {
|
|
4639
|
-
var url;
|
|
4663
|
+
var url, body;
|
|
4640
4664
|
return __generator(this, function (_a) {
|
|
4641
|
-
|
|
4642
|
-
|
|
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
|
+
}
|
|
4643
4676
|
});
|
|
4644
4677
|
});
|
|
4645
4678
|
}
|
|
4646
|
-
function ipfsGet(gateway, ipfsHash, protocolType) {
|
|
4679
|
+
function ipfsGet(gateway, ipfsHash, protocolType, options) {
|
|
4647
4680
|
if (protocolType === void 0) { protocolType = 'ipfs'; }
|
|
4681
|
+
if (options === void 0) { options = {}; }
|
|
4648
4682
|
return __awaiter(this, void 0, void 0, function () {
|
|
4649
|
-
var url;
|
|
4683
|
+
var url, body;
|
|
4650
4684
|
return __generator(this, function (_a) {
|
|
4651
|
-
|
|
4652
|
-
|
|
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
|
+
}
|
|
4653
4696
|
});
|
|
4654
4697
|
});
|
|
4655
4698
|
}
|
|
@@ -4675,17 +4718,18 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl,
|
|
|
4675
4718
|
if (snapshot === void 0) { snapshot = 'latest'; }
|
|
4676
4719
|
if (scoreApiUrl === void 0) { scoreApiUrl = 'https://score.snapshot.org'; }
|
|
4677
4720
|
if (options === void 0) { options = {}; }
|
|
4721
|
+
var _a;
|
|
4678
4722
|
return __awaiter(this, void 0, void 0, function () {
|
|
4679
|
-
var url, params,
|
|
4680
|
-
return __generator(this, function (
|
|
4681
|
-
switch (
|
|
4723
|
+
var url, params, body, e_4;
|
|
4724
|
+
return __generator(this, function (_b) {
|
|
4725
|
+
switch (_b.label) {
|
|
4682
4726
|
case 0:
|
|
4683
4727
|
url = new URL(scoreApiUrl);
|
|
4684
|
-
url.pathname = '/api/scores';
|
|
4728
|
+
url.pathname = options.pathname || '/api/scores';
|
|
4685
4729
|
scoreApiUrl = url.toString();
|
|
4686
|
-
|
|
4730
|
+
_b.label = 1;
|
|
4687
4731
|
case 1:
|
|
4688
|
-
|
|
4732
|
+
_b.trys.push([1, 3, , 4]);
|
|
4689
4733
|
params = {
|
|
4690
4734
|
space: space,
|
|
4691
4735
|
network: network,
|
|
@@ -4693,47 +4737,43 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl,
|
|
|
4693
4737
|
strategies: strategies,
|
|
4694
4738
|
addresses: addresses
|
|
4695
4739
|
};
|
|
4696
|
-
return [4 /*yield*/,
|
|
4740
|
+
return [4 /*yield*/, ofetch(scoreApiUrl, {
|
|
4697
4741
|
method: 'POST',
|
|
4698
4742
|
headers: scoreApiHeaders,
|
|
4699
|
-
|
|
4743
|
+
timeout: options.timeout || 60e3,
|
|
4744
|
+
body: { params: params }
|
|
4700
4745
|
})];
|
|
4701
4746
|
case 2:
|
|
4702
|
-
|
|
4703
|
-
return [4 /*yield*/, res.json()];
|
|
4704
|
-
case 3:
|
|
4705
|
-
obj = _a.sent();
|
|
4706
|
-
if (obj.error) {
|
|
4707
|
-
return [2 /*return*/, Promise.reject(obj.error)];
|
|
4708
|
-
}
|
|
4747
|
+
body = _b.sent();
|
|
4709
4748
|
return [2 /*return*/, options.returnValue === 'all'
|
|
4710
|
-
?
|
|
4711
|
-
:
|
|
4712
|
-
case
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4749
|
+
? body.result
|
|
4750
|
+
: body.result[options.returnValue || 'scores']];
|
|
4751
|
+
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*/];
|
|
4719
4759
|
}
|
|
4720
4760
|
});
|
|
4721
4761
|
});
|
|
4722
4762
|
}
|
|
4723
4763
|
function getVp(address, network, strategies, snapshot, space, delegation, options) {
|
|
4764
|
+
if (options === void 0) { options = {}; }
|
|
4765
|
+
var _a;
|
|
4724
4766
|
return __awaiter(this, void 0, void 0, function () {
|
|
4725
|
-
var
|
|
4726
|
-
return __generator(this, function (
|
|
4727
|
-
switch (
|
|
4767
|
+
var url, init, body, e_5;
|
|
4768
|
+
return __generator(this, function (_b) {
|
|
4769
|
+
switch (_b.label) {
|
|
4728
4770
|
case 0:
|
|
4729
|
-
|
|
4730
|
-
options = {};
|
|
4731
|
-
if (!options.url)
|
|
4732
|
-
options.url = 'https://score.snapshot.org';
|
|
4771
|
+
url = options.url || 'https://score.snapshot.org';
|
|
4733
4772
|
init = {
|
|
4734
4773
|
method: 'POST',
|
|
4735
4774
|
headers: scoreApiHeaders,
|
|
4736
|
-
|
|
4775
|
+
timeout: options.timeout || 60e3,
|
|
4776
|
+
body: {
|
|
4737
4777
|
jsonrpc: '2.0',
|
|
4738
4778
|
method: 'get_vp',
|
|
4739
4779
|
params: {
|
|
@@ -4744,47 +4784,41 @@ function getVp(address, network, strategies, snapshot, space, delegation, option
|
|
|
4744
4784
|
space: space,
|
|
4745
4785
|
delegation: delegation
|
|
4746
4786
|
}
|
|
4747
|
-
}
|
|
4787
|
+
}
|
|
4748
4788
|
};
|
|
4749
|
-
|
|
4789
|
+
_b.label = 1;
|
|
4750
4790
|
case 1:
|
|
4751
|
-
|
|
4752
|
-
return [4 /*yield*/,
|
|
4791
|
+
_b.trys.push([1, 3, , 4]);
|
|
4792
|
+
return [4 /*yield*/, ofetch(url, init)];
|
|
4753
4793
|
case 2:
|
|
4754
|
-
|
|
4755
|
-
return [
|
|
4794
|
+
body = _b.sent();
|
|
4795
|
+
return [2 /*return*/, body.result];
|
|
4756
4796
|
case 3:
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
case 4:
|
|
4764
|
-
e_4 = _a.sent();
|
|
4765
|
-
if (e_4.errno) {
|
|
4766
|
-
return [2 /*return*/, Promise.reject({ code: e_4.errno, message: e_4.toString(), data: '' })];
|
|
4767
|
-
}
|
|
4768
|
-
return [2 /*return*/, Promise.reject(e_4)];
|
|
4769
|
-
case 5: return [2 /*return*/];
|
|
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*/];
|
|
4770
4804
|
}
|
|
4771
4805
|
});
|
|
4772
4806
|
});
|
|
4773
4807
|
}
|
|
4774
4808
|
function validate(validation, author, space, network, snapshot, params, options) {
|
|
4809
|
+
if (options === void 0) { options = {}; }
|
|
4810
|
+
var _a;
|
|
4775
4811
|
return __awaiter(this, void 0, void 0, function () {
|
|
4776
|
-
var
|
|
4777
|
-
return __generator(this, function (
|
|
4778
|
-
switch (
|
|
4812
|
+
var url, init, body, e_6;
|
|
4813
|
+
return __generator(this, function (_b) {
|
|
4814
|
+
switch (_b.label) {
|
|
4779
4815
|
case 0:
|
|
4780
|
-
|
|
4781
|
-
options = {};
|
|
4782
|
-
if (!options.url)
|
|
4783
|
-
options.url = 'https://score.snapshot.org';
|
|
4816
|
+
url = options.url || 'https://score.snapshot.org';
|
|
4784
4817
|
init = {
|
|
4785
4818
|
method: 'POST',
|
|
4786
4819
|
headers: scoreApiHeaders,
|
|
4787
|
-
|
|
4820
|
+
timeout: options.timeout || 30e3,
|
|
4821
|
+
body: {
|
|
4788
4822
|
jsonrpc: '2.0',
|
|
4789
4823
|
method: 'validate',
|
|
4790
4824
|
params: {
|
|
@@ -4795,27 +4829,23 @@ function validate(validation, author, space, network, snapshot, params, options)
|
|
|
4795
4829
|
snapshot: snapshot,
|
|
4796
4830
|
params: params
|
|
4797
4831
|
}
|
|
4798
|
-
}
|
|
4832
|
+
}
|
|
4799
4833
|
};
|
|
4800
|
-
|
|
4834
|
+
_b.label = 1;
|
|
4801
4835
|
case 1:
|
|
4802
|
-
|
|
4803
|
-
return [4 /*yield*/,
|
|
4836
|
+
_b.trys.push([1, 3, , 4]);
|
|
4837
|
+
return [4 /*yield*/, ofetch(url, init)];
|
|
4804
4838
|
case 2:
|
|
4805
|
-
|
|
4806
|
-
return [
|
|
4839
|
+
body = _b.sent();
|
|
4840
|
+
return [2 /*return*/, body.result];
|
|
4807
4841
|
case 3:
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
return [2 /*return*/, Promise.reject({ code: e_5.errno, message: e_5.toString(), data: '' })];
|
|
4816
|
-
}
|
|
4817
|
-
return [2 /*return*/, Promise.reject(e_5)];
|
|
4818
|
-
case 5: return [2 /*return*/];
|
|
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*/];
|
|
4819
4849
|
}
|
|
4820
4850
|
});
|
|
4821
4851
|
});
|
|
@@ -4851,7 +4881,7 @@ function getSpaceUri(id, network, options) {
|
|
|
4851
4881
|
if (network === void 0) { network = '1'; }
|
|
4852
4882
|
if (options === void 0) { options = {}; }
|
|
4853
4883
|
return __awaiter(this, void 0, void 0, function () {
|
|
4854
|
-
var
|
|
4884
|
+
var e_7;
|
|
4855
4885
|
return __generator(this, function (_a) {
|
|
4856
4886
|
switch (_a.label) {
|
|
4857
4887
|
case 0:
|
|
@@ -4859,8 +4889,8 @@ function getSpaceUri(id, network, options) {
|
|
|
4859
4889
|
return [4 /*yield*/, getEnsTextRecord(id, 'snapshot', network, options)];
|
|
4860
4890
|
case 1: return [2 /*return*/, _a.sent()];
|
|
4861
4891
|
case 2:
|
|
4862
|
-
|
|
4863
|
-
console.log(
|
|
4892
|
+
e_7 = _a.sent();
|
|
4893
|
+
console.log(e_7);
|
|
4864
4894
|
return [2 /*return*/, null];
|
|
4865
4895
|
case 3: return [2 /*return*/];
|
|
4866
4896
|
}
|