@snapshot-labs/snapshot.js 0.4.95 → 0.4.97
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/README.md +29 -3
- package/dist/index.d.ts +28 -1
- package/dist/schemas/index.d.ts +28 -1
- package/dist/snapshot.cjs.js +66 -2
- package/dist/snapshot.esm.js +66 -2
- package/dist/snapshot.min.js +8 -7
- package/package.json +2 -1
- package/src/schemas/space.json +30 -2
- package/src/utils.ts +28 -0
package/README.md
CHANGED
|
@@ -2,31 +2,57 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@snapshot-labs/snapshot.js)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Install
|
|
6
|
+
|
|
6
7
|
Snapshot.js was designed to work both in the browser and in Node.js.
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
### In Node Applications
|
|
10
|
+
|
|
9
11
|
To install Snapshot.js on Node.js, open your terminal and run:
|
|
10
|
-
|
|
12
|
+
|
|
13
|
+
```bash
|
|
11
14
|
npm i @snapshot-labs/snapshot.js
|
|
12
15
|
```
|
|
13
16
|
|
|
14
17
|
#### Browser
|
|
18
|
+
|
|
15
19
|
You can create an index.html file and include Snapshot.js with:
|
|
20
|
+
|
|
16
21
|
```html
|
|
17
22
|
<script src="https://cdn.jsdelivr.net/npm/@snapshot-labs/snapshot.js"></script>
|
|
18
23
|
```
|
|
24
|
+
|
|
19
25
|
### Development
|
|
20
26
|
|
|
21
27
|
#### Install dependencies
|
|
28
|
+
|
|
22
29
|
```bash
|
|
23
30
|
yarn
|
|
24
31
|
```
|
|
25
32
|
|
|
26
33
|
#### Build package
|
|
34
|
+
|
|
27
35
|
```bash
|
|
28
36
|
yarn build
|
|
29
37
|
```
|
|
30
38
|
|
|
39
|
+
#### Test cases
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
yarn test
|
|
43
|
+
# or
|
|
44
|
+
yarn test:once
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
#### Other useful scripts
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Format ABI
|
|
51
|
+
ts-node scripts/abi.ts
|
|
52
|
+
# Generate hash for types
|
|
53
|
+
ts-node scripts/generateHashWithTypes.ts
|
|
54
|
+
```
|
|
55
|
+
|
|
31
56
|
### License
|
|
57
|
+
|
|
32
58
|
[MIT](LICENSE).
|
package/dist/index.d.ts
CHANGED
|
@@ -235,8 +235,35 @@ declare const _default: {
|
|
|
235
235
|
required: string[];
|
|
236
236
|
additionalProperties: boolean;
|
|
237
237
|
};
|
|
238
|
-
|
|
238
|
+
delegationPortal: {
|
|
239
239
|
type: string;
|
|
240
|
+
properties: {
|
|
241
|
+
delegationType: {
|
|
242
|
+
type: string;
|
|
243
|
+
title: string;
|
|
244
|
+
description: string;
|
|
245
|
+
anyOf: {
|
|
246
|
+
const: string;
|
|
247
|
+
title: string;
|
|
248
|
+
}[];
|
|
249
|
+
};
|
|
250
|
+
delegationContract: {
|
|
251
|
+
type: string;
|
|
252
|
+
format: string;
|
|
253
|
+
title: string;
|
|
254
|
+
description: string;
|
|
255
|
+
examples: string[];
|
|
256
|
+
};
|
|
257
|
+
delegationApi: {
|
|
258
|
+
type: string;
|
|
259
|
+
format: string;
|
|
260
|
+
title: string;
|
|
261
|
+
description: string;
|
|
262
|
+
examples: string[];
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
required: string[];
|
|
266
|
+
additionalProperties: boolean;
|
|
240
267
|
};
|
|
241
268
|
allowAlias: {
|
|
242
269
|
type: string;
|
package/dist/schemas/index.d.ts
CHANGED
|
@@ -231,8 +231,35 @@ declare const _default: {
|
|
|
231
231
|
required: string[];
|
|
232
232
|
additionalProperties: boolean;
|
|
233
233
|
};
|
|
234
|
-
|
|
234
|
+
delegationPortal: {
|
|
235
235
|
type: string;
|
|
236
|
+
properties: {
|
|
237
|
+
delegationType: {
|
|
238
|
+
type: string;
|
|
239
|
+
title: string;
|
|
240
|
+
description: string;
|
|
241
|
+
anyOf: {
|
|
242
|
+
const: string;
|
|
243
|
+
title: string;
|
|
244
|
+
}[];
|
|
245
|
+
};
|
|
246
|
+
delegationContract: {
|
|
247
|
+
type: string;
|
|
248
|
+
format: string;
|
|
249
|
+
title: string;
|
|
250
|
+
description: string;
|
|
251
|
+
examples: string[];
|
|
252
|
+
};
|
|
253
|
+
delegationApi: {
|
|
254
|
+
type: string;
|
|
255
|
+
format: string;
|
|
256
|
+
title: string;
|
|
257
|
+
description: string;
|
|
258
|
+
examples: string[];
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
required: string[];
|
|
262
|
+
additionalProperties: boolean;
|
|
236
263
|
};
|
|
237
264
|
allowAlias: {
|
|
238
265
|
type: string;
|
package/dist/snapshot.cjs.js
CHANGED
|
@@ -4,6 +4,7 @@ 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');
|
|
7
|
+
var units = require('@ethersproject/units');
|
|
7
8
|
var ethEnsNamehash = require('@ensdomains/eth-ens-namehash');
|
|
8
9
|
var jsonToGraphqlQuery = require('json-to-graphql-query');
|
|
9
10
|
var Ajv = require('ajv');
|
|
@@ -751,8 +752,45 @@ var definitions = {
|
|
|
751
752
|
],
|
|
752
753
|
additionalProperties: false
|
|
753
754
|
},
|
|
754
|
-
|
|
755
|
-
type: "
|
|
755
|
+
delegationPortal: {
|
|
756
|
+
type: "object",
|
|
757
|
+
properties: {
|
|
758
|
+
delegationType: {
|
|
759
|
+
type: "string",
|
|
760
|
+
title: "Delegation type",
|
|
761
|
+
description: "Specify the type of delegation that you are using",
|
|
762
|
+
anyOf: [
|
|
763
|
+
{
|
|
764
|
+
"const": "compound-governor",
|
|
765
|
+
title: "Compound governor"
|
|
766
|
+
}
|
|
767
|
+
]
|
|
768
|
+
},
|
|
769
|
+
delegationContract: {
|
|
770
|
+
type: "string",
|
|
771
|
+
format: "address",
|
|
772
|
+
title: "Contract address",
|
|
773
|
+
description: "The address of your delegation contract",
|
|
774
|
+
examples: [
|
|
775
|
+
"0x3901D0fDe202aF1427216b79f5243f8A022d68cf"
|
|
776
|
+
]
|
|
777
|
+
},
|
|
778
|
+
delegationApi: {
|
|
779
|
+
type: "string",
|
|
780
|
+
format: "uri",
|
|
781
|
+
title: "Delegation API",
|
|
782
|
+
description: "The URL of your delegation API (e.g a subgraph)",
|
|
783
|
+
examples: [
|
|
784
|
+
"https://api.thegraph.com/subgraphs/name/arr00/uniswap-governance-v2"
|
|
785
|
+
]
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
required: [
|
|
789
|
+
"delegationType",
|
|
790
|
+
"delegationApi",
|
|
791
|
+
"delegationContract"
|
|
792
|
+
],
|
|
793
|
+
additionalProperties: false
|
|
756
794
|
},
|
|
757
795
|
allowAlias: {
|
|
758
796
|
type: "boolean"
|
|
@@ -3986,6 +4024,32 @@ var ENS_RESOLVER_ABI = [
|
|
|
3986
4024
|
var ajv = new Ajv__default['default']({ allErrors: true, allowUnionTypes: true, $data: true });
|
|
3987
4025
|
// @ts-ignore
|
|
3988
4026
|
addFormats__default['default'](ajv);
|
|
4027
|
+
ajv.addFormat('address', {
|
|
4028
|
+
validate: function (value) {
|
|
4029
|
+
try {
|
|
4030
|
+
return address.isAddress(value);
|
|
4031
|
+
}
|
|
4032
|
+
catch (err) {
|
|
4033
|
+
return false;
|
|
4034
|
+
}
|
|
4035
|
+
}
|
|
4036
|
+
});
|
|
4037
|
+
ajv.addFormat('long', {
|
|
4038
|
+
validate: function () { return true; }
|
|
4039
|
+
});
|
|
4040
|
+
ajv.addFormat('ethValue', {
|
|
4041
|
+
validate: function (value) {
|
|
4042
|
+
if (!value.match(/^([0-9]|[1-9][0-9]+)(\.[0-9]+)?$/))
|
|
4043
|
+
return false;
|
|
4044
|
+
try {
|
|
4045
|
+
units.parseUnits(value, 18);
|
|
4046
|
+
return true;
|
|
4047
|
+
}
|
|
4048
|
+
catch (_a) {
|
|
4049
|
+
return false;
|
|
4050
|
+
}
|
|
4051
|
+
}
|
|
4052
|
+
});
|
|
3989
4053
|
// Custom URL format to allow empty string values
|
|
3990
4054
|
// https://github.com/snapshot-labs/snapshot.js/pull/541/files
|
|
3991
4055
|
ajv.addFormat('customUrl', {
|
package/dist/snapshot.esm.js
CHANGED
|
@@ -2,6 +2,7 @@ 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';
|
|
5
|
+
import { parseUnits } from '@ethersproject/units';
|
|
5
6
|
import { hash, normalize } from '@ensdomains/eth-ens-namehash';
|
|
6
7
|
import { jsonToGraphQLQuery } from 'json-to-graphql-query';
|
|
7
8
|
import Ajv from 'ajv';
|
|
@@ -742,8 +743,45 @@ var definitions = {
|
|
|
742
743
|
],
|
|
743
744
|
additionalProperties: false
|
|
744
745
|
},
|
|
745
|
-
|
|
746
|
-
type: "
|
|
746
|
+
delegationPortal: {
|
|
747
|
+
type: "object",
|
|
748
|
+
properties: {
|
|
749
|
+
delegationType: {
|
|
750
|
+
type: "string",
|
|
751
|
+
title: "Delegation type",
|
|
752
|
+
description: "Specify the type of delegation that you are using",
|
|
753
|
+
anyOf: [
|
|
754
|
+
{
|
|
755
|
+
"const": "compound-governor",
|
|
756
|
+
title: "Compound governor"
|
|
757
|
+
}
|
|
758
|
+
]
|
|
759
|
+
},
|
|
760
|
+
delegationContract: {
|
|
761
|
+
type: "string",
|
|
762
|
+
format: "address",
|
|
763
|
+
title: "Contract address",
|
|
764
|
+
description: "The address of your delegation contract",
|
|
765
|
+
examples: [
|
|
766
|
+
"0x3901D0fDe202aF1427216b79f5243f8A022d68cf"
|
|
767
|
+
]
|
|
768
|
+
},
|
|
769
|
+
delegationApi: {
|
|
770
|
+
type: "string",
|
|
771
|
+
format: "uri",
|
|
772
|
+
title: "Delegation API",
|
|
773
|
+
description: "The URL of your delegation API (e.g a subgraph)",
|
|
774
|
+
examples: [
|
|
775
|
+
"https://api.thegraph.com/subgraphs/name/arr00/uniswap-governance-v2"
|
|
776
|
+
]
|
|
777
|
+
}
|
|
778
|
+
},
|
|
779
|
+
required: [
|
|
780
|
+
"delegationType",
|
|
781
|
+
"delegationApi",
|
|
782
|
+
"delegationContract"
|
|
783
|
+
],
|
|
784
|
+
additionalProperties: false
|
|
747
785
|
},
|
|
748
786
|
allowAlias: {
|
|
749
787
|
type: "boolean"
|
|
@@ -3977,6 +4015,32 @@ var ENS_RESOLVER_ABI = [
|
|
|
3977
4015
|
var ajv = new Ajv({ allErrors: true, allowUnionTypes: true, $data: true });
|
|
3978
4016
|
// @ts-ignore
|
|
3979
4017
|
addFormats(ajv);
|
|
4018
|
+
ajv.addFormat('address', {
|
|
4019
|
+
validate: function (value) {
|
|
4020
|
+
try {
|
|
4021
|
+
return isAddress(value);
|
|
4022
|
+
}
|
|
4023
|
+
catch (err) {
|
|
4024
|
+
return false;
|
|
4025
|
+
}
|
|
4026
|
+
}
|
|
4027
|
+
});
|
|
4028
|
+
ajv.addFormat('long', {
|
|
4029
|
+
validate: function () { return true; }
|
|
4030
|
+
});
|
|
4031
|
+
ajv.addFormat('ethValue', {
|
|
4032
|
+
validate: function (value) {
|
|
4033
|
+
if (!value.match(/^([0-9]|[1-9][0-9]+)(\.[0-9]+)?$/))
|
|
4034
|
+
return false;
|
|
4035
|
+
try {
|
|
4036
|
+
parseUnits(value, 18);
|
|
4037
|
+
return true;
|
|
4038
|
+
}
|
|
4039
|
+
catch (_a) {
|
|
4040
|
+
return false;
|
|
4041
|
+
}
|
|
4042
|
+
}
|
|
4043
|
+
});
|
|
3980
4044
|
// Custom URL format to allow empty string values
|
|
3981
4045
|
// https://github.com/snapshot-labs/snapshot.js/pull/541/files
|
|
3982
4046
|
ajv.addFormat('customUrl', {
|