@snapshot-labs/snapshot.js 0.5.8 → 0.6.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/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.0",
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
@@ -238,10 +238,18 @@ export async function getScores(
238
238
  body: JSON.stringify({ params })
239
239
  });
240
240
  const obj = await res.json();
241
+
242
+ if (obj.error) {
243
+ return Promise.reject(obj.error);
244
+ }
245
+
241
246
  return options.returnValue === 'all'
242
247
  ? obj.result
243
248
  : obj.result[options.returnValue || 'scores'];
244
249
  } catch (e) {
250
+ if (e.errno) {
251
+ return Promise.reject({ code: e.errno, message: e.toString(), data: '' });
252
+ }
245
253
  return Promise.reject(e);
246
254
  }
247
255
  }
@@ -273,10 +281,18 @@ export async function getVp(
273
281
  }
274
282
  })
275
283
  };
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;
284
+
285
+ try {
286
+ const res = await fetch(options.url, init);
287
+ const json = await res.json();
288
+ if (json.error) return Promise.reject(json.error);
289
+ if (json.result) return json.result;
290
+ } catch (e) {
291
+ if (e.errno) {
292
+ return Promise.reject({ code: e.errno, message: e.toString(), data: '' });
293
+ }
294
+ return Promise.reject(e);
295
+ }
280
296
  }
281
297
 
282
298
  export async function validate(
@@ -306,10 +322,18 @@ export async function validate(
306
322
  }
307
323
  })
308
324
  };
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;
325
+
326
+ try {
327
+ const res = await fetch(options.url, init);
328
+ const json = await res.json();
329
+ if (json.error) return Promise.reject(json.error);
330
+ return json.result;
331
+ } catch (e) {
332
+ if (e.errno) {
333
+ return Promise.reject({ code: e.errno, message: e.toString(), data: '' });
334
+ }
335
+ return Promise.reject(e);
336
+ }
313
337
  }
314
338
 
315
339
  export function validateSchema(schema, data) {
@@ -412,8 +436,7 @@ export async function getDelegatesBySpace(
412
436
  snapshot = 'latest',
413
437
  options: any = {}
414
438
  ) {
415
- const subgraphUrl =
416
- options.subgraphUrl || SNAPSHOT_SUBGRAPH_URL[network];
439
+ const subgraphUrl = options.subgraphUrl || SNAPSHOT_SUBGRAPH_URL[network];
417
440
  if (!subgraphUrl) {
418
441
  return Promise.reject(
419
442
  `Delegation subgraph not available for network ${network}`