@snapshot-labs/snapshot.js 0.7.2 → 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/index.d.ts +12 -0
- package/dist/schemas/index.d.ts +12 -0
- package/dist/sign/index.d.ts +16 -16
- package/dist/snapshot.cjs.js +185 -131
- package/dist/snapshot.esm.js +185 -130
- package/dist/snapshot.min.js +5 -5
- package/dist/utils.d.ts +13 -6
- package/package.json +3 -3
- package/src/schemas/alias.json +18 -0
- package/src/schemas/index.ts +3 -1
- 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
|
};
|
|
@@ -1288,6 +1294,30 @@ var zodiac = {
|
|
|
1288
1294
|
definitions: definitions$6
|
|
1289
1295
|
};
|
|
1290
1296
|
|
|
1297
|
+
var $schema$7 = "http://json-schema.org/draft-07/schema#";
|
|
1298
|
+
var $ref$7 = "#/definitions/Alias";
|
|
1299
|
+
var definitions$7 = {
|
|
1300
|
+
Alias: {
|
|
1301
|
+
title: "Alias",
|
|
1302
|
+
type: "object",
|
|
1303
|
+
properties: {
|
|
1304
|
+
alias: {
|
|
1305
|
+
type: "string",
|
|
1306
|
+
format: "address"
|
|
1307
|
+
}
|
|
1308
|
+
},
|
|
1309
|
+
required: [
|
|
1310
|
+
"alias"
|
|
1311
|
+
],
|
|
1312
|
+
additionalProperties: false
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1315
|
+
var alias = {
|
|
1316
|
+
$schema: $schema$7,
|
|
1317
|
+
$ref: $ref$7,
|
|
1318
|
+
definitions: definitions$7
|
|
1319
|
+
};
|
|
1320
|
+
|
|
1291
1321
|
var schemas = {
|
|
1292
1322
|
space: space.definitions.Space,
|
|
1293
1323
|
proposal: proposal.definitions.Proposal,
|
|
@@ -1295,7 +1325,8 @@ var schemas = {
|
|
|
1295
1325
|
vote: vote.definitions.Vote,
|
|
1296
1326
|
profile: profile.definitions.Profile,
|
|
1297
1327
|
statement: statement.definitions.Statement,
|
|
1298
|
-
zodiac: zodiac.definitions.Zodiac
|
|
1328
|
+
zodiac: zodiac.definitions.Zodiac,
|
|
1329
|
+
alias: alias.definitions.Alias
|
|
1299
1330
|
};
|
|
1300
1331
|
|
|
1301
1332
|
var Multicaller = /** @class */ (function () {
|
|
@@ -4561,32 +4592,50 @@ function multicall(network, provider, abi, calls, options) {
|
|
|
4561
4592
|
});
|
|
4562
4593
|
}
|
|
4563
4594
|
function subgraphRequest(url, query, options) {
|
|
4564
|
-
|
|
4595
|
+
var _a;
|
|
4565
4596
|
return __awaiter(this, void 0, void 0, function () {
|
|
4566
|
-
var
|
|
4567
|
-
return __generator(this, function (
|
|
4568
|
-
switch (
|
|
4569
|
-
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 = {
|
|
4570
4603
|
method: 'POST',
|
|
4571
4604
|
headers: __assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers),
|
|
4572
|
-
|
|
4573
|
-
|
|
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)];
|
|
4574
4609
|
case 1:
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
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
|
+
})];
|
|
4584
4620
|
}
|
|
4585
|
-
if (
|
|
4586
|
-
|
|
4621
|
+
if (body.errors) {
|
|
4622
|
+
return [2 /*return*/, Promise.reject(body)];
|
|
4587
4623
|
}
|
|
4588
|
-
|
|
4589
|
-
|
|
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*/];
|
|
4590
4639
|
}
|
|
4591
4640
|
});
|
|
4592
4641
|
});
|
|
@@ -4611,20 +4660,39 @@ function getUrl(uri, gateway) {
|
|
|
4611
4660
|
function getJSON(uri, options) {
|
|
4612
4661
|
if (options === void 0) { options = {}; }
|
|
4613
4662
|
return __awaiter(this, void 0, void 0, function () {
|
|
4614
|
-
var url;
|
|
4663
|
+
var url, body;
|
|
4615
4664
|
return __generator(this, function (_a) {
|
|
4616
|
-
|
|
4617
|
-
|
|
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
|
+
}
|
|
4618
4676
|
});
|
|
4619
4677
|
});
|
|
4620
4678
|
}
|
|
4621
|
-
function ipfsGet(gateway, ipfsHash, protocolType) {
|
|
4679
|
+
function ipfsGet(gateway, ipfsHash, protocolType, options) {
|
|
4622
4680
|
if (protocolType === void 0) { protocolType = 'ipfs'; }
|
|
4681
|
+
if (options === void 0) { options = {}; }
|
|
4623
4682
|
return __awaiter(this, void 0, void 0, function () {
|
|
4624
|
-
var url;
|
|
4683
|
+
var url, body;
|
|
4625
4684
|
return __generator(this, function (_a) {
|
|
4626
|
-
|
|
4627
|
-
|
|
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
|
+
}
|
|
4628
4696
|
});
|
|
4629
4697
|
});
|
|
4630
4698
|
}
|
|
@@ -4650,17 +4718,18 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl,
|
|
|
4650
4718
|
if (snapshot === void 0) { snapshot = 'latest'; }
|
|
4651
4719
|
if (scoreApiUrl === void 0) { scoreApiUrl = 'https://score.snapshot.org'; }
|
|
4652
4720
|
if (options === void 0) { options = {}; }
|
|
4721
|
+
var _a;
|
|
4653
4722
|
return __awaiter(this, void 0, void 0, function () {
|
|
4654
|
-
var url, params,
|
|
4655
|
-
return __generator(this, function (
|
|
4656
|
-
switch (
|
|
4723
|
+
var url, params, body, e_4;
|
|
4724
|
+
return __generator(this, function (_b) {
|
|
4725
|
+
switch (_b.label) {
|
|
4657
4726
|
case 0:
|
|
4658
4727
|
url = new URL(scoreApiUrl);
|
|
4659
|
-
url.pathname = '/api/scores';
|
|
4728
|
+
url.pathname = options.pathname || '/api/scores';
|
|
4660
4729
|
scoreApiUrl = url.toString();
|
|
4661
|
-
|
|
4730
|
+
_b.label = 1;
|
|
4662
4731
|
case 1:
|
|
4663
|
-
|
|
4732
|
+
_b.trys.push([1, 3, , 4]);
|
|
4664
4733
|
params = {
|
|
4665
4734
|
space: space,
|
|
4666
4735
|
network: network,
|
|
@@ -4668,47 +4737,43 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl,
|
|
|
4668
4737
|
strategies: strategies,
|
|
4669
4738
|
addresses: addresses
|
|
4670
4739
|
};
|
|
4671
|
-
return [4 /*yield*/,
|
|
4740
|
+
return [4 /*yield*/, ofetch(scoreApiUrl, {
|
|
4672
4741
|
method: 'POST',
|
|
4673
4742
|
headers: scoreApiHeaders,
|
|
4674
|
-
|
|
4743
|
+
timeout: options.timeout || 60e3,
|
|
4744
|
+
body: { params: params }
|
|
4675
4745
|
})];
|
|
4676
4746
|
case 2:
|
|
4677
|
-
|
|
4678
|
-
return [4 /*yield*/, res.json()];
|
|
4679
|
-
case 3:
|
|
4680
|
-
obj = _a.sent();
|
|
4681
|
-
if (obj.error) {
|
|
4682
|
-
return [2 /*return*/, Promise.reject(obj.error)];
|
|
4683
|
-
}
|
|
4747
|
+
body = _b.sent();
|
|
4684
4748
|
return [2 /*return*/, options.returnValue === 'all'
|
|
4685
|
-
?
|
|
4686
|
-
:
|
|
4687
|
-
case
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
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*/];
|
|
4694
4759
|
}
|
|
4695
4760
|
});
|
|
4696
4761
|
});
|
|
4697
4762
|
}
|
|
4698
4763
|
function getVp(address, network, strategies, snapshot, space, delegation, options) {
|
|
4764
|
+
if (options === void 0) { options = {}; }
|
|
4765
|
+
var _a;
|
|
4699
4766
|
return __awaiter(this, void 0, void 0, function () {
|
|
4700
|
-
var
|
|
4701
|
-
return __generator(this, function (
|
|
4702
|
-
switch (
|
|
4767
|
+
var url, init, body, e_5;
|
|
4768
|
+
return __generator(this, function (_b) {
|
|
4769
|
+
switch (_b.label) {
|
|
4703
4770
|
case 0:
|
|
4704
|
-
|
|
4705
|
-
options = {};
|
|
4706
|
-
if (!options.url)
|
|
4707
|
-
options.url = 'https://score.snapshot.org';
|
|
4771
|
+
url = options.url || 'https://score.snapshot.org';
|
|
4708
4772
|
init = {
|
|
4709
4773
|
method: 'POST',
|
|
4710
4774
|
headers: scoreApiHeaders,
|
|
4711
|
-
|
|
4775
|
+
timeout: options.timeout || 60e3,
|
|
4776
|
+
body: {
|
|
4712
4777
|
jsonrpc: '2.0',
|
|
4713
4778
|
method: 'get_vp',
|
|
4714
4779
|
params: {
|
|
@@ -4719,47 +4784,41 @@ function getVp(address, network, strategies, snapshot, space, delegation, option
|
|
|
4719
4784
|
space: space,
|
|
4720
4785
|
delegation: delegation
|
|
4721
4786
|
}
|
|
4722
|
-
}
|
|
4787
|
+
}
|
|
4723
4788
|
};
|
|
4724
|
-
|
|
4789
|
+
_b.label = 1;
|
|
4725
4790
|
case 1:
|
|
4726
|
-
|
|
4727
|
-
return [4 /*yield*/,
|
|
4791
|
+
_b.trys.push([1, 3, , 4]);
|
|
4792
|
+
return [4 /*yield*/, ofetch(url, init)];
|
|
4728
4793
|
case 2:
|
|
4729
|
-
|
|
4730
|
-
return [
|
|
4794
|
+
body = _b.sent();
|
|
4795
|
+
return [2 /*return*/, body.result];
|
|
4731
4796
|
case 3:
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
case 4:
|
|
4739
|
-
e_4 = _a.sent();
|
|
4740
|
-
if (e_4.errno) {
|
|
4741
|
-
return [2 /*return*/, Promise.reject({ code: e_4.errno, message: e_4.toString(), data: '' })];
|
|
4742
|
-
}
|
|
4743
|
-
return [2 /*return*/, Promise.reject(e_4)];
|
|
4744
|
-
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*/];
|
|
4745
4804
|
}
|
|
4746
4805
|
});
|
|
4747
4806
|
});
|
|
4748
4807
|
}
|
|
4749
4808
|
function validate(validation, author, space, network, snapshot, params, options) {
|
|
4809
|
+
if (options === void 0) { options = {}; }
|
|
4810
|
+
var _a;
|
|
4750
4811
|
return __awaiter(this, void 0, void 0, function () {
|
|
4751
|
-
var
|
|
4752
|
-
return __generator(this, function (
|
|
4753
|
-
switch (
|
|
4812
|
+
var url, init, body, e_6;
|
|
4813
|
+
return __generator(this, function (_b) {
|
|
4814
|
+
switch (_b.label) {
|
|
4754
4815
|
case 0:
|
|
4755
|
-
|
|
4756
|
-
options = {};
|
|
4757
|
-
if (!options.url)
|
|
4758
|
-
options.url = 'https://score.snapshot.org';
|
|
4816
|
+
url = options.url || 'https://score.snapshot.org';
|
|
4759
4817
|
init = {
|
|
4760
4818
|
method: 'POST',
|
|
4761
4819
|
headers: scoreApiHeaders,
|
|
4762
|
-
|
|
4820
|
+
timeout: options.timeout || 30e3,
|
|
4821
|
+
body: {
|
|
4763
4822
|
jsonrpc: '2.0',
|
|
4764
4823
|
method: 'validate',
|
|
4765
4824
|
params: {
|
|
@@ -4770,27 +4829,23 @@ function validate(validation, author, space, network, snapshot, params, options)
|
|
|
4770
4829
|
snapshot: snapshot,
|
|
4771
4830
|
params: params
|
|
4772
4831
|
}
|
|
4773
|
-
}
|
|
4832
|
+
}
|
|
4774
4833
|
};
|
|
4775
|
-
|
|
4834
|
+
_b.label = 1;
|
|
4776
4835
|
case 1:
|
|
4777
|
-
|
|
4778
|
-
return [4 /*yield*/,
|
|
4836
|
+
_b.trys.push([1, 3, , 4]);
|
|
4837
|
+
return [4 /*yield*/, ofetch(url, init)];
|
|
4779
4838
|
case 2:
|
|
4780
|
-
|
|
4781
|
-
return [
|
|
4839
|
+
body = _b.sent();
|
|
4840
|
+
return [2 /*return*/, body.result];
|
|
4782
4841
|
case 3:
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
return [2 /*return*/, Promise.reject({ code: e_5.errno, message: e_5.toString(), data: '' })];
|
|
4791
|
-
}
|
|
4792
|
-
return [2 /*return*/, Promise.reject(e_5)];
|
|
4793
|
-
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*/];
|
|
4794
4849
|
}
|
|
4795
4850
|
});
|
|
4796
4851
|
});
|
|
@@ -4826,7 +4881,7 @@ function getSpaceUri(id, network, options) {
|
|
|
4826
4881
|
if (network === void 0) { network = '1'; }
|
|
4827
4882
|
if (options === void 0) { options = {}; }
|
|
4828
4883
|
return __awaiter(this, void 0, void 0, function () {
|
|
4829
|
-
var
|
|
4884
|
+
var e_7;
|
|
4830
4885
|
return __generator(this, function (_a) {
|
|
4831
4886
|
switch (_a.label) {
|
|
4832
4887
|
case 0:
|
|
@@ -4834,8 +4889,8 @@ function getSpaceUri(id, network, options) {
|
|
|
4834
4889
|
return [4 /*yield*/, getEnsTextRecord(id, 'snapshot', network, options)];
|
|
4835
4890
|
case 1: return [2 /*return*/, _a.sent()];
|
|
4836
4891
|
case 2:
|
|
4837
|
-
|
|
4838
|
-
console.log(
|
|
4892
|
+
e_7 = _a.sent();
|
|
4893
|
+
console.log(e_7);
|
|
4839
4894
|
return [2 /*return*/, null];
|
|
4840
4895
|
case 3: return [2 /*return*/];
|
|
4841
4896
|
}
|