@snapshot-labs/snapshot.js 0.14.5 → 0.14.7

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.
@@ -1,4 +1,4 @@
1
- import fetch from 'cross-fetch';
1
+ import crossFetch from 'cross-fetch';
2
2
  import { Contract as Contract$1 } from '@ethersproject/contracts';
3
3
  import { isAddress, getAddress } from '@ethersproject/address';
4
4
  import { parseUnits } from '@ethersproject/units';
@@ -52,227 +52,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
52
52
  });
53
53
  }
54
54
 
55
- const spaceTypes = {
56
- Space: [
57
- { name: 'from', type: 'address' },
58
- { name: 'space', type: 'string' },
59
- { name: 'timestamp', type: 'uint64' },
60
- { name: 'settings', type: 'string' }
61
- ]
62
- };
63
- const proposalTypes = {
64
- Proposal: [
65
- { name: 'from', type: 'string' },
66
- { name: 'space', type: 'string' },
67
- { name: 'timestamp', type: 'uint64' },
68
- { name: 'type', type: 'string' },
69
- { name: 'title', type: 'string' },
70
- { name: 'body', type: 'string' },
71
- { name: 'discussion', type: 'string' },
72
- { name: 'choices', type: 'string[]' },
73
- { name: 'labels', type: 'string[]' },
74
- { name: 'start', type: 'uint64' },
75
- { name: 'end', type: 'uint64' },
76
- { name: 'snapshot', type: 'uint64' },
77
- { name: 'plugins', type: 'string' },
78
- { name: 'privacy', type: 'string' },
79
- { name: 'app', type: 'string' }
80
- ]
81
- };
82
- const updateProposalTypes = {
83
- UpdateProposal: [
84
- { name: 'proposal', type: 'string' },
85
- { name: 'from', type: 'string' },
86
- { name: 'space', type: 'string' },
87
- { name: 'timestamp', type: 'uint64' },
88
- { name: 'type', type: 'string' },
89
- { name: 'title', type: 'string' },
90
- { name: 'body', type: 'string' },
91
- { name: 'discussion', type: 'string' },
92
- { name: 'choices', type: 'string[]' },
93
- { name: 'labels', type: 'string[]' },
94
- { name: 'plugins', type: 'string' },
95
- { name: 'privacy', type: 'string' }
96
- ]
97
- };
98
- const flagProposalTypes = {
99
- FlagProposal: [
100
- { name: 'from', type: 'string' },
101
- { name: 'space', type: 'string' },
102
- { name: 'proposal', type: 'string' },
103
- { name: 'timestamp', type: 'uint64' }
104
- ]
105
- };
106
- const cancelProposalTypes = {
107
- CancelProposal: [
108
- { name: 'from', type: 'string' },
109
- { name: 'space', type: 'string' },
110
- { name: 'timestamp', type: 'uint64' },
111
- { name: 'proposal', type: 'string' }
112
- ]
113
- };
114
- const cancelProposal2Types = {
115
- CancelProposal: [
116
- { name: 'from', type: 'string' },
117
- { name: 'space', type: 'string' },
118
- { name: 'timestamp', type: 'uint64' },
119
- { name: 'proposal', type: 'bytes32' }
120
- ]
121
- };
122
- const voteTypes = {
123
- Vote: [
124
- { name: 'from', type: 'string' },
125
- { name: 'space', type: 'string' },
126
- { name: 'timestamp', type: 'uint64' },
127
- { name: 'proposal', type: 'string' },
128
- { name: 'choice', type: 'uint32' },
129
- { name: 'reason', type: 'string' },
130
- { name: 'app', type: 'string' },
131
- { name: 'metadata', type: 'string' }
132
- ]
133
- };
134
- const voteArrayTypes = {
135
- Vote: [
136
- { name: 'from', type: 'string' },
137
- { name: 'space', type: 'string' },
138
- { name: 'timestamp', type: 'uint64' },
139
- { name: 'proposal', type: 'string' },
140
- { name: 'choice', type: 'uint32[]' },
141
- { name: 'reason', type: 'string' },
142
- { name: 'app', type: 'string' },
143
- { name: 'metadata', type: 'string' }
144
- ]
145
- };
146
- const voteStringTypes = {
147
- Vote: [
148
- { name: 'from', type: 'string' },
149
- { name: 'space', type: 'string' },
150
- { name: 'timestamp', type: 'uint64' },
151
- { name: 'proposal', type: 'string' },
152
- { name: 'choice', type: 'string' },
153
- { name: 'reason', type: 'string' },
154
- { name: 'app', type: 'string' },
155
- { name: 'metadata', type: 'string' }
156
- ]
157
- };
158
- const vote2Types = {
159
- Vote: [
160
- { name: 'from', type: 'string' },
161
- { name: 'space', type: 'string' },
162
- { name: 'timestamp', type: 'uint64' },
163
- { name: 'proposal', type: 'bytes32' },
164
- { name: 'choice', type: 'uint32' },
165
- { name: 'reason', type: 'string' },
166
- { name: 'app', type: 'string' },
167
- { name: 'metadata', type: 'string' }
168
- ]
169
- };
170
- const voteArray2Types = {
171
- Vote: [
172
- { name: 'from', type: 'string' },
173
- { name: 'space', type: 'string' },
174
- { name: 'timestamp', type: 'uint64' },
175
- { name: 'proposal', type: 'bytes32' },
176
- { name: 'choice', type: 'uint32[]' },
177
- { name: 'reason', type: 'string' },
178
- { name: 'app', type: 'string' },
179
- { name: 'metadata', type: 'string' }
180
- ]
181
- };
182
- const voteString2Types = {
183
- Vote: [
184
- { name: 'from', type: 'string' },
185
- { name: 'space', type: 'string' },
186
- { name: 'timestamp', type: 'uint64' },
187
- { name: 'proposal', type: 'bytes32' },
188
- { name: 'choice', type: 'string' },
189
- { name: 'reason', type: 'string' },
190
- { name: 'app', type: 'string' },
191
- { name: 'metadata', type: 'string' }
192
- ]
193
- };
194
- const followTypes = {
195
- Follow: [
196
- { name: 'from', type: 'address' },
197
- { name: 'network', type: 'string' },
198
- { name: 'space', type: 'string' },
199
- { name: 'timestamp', type: 'uint64' }
200
- ]
201
- };
202
- const unfollowTypes = {
203
- Unfollow: [
204
- { name: 'from', type: 'address' },
205
- { name: 'network', type: 'string' },
206
- { name: 'space', type: 'string' },
207
- { name: 'timestamp', type: 'uint64' }
208
- ]
209
- };
210
- const subscribeTypes = {
211
- Subscribe: [
212
- { name: 'from', type: 'address' },
213
- { name: 'space', type: 'string' },
214
- { name: 'timestamp', type: 'uint64' }
215
- ]
216
- };
217
- const unsubscribeTypes = {
218
- Unsubscribe: [
219
- { name: 'from', type: 'address' },
220
- { name: 'space', type: 'string' },
221
- { name: 'timestamp', type: 'uint64' }
222
- ]
223
- };
224
- const profileTypes = {
225
- Profile: [
226
- { name: 'from', type: 'address' },
227
- { name: 'timestamp', type: 'uint64' },
228
- { name: 'profile', type: 'string' }
229
- ]
230
- };
231
- const statementTypes = {
232
- Statement: [
233
- { name: 'from', type: 'address' },
234
- { name: 'timestamp', type: 'uint64' },
235
- { name: 'space', type: 'string' },
236
- { name: 'about', type: 'string' },
237
- { name: 'statement', type: 'string' },
238
- { name: 'discourse', type: 'string' },
239
- { name: 'status', type: 'string' },
240
- { name: 'network', type: 'string' }
241
- ]
242
- };
243
- const aliasTypes = {
244
- Alias: [
245
- { name: 'from', type: 'address' },
246
- { name: 'alias', type: 'address' },
247
- { name: 'timestamp', type: 'uint64' }
248
- ]
249
- };
250
- const deleteSpaceType = {
251
- DeleteSpace: [
252
- { name: 'from', type: 'address' },
253
- { name: 'space', type: 'string' },
254
- { name: 'timestamp', type: 'uint64' }
255
- ]
256
- };
257
-
258
- var mainnet = {
259
- hub: "https://hub.snapshot.org",
260
- sequencer: "https://seq.snapshot.org"
261
- };
262
- var testnet = {
263
- hub: "https://testnet.hub.snapshot.org",
264
- sequencer: "https://testnet.seq.snapshot.org"
265
- };
266
- var local = {
267
- hub: "http://localhost:3000",
268
- sequencer: "http://localhost:3001"
269
- };
270
- var constants = {
271
- mainnet: mainnet,
272
- testnet: testnet,
273
- local: local
274
- };
275
-
276
55
  let cache = {};
277
56
  let expirationTime = 0;
278
57
  function getSnapshots(network_1, snapshot_1, provider_1, networks_1) {
@@ -733,6 +512,21 @@ var networks = {
733
512
  },
734
513
  start: 1290,
735
514
  logo: "ipfs://bafkreib4xhbgbhrwkmizp4d4nz3wzbpyhdm6wpz2v2pbkk7jxsgg3hdt74"
515
+ },
516
+ "151": {
517
+ key: "151",
518
+ name: "Redbelly",
519
+ shortName: "mainnet",
520
+ chainId: 151,
521
+ network: "mainnet",
522
+ multicall: "0xEe43BBcC6340038130681F98d855E416F7F728e9",
523
+ rpc: [
524
+ ],
525
+ explorer: {
526
+ url: "https://redbelly.routescan.io"
527
+ },
528
+ start: 1908395,
529
+ logo: "ipfs://bafkreie5mdk5shaebcec6zs5dc4722u2tn7oxvkksjy62kkjdzgnvmad7q"
736
530
  },
737
531
  "157": {
738
532
  key: "157",
@@ -2901,7 +2695,7 @@ class RankedChoiceVoting {
2901
2695
  return this.proposal.choices.map((choice, i) => this.strategies.map((strategy, sI) => {
2902
2696
  return finalRound
2903
2697
  .filter((res) => Number(res[0]) === i + 1)
2904
- .reduce((a, b) => a + b[1][1][sI], 0);
2698
+ .reduce((a, b) => a + b[1][1][sI] || 0, 0);
2905
2699
  }));
2906
2700
  }
2907
2701
  getScoresTotal() {
@@ -3704,10 +3498,67 @@ function getUrl(uri, gateway = gateways[0]) {
3704
3498
  return uri.replace('ipns://', `${ipfsGateway}/ipns/`);
3705
3499
  return uri;
3706
3500
  }
3501
+ /**
3502
+ * Enhanced fetch with timeout support - drop-in replacement for native fetch
3503
+ *
3504
+ * @param url - The URL to fetch
3505
+ * @param options - Fetch options with optional timeout
3506
+ * @param options.timeout - Request timeout in milliseconds (default: 30000ms). Set to 0 to disable timeout.
3507
+ *
3508
+ * @returns Promise that resolves to the Response object
3509
+ *
3510
+ * @throws {Error} Throws timeout error if request exceeds the specified timeout duration
3511
+ *
3512
+ * @example
3513
+ * ```typescript
3514
+ * // Uses default 30s timeout
3515
+ * const response = await fetch('https://api.example.com/data');
3516
+ *
3517
+ * // Custom 5s timeout
3518
+ * const response = await fetch('https://api.example.com/data', { timeout: 5000 });
3519
+ *
3520
+ * // Disable timeout
3521
+ * const response = await fetch('https://api.example.com/data', { timeout: 0 });
3522
+ *
3523
+ * // With additional fetch options
3524
+ * const response = await fetch('https://api.example.com/data', {
3525
+ * timeout: 10000,
3526
+ * method: 'POST',
3527
+ * headers: { 'Content-Type': 'application/json' },
3528
+ * body: JSON.stringify({ key: 'value' })
3529
+ * });
3530
+ * ```
3531
+ */
3532
+ function fetch(url_1) {
3533
+ return __awaiter(this, arguments, void 0, function* (url, options = {}) {
3534
+ const { timeout = 30000 } = options, fetchOptions = __rest(options, ["timeout"]);
3535
+ if (timeout > 0) {
3536
+ const controller = new AbortController();
3537
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
3538
+ try {
3539
+ const response = yield crossFetch(url, Object.assign(Object.assign({}, fetchOptions), { signal: controller.signal }));
3540
+ return response;
3541
+ }
3542
+ catch (error) {
3543
+ if (error instanceof Error && error.name === 'AbortError') {
3544
+ throw new Error(`Request timeout after ${timeout}ms`);
3545
+ }
3546
+ throw error;
3547
+ }
3548
+ finally {
3549
+ clearTimeout(timeoutId);
3550
+ }
3551
+ }
3552
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3553
+ const cleanFetchOptions = __rest(fetchOptions, ["signal"]);
3554
+ return crossFetch(url, cleanFetchOptions);
3555
+ });
3556
+ }
3707
3557
  function getJSON(uri_1) {
3708
3558
  return __awaiter(this, arguments, void 0, function* (uri, options = {}) {
3709
3559
  const url = getUrl(uri, options.gateways);
3710
- return fetch(url).then((res) => res.json());
3560
+ const response = yield fetch(url, options);
3561
+ return response.json();
3711
3562
  });
3712
3563
  }
3713
3564
  function ipfsGet(gateway_1, ipfsHash_1) {
@@ -4082,6 +3933,7 @@ function inputError(message) {
4082
3933
  var utils = {
4083
3934
  call,
4084
3935
  multicall: multicall$2,
3936
+ fetch,
4085
3937
  subgraphRequest,
4086
3938
  ipfsGet,
4087
3939
  getUrl,
@@ -4113,6 +3965,227 @@ var utils = {
4113
3965
  SNAPSHOT_SUBGRAPH_URL
4114
3966
  };
4115
3967
 
3968
+ const spaceTypes = {
3969
+ Space: [
3970
+ { name: 'from', type: 'address' },
3971
+ { name: 'space', type: 'string' },
3972
+ { name: 'timestamp', type: 'uint64' },
3973
+ { name: 'settings', type: 'string' }
3974
+ ]
3975
+ };
3976
+ const proposalTypes = {
3977
+ Proposal: [
3978
+ { name: 'from', type: 'string' },
3979
+ { name: 'space', type: 'string' },
3980
+ { name: 'timestamp', type: 'uint64' },
3981
+ { name: 'type', type: 'string' },
3982
+ { name: 'title', type: 'string' },
3983
+ { name: 'body', type: 'string' },
3984
+ { name: 'discussion', type: 'string' },
3985
+ { name: 'choices', type: 'string[]' },
3986
+ { name: 'labels', type: 'string[]' },
3987
+ { name: 'start', type: 'uint64' },
3988
+ { name: 'end', type: 'uint64' },
3989
+ { name: 'snapshot', type: 'uint64' },
3990
+ { name: 'plugins', type: 'string' },
3991
+ { name: 'privacy', type: 'string' },
3992
+ { name: 'app', type: 'string' }
3993
+ ]
3994
+ };
3995
+ const updateProposalTypes = {
3996
+ UpdateProposal: [
3997
+ { name: 'proposal', type: 'string' },
3998
+ { name: 'from', type: 'string' },
3999
+ { name: 'space', type: 'string' },
4000
+ { name: 'timestamp', type: 'uint64' },
4001
+ { name: 'type', type: 'string' },
4002
+ { name: 'title', type: 'string' },
4003
+ { name: 'body', type: 'string' },
4004
+ { name: 'discussion', type: 'string' },
4005
+ { name: 'choices', type: 'string[]' },
4006
+ { name: 'labels', type: 'string[]' },
4007
+ { name: 'plugins', type: 'string' },
4008
+ { name: 'privacy', type: 'string' }
4009
+ ]
4010
+ };
4011
+ const flagProposalTypes = {
4012
+ FlagProposal: [
4013
+ { name: 'from', type: 'string' },
4014
+ { name: 'space', type: 'string' },
4015
+ { name: 'proposal', type: 'string' },
4016
+ { name: 'timestamp', type: 'uint64' }
4017
+ ]
4018
+ };
4019
+ const cancelProposalTypes = {
4020
+ CancelProposal: [
4021
+ { name: 'from', type: 'string' },
4022
+ { name: 'space', type: 'string' },
4023
+ { name: 'timestamp', type: 'uint64' },
4024
+ { name: 'proposal', type: 'string' }
4025
+ ]
4026
+ };
4027
+ const cancelProposal2Types = {
4028
+ CancelProposal: [
4029
+ { name: 'from', type: 'string' },
4030
+ { name: 'space', type: 'string' },
4031
+ { name: 'timestamp', type: 'uint64' },
4032
+ { name: 'proposal', type: 'bytes32' }
4033
+ ]
4034
+ };
4035
+ const voteTypes = {
4036
+ Vote: [
4037
+ { name: 'from', type: 'string' },
4038
+ { name: 'space', type: 'string' },
4039
+ { name: 'timestamp', type: 'uint64' },
4040
+ { name: 'proposal', type: 'string' },
4041
+ { name: 'choice', type: 'uint32' },
4042
+ { name: 'reason', type: 'string' },
4043
+ { name: 'app', type: 'string' },
4044
+ { name: 'metadata', type: 'string' }
4045
+ ]
4046
+ };
4047
+ const voteArrayTypes = {
4048
+ Vote: [
4049
+ { name: 'from', type: 'string' },
4050
+ { name: 'space', type: 'string' },
4051
+ { name: 'timestamp', type: 'uint64' },
4052
+ { name: 'proposal', type: 'string' },
4053
+ { name: 'choice', type: 'uint32[]' },
4054
+ { name: 'reason', type: 'string' },
4055
+ { name: 'app', type: 'string' },
4056
+ { name: 'metadata', type: 'string' }
4057
+ ]
4058
+ };
4059
+ const voteStringTypes = {
4060
+ Vote: [
4061
+ { name: 'from', type: 'string' },
4062
+ { name: 'space', type: 'string' },
4063
+ { name: 'timestamp', type: 'uint64' },
4064
+ { name: 'proposal', type: 'string' },
4065
+ { name: 'choice', type: 'string' },
4066
+ { name: 'reason', type: 'string' },
4067
+ { name: 'app', type: 'string' },
4068
+ { name: 'metadata', type: 'string' }
4069
+ ]
4070
+ };
4071
+ const vote2Types = {
4072
+ Vote: [
4073
+ { name: 'from', type: 'string' },
4074
+ { name: 'space', type: 'string' },
4075
+ { name: 'timestamp', type: 'uint64' },
4076
+ { name: 'proposal', type: 'bytes32' },
4077
+ { name: 'choice', type: 'uint32' },
4078
+ { name: 'reason', type: 'string' },
4079
+ { name: 'app', type: 'string' },
4080
+ { name: 'metadata', type: 'string' }
4081
+ ]
4082
+ };
4083
+ const voteArray2Types = {
4084
+ Vote: [
4085
+ { name: 'from', type: 'string' },
4086
+ { name: 'space', type: 'string' },
4087
+ { name: 'timestamp', type: 'uint64' },
4088
+ { name: 'proposal', type: 'bytes32' },
4089
+ { name: 'choice', type: 'uint32[]' },
4090
+ { name: 'reason', type: 'string' },
4091
+ { name: 'app', type: 'string' },
4092
+ { name: 'metadata', type: 'string' }
4093
+ ]
4094
+ };
4095
+ const voteString2Types = {
4096
+ Vote: [
4097
+ { name: 'from', type: 'string' },
4098
+ { name: 'space', type: 'string' },
4099
+ { name: 'timestamp', type: 'uint64' },
4100
+ { name: 'proposal', type: 'bytes32' },
4101
+ { name: 'choice', type: 'string' },
4102
+ { name: 'reason', type: 'string' },
4103
+ { name: 'app', type: 'string' },
4104
+ { name: 'metadata', type: 'string' }
4105
+ ]
4106
+ };
4107
+ const followTypes = {
4108
+ Follow: [
4109
+ { name: 'from', type: 'address' },
4110
+ { name: 'network', type: 'string' },
4111
+ { name: 'space', type: 'string' },
4112
+ { name: 'timestamp', type: 'uint64' }
4113
+ ]
4114
+ };
4115
+ const unfollowTypes = {
4116
+ Unfollow: [
4117
+ { name: 'from', type: 'address' },
4118
+ { name: 'network', type: 'string' },
4119
+ { name: 'space', type: 'string' },
4120
+ { name: 'timestamp', type: 'uint64' }
4121
+ ]
4122
+ };
4123
+ const subscribeTypes = {
4124
+ Subscribe: [
4125
+ { name: 'from', type: 'address' },
4126
+ { name: 'space', type: 'string' },
4127
+ { name: 'timestamp', type: 'uint64' }
4128
+ ]
4129
+ };
4130
+ const unsubscribeTypes = {
4131
+ Unsubscribe: [
4132
+ { name: 'from', type: 'address' },
4133
+ { name: 'space', type: 'string' },
4134
+ { name: 'timestamp', type: 'uint64' }
4135
+ ]
4136
+ };
4137
+ const profileTypes = {
4138
+ Profile: [
4139
+ { name: 'from', type: 'address' },
4140
+ { name: 'timestamp', type: 'uint64' },
4141
+ { name: 'profile', type: 'string' }
4142
+ ]
4143
+ };
4144
+ const statementTypes = {
4145
+ Statement: [
4146
+ { name: 'from', type: 'address' },
4147
+ { name: 'timestamp', type: 'uint64' },
4148
+ { name: 'space', type: 'string' },
4149
+ { name: 'about', type: 'string' },
4150
+ { name: 'statement', type: 'string' },
4151
+ { name: 'discourse', type: 'string' },
4152
+ { name: 'status', type: 'string' },
4153
+ { name: 'network', type: 'string' }
4154
+ ]
4155
+ };
4156
+ const aliasTypes = {
4157
+ Alias: [
4158
+ { name: 'from', type: 'address' },
4159
+ { name: 'alias', type: 'address' },
4160
+ { name: 'timestamp', type: 'uint64' }
4161
+ ]
4162
+ };
4163
+ const deleteSpaceType = {
4164
+ DeleteSpace: [
4165
+ { name: 'from', type: 'address' },
4166
+ { name: 'space', type: 'string' },
4167
+ { name: 'timestamp', type: 'uint64' }
4168
+ ]
4169
+ };
4170
+
4171
+ var mainnet = {
4172
+ hub: "https://hub.snapshot.org",
4173
+ sequencer: "https://seq.snapshot.org"
4174
+ };
4175
+ var testnet = {
4176
+ hub: "https://testnet.hub.snapshot.org",
4177
+ sequencer: "https://testnet.seq.snapshot.org"
4178
+ };
4179
+ var local = {
4180
+ hub: "http://localhost:3000",
4181
+ sequencer: "http://localhost:3001"
4182
+ };
4183
+ var constants = {
4184
+ mainnet: mainnet,
4185
+ testnet: testnet,
4186
+ local: local
4187
+ };
4188
+
4116
4189
  const NAME = 'snapshot';
4117
4190
  const VERSION = '0.1.4';
4118
4191
  const domain = {