@snapshot-labs/snapshot.js 0.5.8 → 0.6.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapshot-labs/snapshot.js",
3
- "version": "0.5.8",
3
+ "version": "0.6.1",
4
4
  "repository": "snapshot-labs/snapshot.js",
5
5
  "license": "MIT",
6
6
  "main": "dist/snapshot.cjs.js",
package/src/networks.json CHANGED
@@ -717,6 +717,20 @@
717
717
  "start": 360030,
718
718
  "logo": "ipfs://bafkreid6pm3mic7izp3a6zlfwhhe7etd276bjfsq2xash6a4s2vmcdf65a"
719
719
  },
720
+ "148": {
721
+ "key": "148",
722
+ "name": "ShimmerEVM",
723
+ "shortName": "ShimmerEVM",
724
+ "chainId": 148,
725
+ "network": "mainnet",
726
+ "multicall": "0xcA11bde05977b3631167028862bE2a173976CA11",
727
+ "rpc": [],
728
+ "explorer": {
729
+ "url": "https://explorer.evm.shimmer.network/"
730
+ },
731
+ "start": 1290,
732
+ "logo": "ipfs://bafkreib4xhbgbhrwkmizp4d4nz3wzbpyhdm6wpz2v2pbkk7jxsgg3hdt74"
733
+ },
720
734
  "188": {
721
735
  "key": "188",
722
736
  "name": "Bytom Sidechain",
@@ -2321,6 +2335,21 @@
2321
2335
  "start": 751532,
2322
2336
  "logo": "ipfs://QmR2UYZczmYa4s8mr9HZHci5AQwyAnwUW7tSUZz7KWF3sA"
2323
2337
  },
2338
+ "245022926": {
2339
+ "key": "245022926",
2340
+ "name": "Neon Devnet",
2341
+ "shortName": "devnet",
2342
+ "chainId": 245022934,
2343
+ "network": "testnet",
2344
+ "multicall": "0xcA11bde05977b3631167028862bE2a173976CA11",
2345
+ "rpc": [],
2346
+ "explorer": {
2347
+ "url": "https://devnet.neonscan.org/"
2348
+ },
2349
+ "start": 205206112,
2350
+ "logo": "ipfs://QmecRPQGa4bU7tybg1sUQY48Md9rWnmhrT6WW5ueqvhg6P",
2351
+ "testnet": true
2352
+ },
2324
2353
  "278611351": {
2325
2354
  "key": "278611351",
2326
2355
  "name": "Razor SKALE Chain",
@@ -2425,4 +2454,4 @@
2425
2454
  "start": 7282345,
2426
2455
  "logo": "ipfs://QmRHB9TqMdVHY392vYiv8sTJ7VHShkq5FT6nS9fPuUNBf1"
2427
2456
  }
2428
- }
2457
+ }
@@ -1,5 +1,6 @@
1
1
  import space from './space.json';
2
2
  import proposal from './proposal.json';
3
+ import updateProposal from './update-proposal.json';
3
4
  import vote from './vote.json';
4
5
  import profile from './profile.json';
5
6
  import statement from './statement.json';
@@ -8,6 +9,7 @@ import zodiac from './zodiac.json';
8
9
  export default {
9
10
  space: space.definitions.Space,
10
11
  proposal: proposal.definitions.Proposal,
12
+ updateProposal: updateProposal.definitions.UpdateProposal,
11
13
  vote: vote.definitions.Vote,
12
14
  profile: profile.definitions.Profile,
13
15
  statement: statement.definitions.Statement,
@@ -0,0 +1,57 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$ref": "#/definitions/UpdateProposal",
4
+ "definitions": {
5
+ "UpdateProposal": {
6
+ "title": "Update Proposal",
7
+ "type": "object",
8
+ "properties": {
9
+ "proposal": {
10
+ "type": "string",
11
+ "title": "proposal id"
12
+ },
13
+ "name": {
14
+ "type": "string",
15
+ "title": "name",
16
+ "minLength": 1,
17
+ "maxLength": 256
18
+ },
19
+ "body": {
20
+ "type": "string",
21
+ "title": "body",
22
+ "minLength": 0,
23
+ "maxLength": 20000
24
+ },
25
+ "discussion": {
26
+ "type": "string",
27
+ "format": "customUrl",
28
+ "title": "discussion",
29
+ "maxLength": 256
30
+ },
31
+ "choices": {
32
+ "type": "array",
33
+ "title": "choices",
34
+ "minItems": 1,
35
+ "maxItems": 500
36
+ },
37
+ "type": {
38
+ "enum": [
39
+ "single-choice",
40
+ "approval",
41
+ "ranked-choice",
42
+ "quadratic",
43
+ "weighted",
44
+ "custom",
45
+ "basic"
46
+ ]
47
+ },
48
+ "metadata": {
49
+ "type": "object",
50
+ "title": "metadata"
51
+ }
52
+ },
53
+ "required": ["proposal", "name", "body", "discussion", "choices", "type", "metadata"],
54
+ "additionalProperties": false
55
+ }
56
+ }
57
+ }
package/src/sign/index.ts CHANGED
@@ -5,6 +5,7 @@ import { getAddress } from '@ethersproject/address';
5
5
  import {
6
6
  Space,
7
7
  Proposal,
8
+ UpdateProposal,
8
9
  CancelProposal,
9
10
  Vote,
10
11
  Follow,
@@ -17,6 +18,7 @@ import {
17
18
  Statement,
18
19
  spaceTypes,
19
20
  proposalTypes,
21
+ updateProposalTypes,
20
22
  cancelProposalTypes,
21
23
  cancelProposal2Types,
22
24
  voteTypes,
@@ -111,6 +113,14 @@ export default class Client {
111
113
  return await this.sign(web3, address, message, proposalTypes);
112
114
  }
113
115
 
116
+ async updateProposal(
117
+ web3: Web3Provider | Wallet,
118
+ address: string,
119
+ message: UpdateProposal
120
+ ) {
121
+ return await this.sign(web3, address, message, updateProposalTypes);
122
+ }
123
+
114
124
  async cancelProposal(
115
125
  web3: Web3Provider | Wallet,
116
126
  address: string,
@@ -4,6 +4,7 @@
4
4
  "6fee59b7db10fabbb0c6420c0a18c9d2c36306e342042826a355bfc7fe733870": "proposal",
5
5
  "9ff8af4cfb586e2c7962d792b99328fb47e8a4e73cc89873c0980484bc1063a5": "delete-proposal",
6
6
  "734df82cdad586386defa4cb55adda7cb1b2a56929c4e6c3dc676f9901947288": "delete-proposal",
7
+ "4e5fa89616761defa1274103441809c8445f8404306890ad36ec653d90201d58": "update-proposal",
7
8
  "50084aae0fe117c83ddf855557dde35ae2872e9045443a15f72aa6c68ea3943b": "vote",
8
9
  "1dfe3863f6333a85581fb150d4ee77c95a6d026c518ca1b11c08ae1d98acd598": "vote-array",
9
10
  "1814c3dd303c5919ce488b924f92b9a42a0834972f514e55b1879fda48e67736": "vote-string",
package/src/sign/types.ts CHANGED
@@ -29,6 +29,19 @@ export interface Proposal {
29
29
  app?: string;
30
30
  }
31
31
 
32
+ export interface UpdateProposal {
33
+ proposal: string;
34
+ from: string;
35
+ space: string;
36
+ timestamp: number;
37
+ type: ProposalType;
38
+ title: string;
39
+ body: string;
40
+ discussion: string;
41
+ choices: string[];
42
+ plugins: string;
43
+ }
44
+
32
45
  export interface CancelProposal {
33
46
  from?: string;
34
47
  space: string;
@@ -126,6 +139,21 @@ export const proposalTypes = {
126
139
  ]
127
140
  };
128
141
 
142
+ export const updateProposalTypes = {
143
+ UpdateProposal: [
144
+ { name: 'proposal', type: 'string' },
145
+ { name: 'from', type: 'address' },
146
+ { name: 'space', type: 'string' },
147
+ { name: 'timestamp', type: 'uint64' },
148
+ { name: 'type', type: 'string' },
149
+ { name: 'title', type: 'string' },
150
+ { name: 'body', type: 'string' },
151
+ { name: 'discussion', type: 'string' },
152
+ { name: 'choices', type: 'string[]' },
153
+ { name: 'plugins', type: 'string' }
154
+ ]
155
+ };
156
+
129
157
  export const cancelProposalTypes = {
130
158
  CancelProposal: [
131
159
  { name: 'from', type: 'address' },
package/src/utils.ts CHANGED
@@ -150,14 +150,16 @@ export async function subgraphRequest(url: string, query, options: any = {}) {
150
150
  responseData = JSON.parse(responseData);
151
151
  } catch (e) {
152
152
  throw new Error(
153
- `Errors found in subgraphRequest: URL: ${url}, Status: ${res.status}, Response: ${responseData}`
153
+ `Errors found in subgraphRequest: URL: ${url}, Status: ${
154
+ res.status
155
+ }, Response: ${responseData.substring(0, 400)}`
154
156
  );
155
157
  }
156
158
  if (responseData.errors) {
157
159
  throw new Error(
158
160
  `Errors found in subgraphRequest: URL: ${url}, Status: ${
159
161
  res.status
160
- }, Response: ${JSON.stringify(responseData.errors)}`
162
+ }, Response: ${JSON.stringify(responseData.errors).substring(0, 400)}`
161
163
  );
162
164
  }
163
165
  const { data } = responseData;
@@ -238,10 +240,18 @@ export async function getScores(
238
240
  body: JSON.stringify({ params })
239
241
  });
240
242
  const obj = await res.json();
243
+
244
+ if (obj.error) {
245
+ return Promise.reject(obj.error);
246
+ }
247
+
241
248
  return options.returnValue === 'all'
242
249
  ? obj.result
243
250
  : obj.result[options.returnValue || 'scores'];
244
251
  } catch (e) {
252
+ if (e.errno) {
253
+ return Promise.reject({ code: e.errno, message: e.toString(), data: '' });
254
+ }
245
255
  return Promise.reject(e);
246
256
  }
247
257
  }
@@ -273,10 +283,18 @@ export async function getVp(
273
283
  }
274
284
  })
275
285
  };
276
- const res = await fetch(options.url, init);
277
- const json = await res.json();
278
- if (json.error) return Promise.reject(json.error);
279
- if (json.result) return json.result;
286
+
287
+ try {
288
+ const res = await fetch(options.url, init);
289
+ const json = await res.json();
290
+ if (json.error) return Promise.reject(json.error);
291
+ if (json.result) return json.result;
292
+ } catch (e) {
293
+ if (e.errno) {
294
+ return Promise.reject({ code: e.errno, message: e.toString(), data: '' });
295
+ }
296
+ return Promise.reject(e);
297
+ }
280
298
  }
281
299
 
282
300
  export async function validate(
@@ -306,10 +324,18 @@ export async function validate(
306
324
  }
307
325
  })
308
326
  };
309
- const res = await fetch(options.url, init);
310
- const json = await res.json();
311
- if (json.error) return Promise.reject(json.error);
312
- return json.result;
327
+
328
+ try {
329
+ const res = await fetch(options.url, init);
330
+ const json = await res.json();
331
+ if (json.error) return Promise.reject(json.error);
332
+ return json.result;
333
+ } catch (e) {
334
+ if (e.errno) {
335
+ return Promise.reject({ code: e.errno, message: e.toString(), data: '' });
336
+ }
337
+ return Promise.reject(e);
338
+ }
313
339
  }
314
340
 
315
341
  export function validateSchema(schema, data) {
@@ -412,8 +438,7 @@ export async function getDelegatesBySpace(
412
438
  snapshot = 'latest',
413
439
  options: any = {}
414
440
  ) {
415
- const subgraphUrl =
416
- options.subgraphUrl || SNAPSHOT_SUBGRAPH_URL[network];
441
+ const subgraphUrl = options.subgraphUrl || SNAPSHOT_SUBGRAPH_URL[network];
417
442
  if (!subgraphUrl) {
418
443
  return Promise.reject(
419
444
  `Delegation subgraph not available for network ${network}`