@snapshot-labs/snapshot.js 0.8.2 → 0.9.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/dist/index.d.ts +4 -0
- package/dist/schemas/index.d.ts +4 -0
- package/dist/snapshot.cjs.js +39 -9
- package/dist/snapshot.esm.js +39 -9
- package/dist/snapshot.min.js +3 -3
- package/dist/utils.d.ts +3 -1
- package/package.json +1 -1
- package/src/networks.json +4 -4
- package/src/schemas/space.json +4 -1
- package/src/schemas/zodiac.json +2 -1
- package/src/utils.ts +36 -3
package/dist/utils.d.ts
CHANGED
|
@@ -31,7 +31,9 @@ export declare function sendTransaction(web3: any, contractAddress: string, abi:
|
|
|
31
31
|
export declare function getScores(space: string, strategies: Strategy[], network: string, addresses: string[], snapshot?: number | string, scoreApiUrl?: string, options?: any): Promise<any>;
|
|
32
32
|
export declare function getVp(address: string, network: string, strategies: Strategy[], snapshot: number | 'latest', space: string, delegation: boolean, options?: Options): Promise<any>;
|
|
33
33
|
export declare function validate(validation: string, author: string, space: string, network: string, snapshot: number | 'latest', params: any, options: any): Promise<any>;
|
|
34
|
-
export declare function validateSchema(schema: any, data: any
|
|
34
|
+
export declare function validateSchema(schema: any, data: any, options?: {
|
|
35
|
+
snapshotEnv: string;
|
|
36
|
+
}): true | import("ajv").ErrorObject<string, Record<string, any>, unknown>[] | null | undefined;
|
|
35
37
|
export declare function getEnsTextRecord(ens: string, record: string, network?: string, options?: any): Promise<any>;
|
|
36
38
|
export declare function getSpaceUri(id: string, network?: string, options?: any): Promise<string | null>;
|
|
37
39
|
export declare function getEnsOwner(ens: string, network?: string, options?: any): Promise<string | null>;
|
package/package.json
CHANGED
package/src/networks.json
CHANGED
|
@@ -705,7 +705,7 @@
|
|
|
705
705
|
"explorer": {
|
|
706
706
|
"url": "https://explorer.kardiachain.io"
|
|
707
707
|
},
|
|
708
|
-
"logo": "ipfs://
|
|
708
|
+
"logo": "ipfs://bafkreig73yfyqzbxydv6e3dbj5nks3f57px2iez7tywayey4rilfhhrr34"
|
|
709
709
|
},
|
|
710
710
|
"1072": {
|
|
711
711
|
"key": "1072",
|
|
@@ -722,7 +722,7 @@
|
|
|
722
722
|
"url": "https://explorer.evm.testnet.shimmer.network/"
|
|
723
723
|
},
|
|
724
724
|
"start": 10614,
|
|
725
|
-
"logo": "ipfs://
|
|
725
|
+
"logo": "ipfs://bafkreihtwfwrue7klzedwx4rqlk6agklz4lbbk7owsyw6xzn6c2m4t5tgy"
|
|
726
726
|
},
|
|
727
727
|
"1088": {
|
|
728
728
|
"key": "1088",
|
|
@@ -1019,7 +1019,7 @@
|
|
|
1019
1019
|
"url": "https://bx.shyft.network"
|
|
1020
1020
|
},
|
|
1021
1021
|
"start": 3673983,
|
|
1022
|
-
"logo": "ipfs://
|
|
1022
|
+
"logo": "ipfs://bafkreifwxnnfk6koabzmxgcxcwlrwt6b5gijdain2gyqee77q4ajfb7fu4"
|
|
1023
1023
|
},
|
|
1024
1024
|
"8217": {
|
|
1025
1025
|
"key": "8217",
|
|
@@ -1070,7 +1070,7 @@
|
|
|
1070
1070
|
"url": "https://escan.live"
|
|
1071
1071
|
},
|
|
1072
1072
|
"start": 13959539,
|
|
1073
|
-
"logo": "ipfs://
|
|
1073
|
+
"logo": "ipfs://bafkreif4obrdoiretpozdd56seziywc6clha7wwkbldng3ovry2bpzly34"
|
|
1074
1074
|
},
|
|
1075
1075
|
"10000": {
|
|
1076
1076
|
"key": "10000",
|
package/src/schemas/space.json
CHANGED
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
},
|
|
80
80
|
"network": {
|
|
81
81
|
"type": "string",
|
|
82
|
+
"snapshotNetwork": true,
|
|
82
83
|
"title": "network",
|
|
83
84
|
"minLength": 1,
|
|
84
85
|
"maxLength": 32
|
|
@@ -114,7 +115,8 @@
|
|
|
114
115
|
"network": {
|
|
115
116
|
"type": "string",
|
|
116
117
|
"maxLength": 12,
|
|
117
|
-
"title": "network"
|
|
118
|
+
"title": "network",
|
|
119
|
+
"snapshotNetwork": true
|
|
118
120
|
},
|
|
119
121
|
"params": {
|
|
120
122
|
"type": "object",
|
|
@@ -346,6 +348,7 @@
|
|
|
346
348
|
},
|
|
347
349
|
"network": {
|
|
348
350
|
"type": "string",
|
|
351
|
+
"snapshotNetwork": true,
|
|
349
352
|
"title": "Network",
|
|
350
353
|
"maxLength": 12
|
|
351
354
|
}
|
package/src/schemas/zodiac.json
CHANGED
package/src/utils.ts
CHANGED
|
@@ -37,7 +37,12 @@ const scoreApiHeaders = {
|
|
|
37
37
|
'Content-Type': 'application/json'
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
const ajv = new Ajv({
|
|
40
|
+
const ajv = new Ajv({
|
|
41
|
+
allErrors: true,
|
|
42
|
+
allowUnionTypes: true,
|
|
43
|
+
$data: true,
|
|
44
|
+
passContext: true
|
|
45
|
+
});
|
|
41
46
|
// @ts-ignore
|
|
42
47
|
addFormats(ajv);
|
|
43
48
|
|
|
@@ -68,6 +73,28 @@ ajv.addFormat('ethValue', {
|
|
|
68
73
|
}
|
|
69
74
|
});
|
|
70
75
|
|
|
76
|
+
const networksIds = Object.keys(networks);
|
|
77
|
+
const mainnetNetworkIds = Object.keys(networks).filter(
|
|
78
|
+
(id) => !networks[id].testnet
|
|
79
|
+
);
|
|
80
|
+
const testnetNetworkIds = Object.keys(networks).filter(
|
|
81
|
+
(id) => networks[id].testnet
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
ajv.addKeyword({
|
|
85
|
+
keyword: 'snapshotNetwork',
|
|
86
|
+
validate: function (schema, data) {
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
const snapshotEnv = this.snapshotEnv || 'default';
|
|
89
|
+
if (snapshotEnv === 'mainnet') return mainnetNetworkIds.includes(data);
|
|
90
|
+
if (snapshotEnv === 'testnet') return testnetNetworkIds.includes(data);
|
|
91
|
+
return networksIds.includes(data);
|
|
92
|
+
},
|
|
93
|
+
error: {
|
|
94
|
+
message: 'must be a valid network used by snapshot'
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
71
98
|
// Custom URL format to allow empty string values
|
|
72
99
|
// https://github.com/snapshot-labs/snapshot.js/pull/541/files
|
|
73
100
|
ajv.addFormat('customUrl', {
|
|
@@ -338,9 +365,15 @@ export async function validate(
|
|
|
338
365
|
}
|
|
339
366
|
}
|
|
340
367
|
|
|
341
|
-
export function validateSchema(
|
|
368
|
+
export function validateSchema(
|
|
369
|
+
schema,
|
|
370
|
+
data,
|
|
371
|
+
options = {
|
|
372
|
+
snapshotEnv: 'default'
|
|
373
|
+
}
|
|
374
|
+
) {
|
|
342
375
|
const ajvValidate = ajv.compile(schema);
|
|
343
|
-
const valid = ajvValidate(data);
|
|
376
|
+
const valid = ajvValidate.call(options, data);
|
|
344
377
|
return valid ? valid : ajvValidate.errors;
|
|
345
378
|
}
|
|
346
379
|
|