@snapshot-labs/snapshot.js 0.12.0-beta.0 → 0.12.0-beta.2

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.
Files changed (56) hide show
  1. package/README.md +2 -2
  2. package/dist/index.d.ts +20 -2
  3. package/dist/schemas/index.d.ts +19 -1
  4. package/dist/sign/types.d.ts +2 -0
  5. package/dist/snapshot.cjs.js +1851 -1929
  6. package/dist/snapshot.esm.js +1852 -1930
  7. package/dist/snapshot.min.js +16 -5
  8. package/dist/src/index.d.ts +725 -0
  9. package/dist/src/schemas/index.d.ts +671 -0
  10. package/dist/src/sign/index.d.ts +29 -0
  11. package/dist/src/sign/types.d.ts +227 -0
  12. package/dist/src/utils/blockfinder.d.ts +1 -0
  13. package/dist/src/utils/delegation.d.ts +18 -0
  14. package/dist/src/utils/multicaller.d.ts +12 -0
  15. package/dist/src/utils/provider.d.ts +5 -0
  16. package/dist/src/utils/web3.d.ts +2 -0
  17. package/dist/src/utils.d.ts +91 -0
  18. package/dist/src/verify/evm.d.ts +4 -0
  19. package/dist/src/verify/evm.spec.d.ts +1 -0
  20. package/dist/src/verify/index.d.ts +11 -0
  21. package/dist/src/verify/index.spec.d.ts +1 -0
  22. package/dist/src/verify/starknet.d.ts +6 -0
  23. package/dist/src/verify/starknet.spec.d.ts +1 -0
  24. package/dist/src/voting/approval.d.ts +22 -0
  25. package/dist/src/voting/index.d.ts +14 -0
  26. package/dist/src/voting/quadratic.d.ts +20 -0
  27. package/dist/src/voting/rankedChoice.d.ts +18 -0
  28. package/dist/src/voting/singleChoice.d.ts +18 -0
  29. package/dist/src/voting/types.d.ts +35 -0
  30. package/dist/src/voting/weighted.d.ts +26 -0
  31. package/dist/utils/delegation.d.ts +1 -1
  32. package/dist/utils.d.ts +3 -2
  33. package/package.json +6 -3
  34. package/src/delegationSubgraphs.json +8 -8
  35. package/src/gateways.json +1 -2
  36. package/src/networks.json +222 -60
  37. package/src/schemas/profile.json +30 -0
  38. package/src/schemas/proposal.json +1 -1
  39. package/src/schemas/space.json +8 -7
  40. package/src/schemas/statement.json +17 -2
  41. package/src/schemas/vote.json +1 -1
  42. package/src/sign/hashedTypes.json +8 -1
  43. package/src/sign/index.ts +8 -6
  44. package/src/sign/types.ts +11 -1
  45. package/src/utils/provider.ts +8 -2
  46. package/src/utils/web3.ts +1 -1
  47. package/src/utils.spec.js +86 -31
  48. package/src/utils.ts +111 -38
  49. package/src/verify/evm.spec.ts +32 -0
  50. package/src/verify/evm.ts +82 -0
  51. package/src/verify/index.spec.ts +84 -0
  52. package/src/verify/index.ts +41 -0
  53. package/src/verify/starknet.spec.ts +55 -0
  54. package/src/verify/starknet.ts +82 -0
  55. package/src/sign/eip1271.ts +0 -55
  56. package/src/sign/utils.ts +0 -27
@@ -13,6 +13,7 @@ var addErrors = require('ajv-errors');
13
13
  var set = require('lodash.set');
14
14
  var providers$1 = require('@ethersproject/providers');
15
15
  var bytes = require('@ethersproject/bytes');
16
+ var starknet$1 = require('starknet');
16
17
  var wallet = require('@ethersproject/wallet');
17
18
 
18
19
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -38,17 +39,6 @@ See the Apache Version 2.0 License for specific language governing permissions
38
39
  and limitations under the License.
39
40
  ***************************************************************************** */
40
41
 
41
- var __assign = function() {
42
- __assign = Object.assign || function __assign(t) {
43
- for (var s, i = 1, n = arguments.length; i < n; i++) {
44
- s = arguments[i];
45
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
46
- }
47
- return t;
48
- };
49
- return __assign.apply(this, arguments);
50
- };
51
-
52
42
  function __rest(s, e) {
53
43
  var t = {};
54
44
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -69,251 +59,205 @@ function __awaiter(thisArg, _arguments, P, generator) {
69
59
  function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
70
60
  step((generator = generator.apply(thisArg, _arguments || [])).next());
71
61
  });
72
- }
73
-
74
- function __generator(thisArg, body) {
75
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
76
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
77
- function verb(n) { return function (v) { return step([n, v]); }; }
78
- function step(op) {
79
- if (f) throw new TypeError("Generator is already executing.");
80
- while (_) try {
81
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
82
- if (y = 0, t) op = [op[0] & 2, t.value];
83
- switch (op[0]) {
84
- case 0: case 1: t = op; break;
85
- case 4: _.label++; return { value: op[1], done: false };
86
- case 5: _.label++; y = op[1]; op = [0]; continue;
87
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
88
- default:
89
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
90
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
91
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
92
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
93
- if (t[2]) _.ops.pop();
94
- _.trys.pop(); continue;
95
- }
96
- op = body.call(thisArg, _);
97
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
98
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
99
- }
100
- }
101
-
102
- function __read(o, n) {
103
- var m = typeof Symbol === "function" && o[Symbol.iterator];
104
- if (!m) return o;
105
- var i = m.call(o), r, ar = [], e;
106
- try {
107
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
108
- }
109
- catch (error) { e = { error: error }; }
110
- finally {
111
- try {
112
- if (r && !r.done && (m = i["return"])) m.call(i);
113
- }
114
- finally { if (e) throw e.error; }
115
- }
116
- return ar;
117
- }
118
-
119
- function __spread() {
120
- for (var ar = [], i = 0; i < arguments.length; i++)
121
- ar = ar.concat(__read(arguments[i]));
122
- return ar;
123
62
  }
124
63
 
125
- var spaceTypes = {
126
- Space: [
127
- { name: 'from', type: 'address' },
128
- { name: 'space', type: 'string' },
129
- { name: 'timestamp', type: 'uint64' },
130
- { name: 'settings', type: 'string' }
131
- ]
132
- };
133
- var proposalTypes = {
134
- Proposal: [
135
- { name: 'from', type: 'address' },
136
- { name: 'space', type: 'string' },
137
- { name: 'timestamp', type: 'uint64' },
138
- { name: 'type', type: 'string' },
139
- { name: 'title', type: 'string' },
140
- { name: 'body', type: 'string' },
141
- { name: 'discussion', type: 'string' },
142
- { name: 'choices', type: 'string[]' },
143
- { name: 'start', type: 'uint64' },
144
- { name: 'end', type: 'uint64' },
145
- { name: 'snapshot', type: 'uint64' },
146
- { name: 'plugins', type: 'string' },
147
- { name: 'app', type: 'string' }
148
- ]
149
- };
150
- var updateProposalTypes = {
151
- UpdateProposal: [
152
- { name: 'proposal', type: 'string' },
153
- { name: 'from', type: 'address' },
154
- { name: 'space', type: 'string' },
155
- { name: 'timestamp', type: 'uint64' },
156
- { name: 'type', type: 'string' },
157
- { name: 'title', type: 'string' },
158
- { name: 'body', type: 'string' },
159
- { name: 'discussion', type: 'string' },
160
- { name: 'choices', type: 'string[]' },
161
- { name: 'plugins', type: 'string' }
162
- ]
163
- };
164
- var flagProposalTypes = {
165
- FlagProposal: [
166
- { name: 'from', type: 'address' },
167
- { name: 'space', type: 'string' },
168
- { name: 'proposal', type: 'string' },
169
- { name: 'timestamp', type: 'uint64' }
170
- ]
171
- };
172
- var cancelProposalTypes = {
173
- CancelProposal: [
174
- { name: 'from', type: 'address' },
175
- { name: 'space', type: 'string' },
176
- { name: 'timestamp', type: 'uint64' },
177
- { name: 'proposal', type: 'string' }
178
- ]
179
- };
180
- var cancelProposal2Types = {
181
- CancelProposal: [
182
- { name: 'from', type: 'address' },
183
- { name: 'space', type: 'string' },
184
- { name: 'timestamp', type: 'uint64' },
185
- { name: 'proposal', type: 'bytes32' }
186
- ]
187
- };
188
- var voteTypes = {
189
- Vote: [
190
- { name: 'from', type: 'address' },
191
- { name: 'space', type: 'string' },
192
- { name: 'timestamp', type: 'uint64' },
193
- { name: 'proposal', type: 'string' },
194
- { name: 'choice', type: 'uint32' },
195
- { name: 'reason', type: 'string' },
196
- { name: 'app', type: 'string' },
197
- { name: 'metadata', type: 'string' }
198
- ]
199
- };
200
- var voteArrayTypes = {
201
- Vote: [
202
- { name: 'from', type: 'address' },
203
- { name: 'space', type: 'string' },
204
- { name: 'timestamp', type: 'uint64' },
205
- { name: 'proposal', type: 'string' },
206
- { name: 'choice', type: 'uint32[]' },
207
- { name: 'reason', type: 'string' },
208
- { name: 'app', type: 'string' },
209
- { name: 'metadata', type: 'string' }
210
- ]
211
- };
212
- var voteStringTypes = {
213
- Vote: [
214
- { name: 'from', type: 'address' },
215
- { name: 'space', type: 'string' },
216
- { name: 'timestamp', type: 'uint64' },
217
- { name: 'proposal', type: 'string' },
218
- { name: 'choice', type: 'string' },
219
- { name: 'reason', type: 'string' },
220
- { name: 'app', type: 'string' },
221
- { name: 'metadata', type: 'string' }
222
- ]
223
- };
224
- var vote2Types = {
225
- Vote: [
226
- { name: 'from', type: 'address' },
227
- { name: 'space', type: 'string' },
228
- { name: 'timestamp', type: 'uint64' },
229
- { name: 'proposal', type: 'bytes32' },
230
- { name: 'choice', type: 'uint32' },
231
- { name: 'reason', type: 'string' },
232
- { name: 'app', type: 'string' },
233
- { name: 'metadata', type: 'string' }
234
- ]
235
- };
236
- var voteArray2Types = {
237
- Vote: [
238
- { name: 'from', type: 'address' },
239
- { name: 'space', type: 'string' },
240
- { name: 'timestamp', type: 'uint64' },
241
- { name: 'proposal', type: 'bytes32' },
242
- { name: 'choice', type: 'uint32[]' },
243
- { name: 'reason', type: 'string' },
244
- { name: 'app', type: 'string' },
245
- { name: 'metadata', type: 'string' }
246
- ]
247
- };
248
- var voteString2Types = {
249
- Vote: [
250
- { name: 'from', type: 'address' },
251
- { name: 'space', type: 'string' },
252
- { name: 'timestamp', type: 'uint64' },
253
- { name: 'proposal', type: 'bytes32' },
254
- { name: 'choice', type: 'string' },
255
- { name: 'reason', type: 'string' },
256
- { name: 'app', type: 'string' },
257
- { name: 'metadata', type: 'string' }
258
- ]
259
- };
260
- var followTypes = {
261
- Follow: [
262
- { name: 'from', type: 'address' },
263
- { name: 'space', type: 'string' },
264
- { name: 'timestamp', type: 'uint64' }
265
- ]
266
- };
267
- var unfollowTypes = {
268
- Unfollow: [
269
- { name: 'from', type: 'address' },
270
- { name: 'space', type: 'string' },
271
- { name: 'timestamp', type: 'uint64' }
272
- ]
273
- };
274
- var subscribeTypes = {
275
- Subscribe: [
276
- { name: 'from', type: 'address' },
277
- { name: 'space', type: 'string' },
278
- { name: 'timestamp', type: 'uint64' }
279
- ]
280
- };
281
- var unsubscribeTypes = {
282
- Unsubscribe: [
283
- { name: 'from', type: 'address' },
284
- { name: 'space', type: 'string' },
285
- { name: 'timestamp', type: 'uint64' }
286
- ]
287
- };
288
- var profileTypes = {
289
- Profile: [
290
- { name: 'from', type: 'address' },
291
- { name: 'timestamp', type: 'uint64' },
292
- { name: 'profile', type: 'string' }
293
- ]
294
- };
295
- var statementTypes = {
296
- Statement: [
297
- { name: 'from', type: 'address' },
298
- { name: 'timestamp', type: 'uint64' },
299
- { name: 'space', type: 'string' },
300
- { name: 'about', type: 'string' },
301
- { name: 'statement', type: 'string' }
302
- ]
303
- };
304
- var aliasTypes = {
305
- Alias: [
306
- { name: 'from', type: 'address' },
307
- { name: 'alias', type: 'address' },
308
- { name: 'timestamp', type: 'uint64' }
309
- ]
310
- };
311
- var deleteSpaceType = {
312
- DeleteSpace: [
313
- { name: 'from', type: 'address' },
314
- { name: 'space', type: 'string' },
315
- { name: 'timestamp', type: 'uint64' }
316
- ]
64
+ const spaceTypes = {
65
+ Space: [
66
+ { name: 'from', type: 'address' },
67
+ { name: 'space', type: 'string' },
68
+ { name: 'timestamp', type: 'uint64' },
69
+ { name: 'settings', type: 'string' }
70
+ ]
71
+ };
72
+ const proposalTypes = {
73
+ Proposal: [
74
+ { name: 'from', type: 'address' },
75
+ { name: 'space', type: 'string' },
76
+ { name: 'timestamp', type: 'uint64' },
77
+ { name: 'type', type: 'string' },
78
+ { name: 'title', type: 'string' },
79
+ { name: 'body', type: 'string' },
80
+ { name: 'discussion', type: 'string' },
81
+ { name: 'choices', type: 'string[]' },
82
+ { name: 'start', type: 'uint64' },
83
+ { name: 'end', type: 'uint64' },
84
+ { name: 'snapshot', type: 'uint64' },
85
+ { name: 'plugins', type: 'string' },
86
+ { name: 'app', type: 'string' }
87
+ ]
88
+ };
89
+ const updateProposalTypes = {
90
+ UpdateProposal: [
91
+ { name: 'proposal', type: 'string' },
92
+ { name: 'from', type: 'address' },
93
+ { name: 'space', type: 'string' },
94
+ { name: 'timestamp', type: 'uint64' },
95
+ { name: 'type', type: 'string' },
96
+ { name: 'title', type: 'string' },
97
+ { name: 'body', type: 'string' },
98
+ { name: 'discussion', type: 'string' },
99
+ { name: 'choices', type: 'string[]' },
100
+ { name: 'plugins', type: 'string' }
101
+ ]
102
+ };
103
+ const flagProposalTypes = {
104
+ FlagProposal: [
105
+ { name: 'from', type: 'address' },
106
+ { name: 'space', type: 'string' },
107
+ { name: 'proposal', type: 'string' },
108
+ { name: 'timestamp', type: 'uint64' }
109
+ ]
110
+ };
111
+ const cancelProposalTypes = {
112
+ CancelProposal: [
113
+ { name: 'from', type: 'address' },
114
+ { name: 'space', type: 'string' },
115
+ { name: 'timestamp', type: 'uint64' },
116
+ { name: 'proposal', type: 'string' }
117
+ ]
118
+ };
119
+ const cancelProposal2Types = {
120
+ CancelProposal: [
121
+ { name: 'from', type: 'address' },
122
+ { name: 'space', type: 'string' },
123
+ { name: 'timestamp', type: 'uint64' },
124
+ { name: 'proposal', type: 'bytes32' }
125
+ ]
126
+ };
127
+ const voteTypes = {
128
+ Vote: [
129
+ { name: 'from', type: 'address' },
130
+ { name: 'space', type: 'string' },
131
+ { name: 'timestamp', type: 'uint64' },
132
+ { name: 'proposal', type: 'string' },
133
+ { name: 'choice', type: 'uint32' },
134
+ { name: 'reason', type: 'string' },
135
+ { name: 'app', type: 'string' },
136
+ { name: 'metadata', type: 'string' }
137
+ ]
138
+ };
139
+ const voteArrayTypes = {
140
+ Vote: [
141
+ { name: 'from', type: 'address' },
142
+ { name: 'space', type: 'string' },
143
+ { name: 'timestamp', type: 'uint64' },
144
+ { name: 'proposal', type: 'string' },
145
+ { name: 'choice', type: 'uint32[]' },
146
+ { name: 'reason', type: 'string' },
147
+ { name: 'app', type: 'string' },
148
+ { name: 'metadata', type: 'string' }
149
+ ]
150
+ };
151
+ const voteStringTypes = {
152
+ Vote: [
153
+ { name: 'from', type: 'address' },
154
+ { name: 'space', type: 'string' },
155
+ { name: 'timestamp', type: 'uint64' },
156
+ { name: 'proposal', type: 'string' },
157
+ { name: 'choice', type: 'string' },
158
+ { name: 'reason', type: 'string' },
159
+ { name: 'app', type: 'string' },
160
+ { name: 'metadata', type: 'string' }
161
+ ]
162
+ };
163
+ const vote2Types = {
164
+ Vote: [
165
+ { name: 'from', type: 'address' },
166
+ { name: 'space', type: 'string' },
167
+ { name: 'timestamp', type: 'uint64' },
168
+ { name: 'proposal', type: 'bytes32' },
169
+ { name: 'choice', type: 'uint32' },
170
+ { name: 'reason', type: 'string' },
171
+ { name: 'app', type: 'string' },
172
+ { name: 'metadata', type: 'string' }
173
+ ]
174
+ };
175
+ const voteArray2Types = {
176
+ Vote: [
177
+ { name: 'from', type: 'address' },
178
+ { name: 'space', type: 'string' },
179
+ { name: 'timestamp', type: 'uint64' },
180
+ { name: 'proposal', type: 'bytes32' },
181
+ { name: 'choice', type: 'uint32[]' },
182
+ { name: 'reason', type: 'string' },
183
+ { name: 'app', type: 'string' },
184
+ { name: 'metadata', type: 'string' }
185
+ ]
186
+ };
187
+ const voteString2Types = {
188
+ Vote: [
189
+ { name: 'from', type: 'address' },
190
+ { name: 'space', type: 'string' },
191
+ { name: 'timestamp', type: 'uint64' },
192
+ { name: 'proposal', type: 'bytes32' },
193
+ { name: 'choice', type: 'string' },
194
+ { name: 'reason', type: 'string' },
195
+ { name: 'app', type: 'string' },
196
+ { name: 'metadata', type: 'string' }
197
+ ]
198
+ };
199
+ const followTypes = {
200
+ Follow: [
201
+ { name: 'from', type: 'address' },
202
+ { name: 'network', type: 'string' },
203
+ { name: 'space', type: 'string' },
204
+ { name: 'timestamp', type: 'uint64' }
205
+ ]
206
+ };
207
+ const unfollowTypes = {
208
+ Unfollow: [
209
+ { name: 'from', type: 'address' },
210
+ { name: 'network', type: 'string' },
211
+ { name: 'space', type: 'string' },
212
+ { name: 'timestamp', type: 'uint64' }
213
+ ]
214
+ };
215
+ const subscribeTypes = {
216
+ Subscribe: [
217
+ { name: 'from', type: 'address' },
218
+ { name: 'space', type: 'string' },
219
+ { name: 'timestamp', type: 'uint64' }
220
+ ]
221
+ };
222
+ const unsubscribeTypes = {
223
+ Unsubscribe: [
224
+ { name: 'from', type: 'address' },
225
+ { name: 'space', type: 'string' },
226
+ { name: 'timestamp', type: 'uint64' }
227
+ ]
228
+ };
229
+ const profileTypes = {
230
+ Profile: [
231
+ { name: 'from', type: 'address' },
232
+ { name: 'timestamp', type: 'uint64' },
233
+ { name: 'profile', type: 'string' }
234
+ ]
235
+ };
236
+ const statementTypes = {
237
+ Statement: [
238
+ { name: 'from', type: 'address' },
239
+ { name: 'timestamp', type: 'uint64' },
240
+ { name: 'space', type: 'string' },
241
+ { name: 'about', type: 'string' },
242
+ { name: 'statement', type: 'string' },
243
+ { name: 'discourse', type: 'string' },
244
+ { name: 'status', type: 'string' },
245
+ { name: 'network', type: 'string' }
246
+ ]
247
+ };
248
+ const aliasTypes = {
249
+ Alias: [
250
+ { name: 'from', type: 'address' },
251
+ { name: 'alias', type: 'address' },
252
+ { name: 'timestamp', type: 'uint64' }
253
+ ]
254
+ };
255
+ const deleteSpaceType = {
256
+ DeleteSpace: [
257
+ { name: 'from', type: 'address' },
258
+ { name: 'space', type: 'string' },
259
+ { name: 'timestamp', type: 'uint64' }
260
+ ]
317
261
  };
318
262
 
319
263
  var livenet = {
@@ -334,252 +278,163 @@ var constants = {
334
278
  local: local
335
279
  };
336
280
 
337
- var NAME = 'snapshot';
338
- var VERSION = '0.1.4';
339
- var domain = {
340
- name: NAME,
341
- version: VERSION
342
- // chainId: 1
343
- };
344
- var Client = /** @class */ (function () {
345
- function Client(address, options) {
346
- if (address === void 0) { address = constants.livenet.sequencer; }
347
- if (options === void 0) { options = {}; }
348
- address = address.replace(constants.livenet.hub, constants.livenet.sequencer);
349
- address = address.replace(constants.testnet.hub, constants.testnet.sequencer);
350
- address = address.replace(constants.local.hub, constants.local.sequencer);
351
- this.address = address;
352
- this.options = options;
353
- }
354
- Client.prototype.sign = function (web3, address$1, message, types) {
355
- var _a;
356
- return __awaiter(this, void 0, void 0, function () {
357
- var signer, checksumAddress, domainData, _b, data, sig;
358
- return __generator(this, function (_c) {
359
- switch (_c.label) {
360
- case 0:
361
- signer = (web3 === null || web3 === void 0 ? void 0 : web3.getSigner) ? web3.getSigner() : web3;
362
- checksumAddress = address.getAddress(address$1);
363
- message.from = message.from ? address.getAddress(message.from) : checksumAddress;
364
- if (!message.timestamp)
365
- message.timestamp = parseInt((Date.now() / 1e3).toFixed());
366
- domainData = __assign({}, domain);
367
- if (!((_a = window === null || window === void 0 ? void 0 : window.ethereum) === null || _a === void 0 ? void 0 : _a.isTrust)) return [3 /*break*/, 2];
368
- _b = domainData;
369
- return [4 /*yield*/, signer.provider.getNetwork()];
370
- case 1:
371
- _b.chainId = (_c.sent()).chainId;
372
- _c.label = 2;
373
- case 2:
374
- data = { domain: domainData, types: types, message: message };
375
- return [4 /*yield*/, signer._signTypedData(domainData, data.types, message)];
376
- case 3:
377
- sig = _c.sent();
378
- return [4 /*yield*/, this.send({ address: checksumAddress, sig: sig, data: data })];
379
- case 4: return [2 /*return*/, _c.sent()];
380
- }
381
- });
382
- });
383
- };
384
- Client.prototype.send = function (envelop) {
385
- return __awaiter(this, void 0, void 0, function () {
386
- var address, init;
387
- return __generator(this, function (_a) {
388
- address = this.address;
389
- if (envelop.sig === '0x' && this.options.relayerURL)
390
- address = this.options.relayerURL;
391
- init = {
392
- method: 'POST',
393
- headers: {
394
- Accept: 'application/json',
395
- 'Content-Type': 'application/json'
396
- },
397
- body: JSON.stringify(envelop)
398
- };
399
- return [2 /*return*/, new Promise(function (resolve, reject) {
400
- fetch__default['default'](address, init)
401
- .then(function (res) {
402
- if (res.ok)
403
- return resolve(res.json());
404
- throw res;
405
- })
406
- .catch(function (e) { return reject(e); });
407
- })];
408
- });
409
- });
410
- };
411
- Client.prototype.space = function (web3, address, message) {
412
- return __awaiter(this, void 0, void 0, function () {
413
- return __generator(this, function (_a) {
414
- switch (_a.label) {
415
- case 0: return [4 /*yield*/, this.sign(web3, address, message, spaceTypes)];
416
- case 1: return [2 /*return*/, _a.sent()];
417
- }
418
- });
419
- });
420
- };
421
- Client.prototype.proposal = function (web3, address, message) {
422
- return __awaiter(this, void 0, void 0, function () {
423
- return __generator(this, function (_a) {
424
- switch (_a.label) {
425
- case 0:
426
- if (!message.discussion)
427
- message.discussion = '';
428
- if (!message.app)
429
- message.app = '';
430
- return [4 /*yield*/, this.sign(web3, address, message, proposalTypes)];
431
- case 1: return [2 /*return*/, _a.sent()];
432
- }
433
- });
434
- });
435
- };
436
- Client.prototype.updateProposal = function (web3, address, message) {
437
- return __awaiter(this, void 0, void 0, function () {
438
- return __generator(this, function (_a) {
439
- switch (_a.label) {
440
- case 0: return [4 /*yield*/, this.sign(web3, address, message, updateProposalTypes)];
441
- case 1: return [2 /*return*/, _a.sent()];
442
- }
443
- });
444
- });
445
- };
446
- Client.prototype.flagProposal = function (web3, address, message) {
447
- return __awaiter(this, void 0, void 0, function () {
448
- return __generator(this, function (_a) {
449
- switch (_a.label) {
450
- case 0: return [4 /*yield*/, this.sign(web3, address, message, flagProposalTypes)];
451
- case 1: return [2 /*return*/, _a.sent()];
452
- }
453
- });
454
- });
455
- };
456
- Client.prototype.cancelProposal = function (web3, address, message) {
457
- return __awaiter(this, void 0, void 0, function () {
458
- var type2;
459
- return __generator(this, function (_a) {
460
- switch (_a.label) {
461
- case 0:
462
- type2 = message.proposal.startsWith('0x');
463
- return [4 /*yield*/, this.sign(web3, address, message, type2 ? cancelProposal2Types : cancelProposalTypes)];
464
- case 1: return [2 /*return*/, _a.sent()];
465
- }
466
- });
467
- });
468
- };
469
- Client.prototype.vote = function (web3, address, message) {
470
- return __awaiter(this, void 0, void 0, function () {
471
- var isShutter, type2, type;
472
- return __generator(this, function (_a) {
473
- switch (_a.label) {
474
- case 0:
475
- isShutter = (message === null || message === void 0 ? void 0 : message.privacy) === 'shutter';
476
- if (!message.reason)
477
- message.reason = '';
478
- if (!message.app)
479
- message.app = '';
480
- if (!message.metadata)
481
- message.metadata = '{}';
482
- type2 = message.proposal.startsWith('0x');
483
- type = type2 ? vote2Types : voteTypes;
484
- if (['approval', 'ranked-choice'].includes(message.type))
485
- type = type2 ? voteArray2Types : voteArrayTypes;
486
- if (!isShutter && ['quadratic', 'weighted'].includes(message.type)) {
487
- type = type2 ? voteString2Types : voteStringTypes;
488
- message.choice = JSON.stringify(message.choice);
489
- }
490
- if (isShutter)
491
- type = type2 ? voteString2Types : voteStringTypes;
492
- delete message.privacy;
493
- // @ts-ignore
494
- delete message.type;
495
- return [4 /*yield*/, this.sign(web3, address, message, type)];
496
- case 1: return [2 /*return*/, _a.sent()];
497
- }
498
- });
499
- });
500
- };
501
- Client.prototype.follow = function (web3, address, message) {
502
- return __awaiter(this, void 0, void 0, function () {
503
- return __generator(this, function (_a) {
504
- switch (_a.label) {
505
- case 0: return [4 /*yield*/, this.sign(web3, address, message, followTypes)];
506
- case 1: return [2 /*return*/, _a.sent()];
507
- }
508
- });
509
- });
510
- };
511
- Client.prototype.unfollow = function (web3, address, message) {
512
- return __awaiter(this, void 0, void 0, function () {
513
- return __generator(this, function (_a) {
514
- switch (_a.label) {
515
- case 0: return [4 /*yield*/, this.sign(web3, address, message, unfollowTypes)];
516
- case 1: return [2 /*return*/, _a.sent()];
517
- }
518
- });
519
- });
520
- };
521
- Client.prototype.subscribe = function (web3, address, message) {
522
- return __awaiter(this, void 0, void 0, function () {
523
- return __generator(this, function (_a) {
524
- switch (_a.label) {
525
- case 0: return [4 /*yield*/, this.sign(web3, address, message, subscribeTypes)];
526
- case 1: return [2 /*return*/, _a.sent()];
527
- }
528
- });
529
- });
530
- };
531
- Client.prototype.unsubscribe = function (web3, address, message) {
532
- return __awaiter(this, void 0, void 0, function () {
533
- return __generator(this, function (_a) {
534
- switch (_a.label) {
535
- case 0: return [4 /*yield*/, this.sign(web3, address, message, unsubscribeTypes)];
536
- case 1: return [2 /*return*/, _a.sent()];
537
- }
538
- });
539
- });
540
- };
541
- Client.prototype.profile = function (web3, address, message) {
542
- return __awaiter(this, void 0, void 0, function () {
543
- return __generator(this, function (_a) {
544
- switch (_a.label) {
545
- case 0: return [4 /*yield*/, this.sign(web3, address, message, profileTypes)];
546
- case 1: return [2 /*return*/, _a.sent()];
547
- }
548
- });
549
- });
550
- };
551
- Client.prototype.statement = function (web3, address, message) {
552
- return __awaiter(this, void 0, void 0, function () {
553
- return __generator(this, function (_a) {
554
- switch (_a.label) {
555
- case 0: return [4 /*yield*/, this.sign(web3, address, message, statementTypes)];
556
- case 1: return [2 /*return*/, _a.sent()];
557
- }
558
- });
559
- });
560
- };
561
- Client.prototype.alias = function (web3, address, message) {
562
- return __awaiter(this, void 0, void 0, function () {
563
- return __generator(this, function (_a) {
564
- switch (_a.label) {
565
- case 0: return [4 /*yield*/, this.sign(web3, address, message, aliasTypes)];
566
- case 1: return [2 /*return*/, _a.sent()];
567
- }
568
- });
569
- });
570
- };
571
- Client.prototype.deleteSpace = function (web3, address, message) {
572
- return __awaiter(this, void 0, void 0, function () {
573
- return __generator(this, function (_a) {
574
- switch (_a.label) {
575
- case 0: return [4 /*yield*/, this.sign(web3, address, message, deleteSpaceType)];
576
- case 1: return [2 /*return*/, _a.sent()];
577
- }
578
- });
579
- });
580
- };
581
- return Client;
582
- }());
281
+ const NAME = 'snapshot';
282
+ const VERSION = '0.1.4';
283
+ const domain = {
284
+ name: NAME,
285
+ version: VERSION
286
+ // chainId: 1
287
+ };
288
+ class Client {
289
+ constructor(address = constants.livenet.sequencer, options = {}) {
290
+ address = address.replace(constants.livenet.hub, constants.livenet.sequencer);
291
+ address = address.replace(constants.testnet.hub, constants.testnet.sequencer);
292
+ address = address.replace(constants.local.hub, constants.local.sequencer);
293
+ this.address = address;
294
+ this.options = options;
295
+ }
296
+ sign(web3, address$1, message, types) {
297
+ return __awaiter(this, void 0, void 0, function* () {
298
+ var _a;
299
+ // @ts-ignore
300
+ const signer = (web3 === null || web3 === void 0 ? void 0 : web3.getSigner) ? web3.getSigner() : web3;
301
+ const checksumAddress = address.getAddress(address$1);
302
+ message.from = message.from ? address.getAddress(message.from) : checksumAddress;
303
+ if (!message.timestamp)
304
+ message.timestamp = parseInt((Date.now() / 1e3).toFixed());
305
+ const domainData = Object.assign({}, domain);
306
+ // @ts-ignore
307
+ if (typeof window !== 'undefined' && ((_a = window.ethereum) === null || _a === void 0 ? void 0 : _a.isTrust)) {
308
+ domainData.chainId = (yield signer.provider.getNetwork()).chainId;
309
+ }
310
+ const data = { domain: domainData, types, message };
311
+ const sig = yield signer._signTypedData(domainData, data.types, message);
312
+ return yield this.send({ address: checksumAddress, sig, data });
313
+ });
314
+ }
315
+ send(envelop) {
316
+ return __awaiter(this, void 0, void 0, function* () {
317
+ let address = this.address;
318
+ if (envelop.sig === '0x' && this.options.relayerURL)
319
+ address = this.options.relayerURL;
320
+ const init = {
321
+ method: 'POST',
322
+ headers: {
323
+ Accept: 'application/json',
324
+ 'Content-Type': 'application/json'
325
+ },
326
+ body: JSON.stringify(envelop)
327
+ };
328
+ return new Promise((resolve, reject) => {
329
+ fetch__default['default'](address, init)
330
+ .then((res) => {
331
+ var _a;
332
+ if (res.ok)
333
+ return resolve(res.json());
334
+ if ((_a = res.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.includes('application/json'))
335
+ return res.json().then(reject).catch(reject);
336
+ throw res;
337
+ })
338
+ .catch(reject);
339
+ });
340
+ });
341
+ }
342
+ space(web3, address, message) {
343
+ return __awaiter(this, void 0, void 0, function* () {
344
+ return yield this.sign(web3, address, message, spaceTypes);
345
+ });
346
+ }
347
+ proposal(web3, address, message) {
348
+ return __awaiter(this, void 0, void 0, function* () {
349
+ if (!message.discussion)
350
+ message.discussion = '';
351
+ if (!message.app)
352
+ message.app = '';
353
+ return yield this.sign(web3, address, message, proposalTypes);
354
+ });
355
+ }
356
+ updateProposal(web3, address, message) {
357
+ return __awaiter(this, void 0, void 0, function* () {
358
+ return yield this.sign(web3, address, message, updateProposalTypes);
359
+ });
360
+ }
361
+ flagProposal(web3, address, message) {
362
+ return __awaiter(this, void 0, void 0, function* () {
363
+ return yield this.sign(web3, address, message, flagProposalTypes);
364
+ });
365
+ }
366
+ cancelProposal(web3, address, message) {
367
+ return __awaiter(this, void 0, void 0, function* () {
368
+ const type2 = message.proposal.startsWith('0x');
369
+ return yield this.sign(web3, address, message, type2 ? cancelProposal2Types : cancelProposalTypes);
370
+ });
371
+ }
372
+ vote(web3, address, message) {
373
+ return __awaiter(this, void 0, void 0, function* () {
374
+ const isShutter = (message === null || message === void 0 ? void 0 : message.privacy) === 'shutter';
375
+ if (!message.reason)
376
+ message.reason = '';
377
+ if (!message.app)
378
+ message.app = '';
379
+ if (!message.metadata)
380
+ message.metadata = '{}';
381
+ const type2 = message.proposal.startsWith('0x');
382
+ let type = type2 ? vote2Types : voteTypes;
383
+ if (['approval', 'ranked-choice'].includes(message.type))
384
+ type = type2 ? voteArray2Types : voteArrayTypes;
385
+ if (!isShutter && ['quadratic', 'weighted'].includes(message.type)) {
386
+ type = type2 ? voteString2Types : voteStringTypes;
387
+ message.choice = JSON.stringify(message.choice);
388
+ }
389
+ if (isShutter)
390
+ type = type2 ? voteString2Types : voteStringTypes;
391
+ delete message.privacy;
392
+ // @ts-ignore
393
+ delete message.type;
394
+ return yield this.sign(web3, address, message, type);
395
+ });
396
+ }
397
+ follow(web3, address, message) {
398
+ return __awaiter(this, void 0, void 0, function* () {
399
+ return yield this.sign(web3, address, message, followTypes);
400
+ });
401
+ }
402
+ unfollow(web3, address, message) {
403
+ return __awaiter(this, void 0, void 0, function* () {
404
+ return yield this.sign(web3, address, message, unfollowTypes);
405
+ });
406
+ }
407
+ subscribe(web3, address, message) {
408
+ return __awaiter(this, void 0, void 0, function* () {
409
+ return yield this.sign(web3, address, message, subscribeTypes);
410
+ });
411
+ }
412
+ unsubscribe(web3, address, message) {
413
+ return __awaiter(this, void 0, void 0, function* () {
414
+ return yield this.sign(web3, address, message, unsubscribeTypes);
415
+ });
416
+ }
417
+ profile(web3, address, message) {
418
+ return __awaiter(this, void 0, void 0, function* () {
419
+ return yield this.sign(web3, address, message, profileTypes);
420
+ });
421
+ }
422
+ statement(web3, address, message) {
423
+ return __awaiter(this, void 0, void 0, function* () {
424
+ return yield this.sign(web3, address, message, statementTypes);
425
+ });
426
+ }
427
+ alias(web3, address, message) {
428
+ return __awaiter(this, void 0, void 0, function* () {
429
+ return yield this.sign(web3, address, message, aliasTypes);
430
+ });
431
+ }
432
+ deleteSpace(web3, address, message) {
433
+ return __awaiter(this, void 0, void 0, function* () {
434
+ return yield this.sign(web3, address, message, deleteSpaceType);
435
+ });
436
+ }
437
+ }
583
438
 
584
439
  var $schema = "http://json-schema.org/draft-07/schema#";
585
440
  var $ref = "#/definitions/Space";
@@ -841,6 +696,10 @@ var definitions = {
841
696
  {
842
697
  "const": "compound-governor",
843
698
  title: "Compound governor"
699
+ },
700
+ {
701
+ "const": "split-delegation",
702
+ title: "Split Delegation"
844
703
  }
845
704
  ]
846
705
  },
@@ -859,7 +718,7 @@ var definitions = {
859
718
  title: "Delegation API",
860
719
  description: "The URL of your delegation API (e.g a subgraph)",
861
720
  examples: [
862
- "https://api.thegraph.com/subgraphs/name/arr00/uniswap-governance-v2"
721
+ "https://subgrapher.snapshot.org/subgraph/arbitrum/FTzC6VrZd8JhJgWfTJnwWgH1Z1dS3GxaosKkRbCqkZAZ"
863
722
  ]
864
723
  }
865
724
  },
@@ -901,13 +760,12 @@ var definitions = {
901
760
  },
902
761
  quorum: {
903
762
  type: "number",
904
- minimum: 0,
905
- optimisticMinimum: 1
763
+ minimum: 0
906
764
  },
907
765
  quorumType: {
908
766
  type: "string",
909
767
  "enum": [
910
- "optimistic"
768
+ "rejection"
911
769
  ]
912
770
  },
913
771
  blind: {
@@ -992,11 +850,12 @@ var definitions = {
992
850
  },
993
851
  children: {
994
852
  type: "array",
995
- maxItems: 8,
853
+ maxItems: 16,
996
854
  title: "children",
997
855
  items: {
998
856
  type: "string"
999
- }
857
+ },
858
+ uniqueItems: true
1000
859
  },
1001
860
  boost: {
1002
861
  type: "object",
@@ -1049,7 +908,7 @@ var definitions$1 = {
1049
908
  minLength: 0,
1050
909
  maxLengthWithSpaceType: {
1051
910
  "default": 10000,
1052
- turbo: 20000
911
+ turbo: 40000
1053
912
  }
1054
913
  },
1055
914
  discussion: {
@@ -1219,7 +1078,7 @@ var definitions$3 = {
1219
1078
  reason: {
1220
1079
  type: "string",
1221
1080
  title: "reason",
1222
- maxLength: 140
1081
+ maxLength: 1000
1223
1082
  },
1224
1083
  app: {
1225
1084
  type: "string",
@@ -1262,6 +1121,36 @@ var definitions$4 = {
1262
1121
  title: "avatar",
1263
1122
  format: "customUrl",
1264
1123
  maxLength: 256
1124
+ },
1125
+ cover: {
1126
+ type: "string",
1127
+ title: "avatar",
1128
+ format: "customUrl",
1129
+ maxLength: 256
1130
+ },
1131
+ twitter: {
1132
+ type: "string",
1133
+ title: "twitter",
1134
+ pattern: "^[A-Za-z0-9_]*$",
1135
+ maxLength: 15
1136
+ },
1137
+ github: {
1138
+ type: "string",
1139
+ title: "github",
1140
+ pattern: "^[A-Za-z0-9_-]*$",
1141
+ maxLength: 39
1142
+ },
1143
+ lens: {
1144
+ type: "string",
1145
+ title: "lens",
1146
+ pattern: "^[A-Za-z0-9_]*$",
1147
+ maxLength: 26
1148
+ },
1149
+ farcaster: {
1150
+ type: "string",
1151
+ title: "farcaster",
1152
+ pattern: "^[a-z0-9-]*$",
1153
+ maxLength: 17
1265
1154
  }
1266
1155
  },
1267
1156
  required: [
@@ -1286,7 +1175,6 @@ var definitions$5 = {
1286
1175
  type: "string",
1287
1176
  format: "long",
1288
1177
  title: "About",
1289
- minLength: 1,
1290
1178
  maxLength: 140
1291
1179
  },
1292
1180
  statement: {
@@ -1294,10 +1182,28 @@ var definitions$5 = {
1294
1182
  format: "long",
1295
1183
  title: "Statement",
1296
1184
  maxLength: 10000
1185
+ },
1186
+ discourse: {
1187
+ type: "string",
1188
+ title: "discourse",
1189
+ pattern: "^[A-Za-z0-9-_.]*$",
1190
+ maxLength: 30
1191
+ },
1192
+ network: {
1193
+ type: "string",
1194
+ title: "network",
1195
+ pattern: "^[a-z0-9-]*$",
1196
+ maxLength: 24
1197
+ },
1198
+ status: {
1199
+ "enum": [
1200
+ "ACTIVE",
1201
+ "INACTIVE"
1202
+ ],
1203
+ title: "status"
1297
1204
  }
1298
1205
  },
1299
1206
  required: [
1300
- "about"
1301
1207
  ],
1302
1208
  additionalProperties: false
1303
1209
  }
@@ -1377,255 +1283,258 @@ var alias = {
1377
1283
  definitions: definitions$7
1378
1284
  };
1379
1285
 
1380
- var schemas = {
1381
- space: space.definitions.Space,
1382
- proposal: proposal.definitions.Proposal,
1383
- updateProposal: updateProposal.definitions.UpdateProposal,
1384
- vote: vote.definitions.Vote,
1385
- profile: profile.definitions.Profile,
1386
- statement: statement.definitions.Statement,
1387
- zodiac: zodiac.definitions.Zodiac,
1388
- alias: alias.definitions.Alias
1286
+ var schemas = {
1287
+ space: space.definitions.Space,
1288
+ proposal: proposal.definitions.Proposal,
1289
+ updateProposal: updateProposal.definitions.UpdateProposal,
1290
+ vote: vote.definitions.Vote,
1291
+ profile: profile.definitions.Profile,
1292
+ statement: statement.definitions.Statement,
1293
+ zodiac: zodiac.definitions.Zodiac,
1294
+ alias: alias.definitions.Alias
1389
1295
  };
1390
1296
 
1391
- var Multicaller = /** @class */ (function () {
1392
- function Multicaller(network, provider, abi, options) {
1393
- this.options = {};
1394
- this.calls = [];
1395
- this.paths = [];
1396
- this.network = network;
1397
- this.provider = provider;
1398
- this.abi = abi;
1399
- this.options = options || {};
1400
- }
1401
- Multicaller.prototype.call = function (path, address, fn, params) {
1402
- this.calls.push([address, fn, params]);
1403
- this.paths.push(path);
1404
- return this;
1405
- };
1406
- Multicaller.prototype.execute = function (from) {
1407
- return __awaiter(this, void 0, void 0, function () {
1408
- var obj, result;
1409
- var _this = this;
1410
- return __generator(this, function (_a) {
1411
- switch (_a.label) {
1412
- case 0:
1413
- obj = from || {};
1414
- return [4 /*yield*/, multicall(this.network, this.provider, this.abi, this.calls, this.options)];
1415
- case 1:
1416
- result = _a.sent();
1417
- result.forEach(function (r, i) { return set__default['default'](obj, _this.paths[i], r.length > 1 ? r : r[0]); });
1418
- this.calls = [];
1419
- this.paths = [];
1420
- return [2 /*return*/, obj];
1421
- }
1422
- });
1423
- });
1424
- };
1425
- return Multicaller;
1426
- }());
1297
+ class Multicaller {
1298
+ constructor(network, provider, abi, options) {
1299
+ this.options = {};
1300
+ this.calls = [];
1301
+ this.paths = [];
1302
+ this.network = network;
1303
+ this.provider = provider;
1304
+ this.abi = abi;
1305
+ this.options = options || {};
1306
+ }
1307
+ call(path, address, fn, params) {
1308
+ this.calls.push([address, fn, params]);
1309
+ this.paths.push(path);
1310
+ return this;
1311
+ }
1312
+ execute(from) {
1313
+ return __awaiter(this, void 0, void 0, function* () {
1314
+ const obj = from || {};
1315
+ const result = yield multicall(this.network, this.provider, this.abi, this.calls, this.options);
1316
+ result.forEach((r, i) => set__default['default'](obj, this.paths[i], r.length > 1 ? r : r[0]));
1317
+ this.calls = [];
1318
+ this.paths = [];
1319
+ return obj;
1320
+ });
1321
+ }
1322
+ }
1427
1323
 
1428
- var cache = {};
1429
- var expirationTime = 0;
1430
- function getSnapshots(network, snapshot, provider, networks, options) {
1431
- if (options === void 0) { options = {}; }
1432
- return __awaiter(this, void 0, void 0, function () {
1433
- var snapshots, cacheKey, cachedEntry, now, networkIn, block, query, url, data;
1434
- return __generator(this, function (_a) {
1435
- switch (_a.label) {
1436
- case 0:
1437
- snapshots = {};
1438
- networks.forEach(function (n) { return (snapshots[n] = 'latest'); });
1439
- if (snapshot === 'latest')
1440
- return [2 /*return*/, snapshots];
1441
- cacheKey = network + "-" + snapshot + "-" + networks.join('-');
1442
- cachedEntry = cache[cacheKey];
1443
- now = Date.now();
1444
- if (cachedEntry && expirationTime > now) {
1445
- return [2 /*return*/, cachedEntry];
1446
- }
1447
- // Reset cache every hour
1448
- if (expirationTime < now) {
1449
- cache = {};
1450
- // Set expiration time to next hour
1451
- expirationTime = now + 60 * 60 * 1000 - (now % (60 * 60 * 1000));
1452
- }
1453
- snapshots[network] = snapshot;
1454
- networkIn = Object.keys(snapshots).filter(function (s) { return network !== s; });
1455
- if (networkIn.length === 0)
1456
- return [2 /*return*/, snapshots];
1457
- return [4 /*yield*/, provider.getBlock(snapshot)];
1458
- case 1:
1459
- block = _a.sent();
1460
- query = {
1461
- blocks: {
1462
- __args: {
1463
- where: {
1464
- ts: block.timestamp,
1465
- network_in: networkIn
1466
- }
1467
- },
1468
- network: true,
1469
- number: true
1470
- }
1471
- };
1472
- url = options.blockFinderUrl || 'https://blockfinder.snapshot.org';
1473
- return [4 /*yield*/, subgraphRequest(url, query)];
1474
- case 2:
1475
- data = _a.sent();
1476
- data.blocks.forEach(function (block) { return (snapshots[block.network] = block.number); });
1477
- cache[cacheKey] = snapshots;
1478
- return [2 /*return*/, snapshots];
1479
- }
1480
- });
1481
- });
1324
+ let cache = {};
1325
+ let expirationTime = 0;
1326
+ function getSnapshots(network_1, snapshot_1, provider_1, networks_1) {
1327
+ return __awaiter(this, arguments, void 0, function* (network, snapshot, provider, networks, options = {}) {
1328
+ // If snapshot is latest, return all latest
1329
+ const snapshots = {};
1330
+ networks.forEach((n) => (snapshots[n] = 'latest'));
1331
+ if (snapshot === 'latest')
1332
+ return snapshots;
1333
+ // Check if cache is valid
1334
+ const cacheKey = `${network}-${snapshot}-${networks.join('-')}`;
1335
+ const cachedEntry = cache[cacheKey];
1336
+ const now = Date.now();
1337
+ if (cachedEntry && expirationTime > now) {
1338
+ return cachedEntry;
1339
+ }
1340
+ // Reset cache every hour
1341
+ if (expirationTime < now) {
1342
+ cache = {};
1343
+ // Set expiration time to next hour
1344
+ expirationTime = now + 60 * 60 * 1000 - (now % (60 * 60 * 1000));
1345
+ }
1346
+ snapshots[network] = snapshot;
1347
+ const networkIn = Object.keys(snapshots).filter((s) => network !== s);
1348
+ if (networkIn.length === 0)
1349
+ return snapshots;
1350
+ const block = yield provider.getBlock(snapshot);
1351
+ const query = {
1352
+ blocks: {
1353
+ __args: {
1354
+ where: {
1355
+ ts: block.timestamp,
1356
+ network_in: networkIn
1357
+ }
1358
+ },
1359
+ network: true,
1360
+ number: true
1361
+ }
1362
+ };
1363
+ const url = options.blockFinderUrl || 'https://blockfinder.snapshot.org';
1364
+ const data = yield subgraphRequest(url, query);
1365
+ data.blocks.forEach((block) => (snapshots[block.network] = block.number));
1366
+ cache[cacheKey] = snapshots;
1367
+ return snapshots;
1368
+ });
1482
1369
  }
1483
1370
 
1484
- var providers = {};
1485
- function getProvider(network, _a) {
1486
- var _b = (_a === void 0 ? {} : _a).broviderUrl, broviderUrl = _b === void 0 ? 'https://rpc.snapshot.org' : _b;
1487
- var url = broviderUrl + "/" + network;
1488
- if (!providers[network])
1489
- providers[network] = new providers$1.StaticJsonRpcProvider({
1490
- url: url,
1491
- timeout: 25000,
1492
- allowGzip: true
1493
- }, Number(network));
1494
- return providers[network];
1371
+ const providers = {};
1372
+ const DEFAULT_BROVIDER_URL = 'https://rpc.snapshot.org';
1373
+ function getProvider(network, { broviderUrl = DEFAULT_BROVIDER_URL } = {}) {
1374
+ const url = `${broviderUrl}/${network}`;
1375
+ if (!providers[network])
1376
+ providers[network] = new providers$1.StaticJsonRpcProvider({
1377
+ url,
1378
+ timeout: 25000,
1379
+ allowGzip: true
1380
+ }, Number(network));
1381
+ return providers[network];
1495
1382
  }
1496
1383
 
1497
- function signMessage(web3, msg, address) {
1498
- return __awaiter(this, void 0, void 0, function () {
1499
- return __generator(this, function (_a) {
1500
- switch (_a.label) {
1501
- case 0:
1502
- msg = bytes.hexlify(new Buffer(msg, 'utf8'));
1503
- return [4 /*yield*/, web3.send('personal_sign', [msg, address])];
1504
- case 1: return [2 /*return*/, _a.sent()];
1505
- }
1506
- });
1507
- });
1508
- }
1509
- function getBlockNumber(provider) {
1510
- return __awaiter(this, void 0, void 0, function () {
1511
- var blockNumber, e_1;
1512
- return __generator(this, function (_a) {
1513
- switch (_a.label) {
1514
- case 0:
1515
- _a.trys.push([0, 2, , 3]);
1516
- return [4 /*yield*/, provider.getBlockNumber()];
1517
- case 1:
1518
- blockNumber = _a.sent();
1519
- return [2 /*return*/, parseInt(blockNumber)];
1520
- case 2:
1521
- e_1 = _a.sent();
1522
- return [2 /*return*/, Promise.reject()];
1523
- case 3: return [2 /*return*/];
1524
- }
1525
- });
1526
- });
1384
+ function signMessage(web3, msg, address) {
1385
+ return __awaiter(this, void 0, void 0, function* () {
1386
+ msg = bytes.hexlify(new Buffer(msg, 'utf8'));
1387
+ return yield web3.send('personal_sign', [msg, address]);
1388
+ });
1389
+ }
1390
+ function getBlockNumber(provider) {
1391
+ return __awaiter(this, void 0, void 0, function* () {
1392
+ try {
1393
+ const blockNumber = yield provider.getBlockNumber();
1394
+ return parseInt(blockNumber);
1395
+ }
1396
+ catch (e) {
1397
+ return Promise.reject();
1398
+ }
1399
+ });
1527
1400
  }
1528
1401
 
1529
- function verifyDefault(address, sig, hash, provider) {
1530
- return __awaiter(this, void 0, void 0, function () {
1531
- var returnValue, magicValue, abi, e_1;
1532
- return __generator(this, function (_a) {
1533
- switch (_a.label) {
1534
- case 0:
1535
- magicValue = '0x1626ba7e';
1536
- abi = 'function isValidSignature(bytes32 _hash, bytes memory _signature) public view returns (bytes4 magicValue)';
1537
- _a.label = 1;
1538
- case 1:
1539
- _a.trys.push([1, 3, , 4]);
1540
- return [4 /*yield*/, call(provider, [abi], [address, 'isValidSignature', [bytes.arrayify(hash), sig]])];
1541
- case 2:
1542
- returnValue = _a.sent();
1543
- return [3 /*break*/, 4];
1544
- case 3:
1545
- e_1 = _a.sent();
1546
- // @ts-ignore
1547
- if (e_1.message.startsWith('missing revert data in call exception')) {
1548
- return [2 /*return*/, false];
1549
- }
1550
- throw e_1;
1551
- case 4: return [2 /*return*/, returnValue.toLowerCase() === magicValue.toLowerCase()];
1552
- }
1553
- });
1554
- });
1555
- }
1556
- function verifyOldVersion(address, sig, hash, provider) {
1557
- return __awaiter(this, void 0, void 0, function () {
1558
- var magicValue, abi, returnValue;
1559
- return __generator(this, function (_a) {
1560
- switch (_a.label) {
1561
- case 0:
1562
- magicValue = '0x20c13b0b';
1563
- abi = 'function isValidSignature(bytes _hash, bytes memory _signature) public view returns (bytes4 magicValue)';
1564
- return [4 /*yield*/, call(provider, [abi], [address, 'isValidSignature', [bytes.arrayify(hash), sig]])];
1565
- case 1:
1566
- returnValue = _a.sent();
1567
- return [2 /*return*/, returnValue.toLowerCase() === magicValue.toLowerCase()];
1568
- }
1569
- });
1570
- });
1571
- }
1572
- function verify(address, sig, hash, network, options) {
1573
- if (network === void 0) { network = '1'; }
1574
- if (options === void 0) { options = {}; }
1575
- return __awaiter(this, void 0, void 0, function () {
1576
- var provider;
1577
- return __generator(this, function (_a) {
1578
- switch (_a.label) {
1579
- case 0:
1580
- provider = getProvider(network, options);
1581
- return [4 /*yield*/, verifyDefault(address, sig, hash, provider)];
1582
- case 1:
1583
- if (_a.sent())
1584
- return [2 /*return*/, true];
1585
- return [4 /*yield*/, verifyOldVersion(address, sig, hash, provider)];
1586
- case 2: return [2 /*return*/, _a.sent()];
1587
- }
1588
- });
1589
- });
1402
+ const RPC_URLS = {
1403
+ SN_MAIN: 'https://starknet-mainnet.public.blastapi.io',
1404
+ SN_SEPOLIA: 'https://starknet-sepolia.public.blastapi.io'
1405
+ };
1406
+ const ABI = [
1407
+ {
1408
+ name: 'argent::account::interface::IDeprecatedArgentAccount',
1409
+ type: 'interface',
1410
+ items: [
1411
+ {
1412
+ name: 'isValidSignature',
1413
+ type: 'function',
1414
+ inputs: [
1415
+ {
1416
+ name: 'hash',
1417
+ type: 'core::felt252'
1418
+ },
1419
+ {
1420
+ name: 'signatures',
1421
+ type: 'core::array::Array::<core::felt252>'
1422
+ }
1423
+ ],
1424
+ outputs: [
1425
+ {
1426
+ type: 'core::felt252'
1427
+ }
1428
+ ],
1429
+ state_mutability: 'view'
1430
+ }
1431
+ ]
1432
+ }
1433
+ ];
1434
+ function getProvider$1(network, options) {
1435
+ var _a;
1436
+ if (!RPC_URLS[network])
1437
+ throw new Error('Invalid network');
1438
+ return new starknet$1.RpcProvider({
1439
+ nodeUrl: (_a = options === null || options === void 0 ? void 0 : options.broviderUrl) !== null && _a !== void 0 ? _a : RPC_URLS[network]
1440
+ });
1441
+ }
1442
+ function isStarknetMessage(data) {
1443
+ return !!data.primaryType && !!data.types.StarkNetDomain;
1444
+ }
1445
+ function getHash(data, address) {
1446
+ const { domain, types, primaryType, message } = data;
1447
+ return starknet$1.typedData.getMessageHash({ types, primaryType, domain, message }, address);
1448
+ }
1449
+ function verify(address_1, sig_1, data_1) {
1450
+ return __awaiter(this, arguments, void 0, function* (address, sig, data, network = 'SN_MAIN', options = {}) {
1451
+ const contractAccount = new starknet$1.Contract(ABI, address, getProvider$1(network, options));
1452
+ yield contractAccount.isValidSignature(getHash(data, address), [
1453
+ sig[0],
1454
+ sig[1]
1455
+ ]);
1456
+ return true;
1457
+ });
1590
1458
  }
1591
1459
 
1592
- function getHash(data) {
1593
- var domain = data.domain, types = data.types, message = data.message;
1594
- return hash._TypedDataEncoder.hash(domain, types, message);
1595
- }
1596
- function verify$1(address, sig, data, network, options) {
1597
- if (network === void 0) { network = '1'; }
1598
- if (options === void 0) { options = {}; }
1599
- return __awaiter(this, void 0, void 0, function () {
1600
- var domain, types, message, hash, recoverAddress;
1601
- return __generator(this, function (_a) {
1602
- switch (_a.label) {
1603
- case 0:
1604
- domain = data.domain, types = data.types, message = data.message;
1605
- hash = getHash(data);
1606
- // console.log('Hash', hash);
1607
- // console.log('Address', address);
1608
- try {
1609
- recoverAddress = wallet.verifyTypedData(domain, types, message, sig);
1610
- // console.log('Recover address', recoverAddress);
1611
- if (address === recoverAddress)
1612
- return [2 /*return*/, true];
1613
- }
1614
- catch (e) {
1615
- // console.log('Could not recoverAddress:' + e.message);
1616
- }
1617
- return [4 /*yield*/, verify(address, sig, hash, network, options)];
1618
- case 1:
1619
- // console.log('Check EIP1271 signature');
1620
- return [2 /*return*/, _a.sent()];
1621
- }
1622
- });
1623
- });
1460
+ var starknet = /*#__PURE__*/Object.freeze({
1461
+ __proto__: null,
1462
+ isStarknetMessage: isStarknetMessage,
1463
+ getHash: getHash,
1464
+ 'default': verify
1465
+ });
1466
+
1467
+ function isEqual(a, b) {
1468
+ return a.toLowerCase() === b.toLowerCase();
1469
+ }
1470
+ function getHash$1(data) {
1471
+ const { domain, types, message } = data;
1472
+ return hash._TypedDataEncoder.hash(domain, types, message);
1473
+ }
1474
+ function verify$1(address_1, sig_1, data_1) {
1475
+ return __awaiter(this, arguments, void 0, function* (address, sig, data, network = '1', options = {}) {
1476
+ const { domain, types, message } = data;
1477
+ try {
1478
+ const recoverAddress = wallet.verifyTypedData(domain, types, message, sig);
1479
+ if (isEqual(address, recoverAddress))
1480
+ return true;
1481
+ }
1482
+ catch (e) { }
1483
+ const provider = getProvider(network, options);
1484
+ const hash = getHash$1(data);
1485
+ if (yield verifyDefault(address, sig, hash, provider))
1486
+ return true;
1487
+ return yield verifyOldVersion(address, sig, hash, provider);
1488
+ });
1489
+ }
1490
+ function verifyDefault(address, sig, hash, provider) {
1491
+ return __awaiter(this, void 0, void 0, function* () {
1492
+ let returnValue;
1493
+ const magicValue = '0x1626ba7e';
1494
+ const abi = 'function isValidSignature(bytes32 _hash, bytes memory _signature) public view returns (bytes4 magicValue)';
1495
+ try {
1496
+ returnValue = yield call(provider, [abi], [address, 'isValidSignature', [bytes.arrayify(hash), sig]]);
1497
+ }
1498
+ catch (e) {
1499
+ if (e.message.startsWith('missing revert data in call exception')) {
1500
+ return false;
1501
+ }
1502
+ throw e;
1503
+ }
1504
+ return isEqual(returnValue, magicValue);
1505
+ });
1506
+ }
1507
+ function verifyOldVersion(address, sig, hash, provider) {
1508
+ return __awaiter(this, void 0, void 0, function* () {
1509
+ const magicValue = '0x20c13b0b';
1510
+ const abi = 'function isValidSignature(bytes _hash, bytes memory _signature) public view returns (bytes4 magicValue)';
1511
+ const returnValue = yield call(provider, [abi], [address, 'isValidSignature', [bytes.arrayify(hash), sig]]);
1512
+ return isEqual(returnValue, magicValue);
1513
+ });
1514
+ }
1515
+
1516
+ var evm = /*#__PURE__*/Object.freeze({
1517
+ __proto__: null,
1518
+ getHash: getHash$1,
1519
+ 'default': verify$1
1520
+ });
1521
+
1522
+ function getHash$2(data, address) {
1523
+ const networkType = isStarknetMessage(data) ? starknet : evm;
1524
+ return networkType.getHash(data, address);
1525
+ }
1526
+ function verify$2(address_1, sig_1, data_1) {
1527
+ return __awaiter(this, arguments, void 0, function* (address, sig, data, network = '1', options = {}) {
1528
+ if (!isStarknetAddress(address) && !isEvmAddress(address)) {
1529
+ throw new Error('Invalid address');
1530
+ }
1531
+ const networkType = isStarknetMessage(data) ? starknet : evm;
1532
+ return yield networkType.default(address, sig, data, network, options);
1533
+ });
1624
1534
  }
1625
1535
 
1626
1536
  var gateways = [
1627
- "cloudflare-ipfs.com",
1628
- "cf-ipfs.com",
1537
+ "snapshot.4everland.link",
1629
1538
  "ipfs.io",
1630
1539
  "ipfs.fleek.co",
1631
1540
  "gateway.pinata.cloud",
@@ -1645,7 +1554,7 @@ var networks = {
1645
1554
  "0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41"
1646
1555
  ],
1647
1556
  ensNameWrapper: "0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401",
1648
- ensSubgraph: "https://api.thegraph.com/subgraphs/name/ensdomains/ens",
1557
+ ensSubgraph: "https://subgrapher.snapshot.org/subgraph/arbitrum/5XqPmWe6gjyrJtFn9cLy237i4cWw2j9HcUJEXsP5qGtH",
1649
1558
  rpc: [
1650
1559
  "https://rpc.ankr.com/eth",
1651
1560
  {
@@ -1670,30 +1579,6 @@ var networks = {
1670
1579
  },
1671
1580
  start: 7929876,
1672
1581
  logo: "ipfs://bafkreid7ndxh6y2ljw2jhbisodiyrhcy2udvnwqgon5wgells3kh4si5z4"
1673
- },
1674
- "5": {
1675
- key: "5",
1676
- name: "Goerli testnet",
1677
- shortName: "Goerli",
1678
- chainId: 5,
1679
- network: "goerli",
1680
- testnet: true,
1681
- multicall: "0x77dca2c955b15e9de4dbbcf1246b4b85b651e50e",
1682
- ensResolvers: [
1683
- "0xd7a4F6473f32aC2Af804B3686AE8F1932bC35750",
1684
- "0x4B1488B7a6B320d2D721406204aBc3eeAa9AD329"
1685
- ],
1686
- ensNameWrapper: "0x114D4603199df73e7D157787f8778E21fCd13066",
1687
- ensSubgraph: "https://api.thegraph.com/subgraphs/name/ensdomains/ensgoerli",
1688
- rpc: [
1689
- "https://eth-goerli.alchemyapi.io/v2/v4nqH_J-J3STit45Mm07TxuYexMHQsYZ"
1690
- ],
1691
- explorer: {
1692
- url: "https://goerli.etherscan.io",
1693
- apiUrl: "https://api-goerli.etherscan.io"
1694
- },
1695
- start: 743550,
1696
- logo: "ipfs://bafkreid7ndxh6y2ljw2jhbisodiyrhcy2udvnwqgon5wgells3kh4si5z4"
1697
1582
  },
1698
1583
  "8": {
1699
1584
  key: "8",
@@ -2124,22 +2009,21 @@ var networks = {
2124
2009
  start: 13960096,
2125
2010
  logo: "ipfs://QmU7f1MyRz8rLELFfypnWZQjGbDGYgZtC9rjw47jYMYrnu"
2126
2011
  },
2127
- "280": {
2128
- key: "280",
2129
- name: "zkSync Era Testnet",
2130
- shortName: "zkSync testnet",
2131
- chainId: 280,
2132
- network: "zkSync alpha testnet",
2133
- testnet: true,
2134
- multicall: "0xbDAd32d600915cB70576D3d935d49bFf3C9cB0CF",
2012
+ "300": {
2013
+ key: "300",
2014
+ name: "zkSync Sepolia Testnet",
2015
+ shortName: "testnet",
2016
+ chainId: 300,
2017
+ network: "testnet",
2018
+ multicall: "0xF9cda624FBC7e059355ce98a31693d299FACd963",
2135
2019
  rpc: [
2136
- "https://testnet.era.zksync.dev"
2137
2020
  ],
2138
2021
  explorer: {
2139
- url: "https://goerli.explorer.zksync.io/"
2022
+ url: "https://sepolia.explorer.zksync.dev/"
2140
2023
  },
2141
- start: 9012429,
2142
- logo: "ipfs://bafkreih6y7ri7h667cwxe5miisxghfheiidtbw2747y75stoxt3gp3a2yy"
2024
+ start: 2292,
2025
+ logo: "ipfs://bafkreih6y7ri7h667cwxe5miisxghfheiidtbw2747y75stoxt3gp3a2yy",
2026
+ testnet: true
2143
2027
  },
2144
2028
  "314": {
2145
2029
  key: "314",
@@ -2448,6 +2332,37 @@ var networks = {
2448
2332
  },
2449
2333
  start: 859041,
2450
2334
  logo: "ipfs://QmeGbNTU2Jqwg8qLTMGW8n8HSi2VdgCncAaeGzLx6gYnD7"
2335
+ },
2336
+ "1328": {
2337
+ key: "1328",
2338
+ name: "Sei atlantic testnet",
2339
+ shortName: "testnet",
2340
+ chainId: 1328,
2341
+ network: "testnet",
2342
+ multicall: "0xc454132B017b55b427f45078E335549A7124f5f7",
2343
+ rpc: [
2344
+ ],
2345
+ explorer: {
2346
+ url: "https://seitrace.com"
2347
+ },
2348
+ start: 96978658,
2349
+ logo: "ipfs://bafkreiammyt7uztbztqbcqv4bydnczsh2fqmnjf6jxj4xnskzzl6sjrigq",
2350
+ testnet: true
2351
+ },
2352
+ "1329": {
2353
+ key: "1329",
2354
+ name: "Sei",
2355
+ shortName: "mainnet",
2356
+ chainId: 1329,
2357
+ network: "mainnet",
2358
+ multicall: "0xe033Bed7cae4114Af84Be1e9F1CA7DEa07Dfe1Cf",
2359
+ rpc: [
2360
+ ],
2361
+ explorer: {
2362
+ url: "https://seitrace.com/"
2363
+ },
2364
+ start: 79164574,
2365
+ logo: "ipfs://bafkreiammyt7uztbztqbcqv4bydnczsh2fqmnjf6jxj4xnskzzl6sjrigq"
2451
2366
  },
2452
2367
  "1559": {
2453
2368
  key: "1559",
@@ -2528,6 +2443,37 @@ var networks = {
2528
2443
  },
2529
2444
  start: 4219343,
2530
2445
  logo: "ipfs://QmXkneyRB6HbHTHRLCZpZqSsawiyJY7b2kZ2V8ydvKYAgv"
2446
+ },
2447
+ "2221": {
2448
+ key: "2221",
2449
+ name: "Kava Testnet",
2450
+ shortName: "testnet",
2451
+ chainId: 2221,
2452
+ network: "testnet",
2453
+ multicall: "0xc7193EFE367DF0C9349a1149F4E95A2A35604262",
2454
+ rpc: [
2455
+ ],
2456
+ explorer: {
2457
+ url: "https://testnet.kavascan.com"
2458
+ },
2459
+ start: 6193104,
2460
+ logo: "ipfs://bafkreibpfubharx32fjqkqbfdhygwdjb2khxdg6meaasrcxsgvowos26f4",
2461
+ testnet: true
2462
+ },
2463
+ "2222": {
2464
+ key: "2222",
2465
+ name: "Kava",
2466
+ shortName: "mainnet",
2467
+ chainId: 2222,
2468
+ network: "mainnet",
2469
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
2470
+ rpc: [
2471
+ ],
2472
+ explorer: {
2473
+ url: "https://kavascan.com/"
2474
+ },
2475
+ start: 3661165,
2476
+ logo: "ipfs://bafkreibpfubharx32fjqkqbfdhygwdjb2khxdg6meaasrcxsgvowos26f4"
2531
2477
  },
2532
2478
  "2400": {
2533
2479
  key: "2400",
@@ -2669,6 +2615,21 @@ var networks = {
2669
2615
  },
2670
2616
  start: 3673983,
2671
2617
  logo: "ipfs://bafkreifwxnnfk6koabzmxgcxcwlrwt6b5gijdain2gyqee77q4ajfb7fu4"
2618
+ },
2619
+ "7560": {
2620
+ key: "7560",
2621
+ name: "Cyber",
2622
+ shortName: "mainnet",
2623
+ chainId: 7560,
2624
+ network: "mainnet",
2625
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
2626
+ rpc: [
2627
+ ],
2628
+ explorer: {
2629
+ url: "https://cyberscan.co"
2630
+ },
2631
+ start: 1731707,
2632
+ logo: "ipfs://bafkreifm2bbehoqpz4454o7gixnxfi6cgvqlxigqr3f6ipj7l2omtgfgnm"
2672
2633
  },
2673
2634
  "8217": {
2674
2635
  key: "8217",
@@ -2771,6 +2732,37 @@ var networks = {
2771
2732
  start: 3,
2772
2733
  logo: "ipfs://QmaKRLxXPdeTsLx7MFLS3CJbhpSbResgoeL4fCgHB1mTsF",
2773
2734
  testnet: true
2735
+ },
2736
+ "13371": {
2737
+ key: "13371",
2738
+ name: "Immutable zkEVM",
2739
+ shortName: "mainnet",
2740
+ chainId: 13371,
2741
+ network: "mainnet",
2742
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
2743
+ rpc: [
2744
+ ],
2745
+ explorer: {
2746
+ url: "https://explorer.immutable.com"
2747
+ },
2748
+ start: 3680945,
2749
+ logo: "ipfs://bafkreiepnhfv3hgexddjpyaeemxo3byhtxxit6t4zsponyczee6ddjqxwi"
2750
+ },
2751
+ "13473": {
2752
+ key: "13473",
2753
+ name: "Immutable zkEVM Testnet",
2754
+ shortName: "testnet",
2755
+ chainId: 13473,
2756
+ network: "testnet",
2757
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
2758
+ rpc: [
2759
+ ],
2760
+ explorer: {
2761
+ url: "https://explorer.testnet.immutable.com"
2762
+ },
2763
+ start: 5307209,
2764
+ logo: "ipfs://bafkreiepnhfv3hgexddjpyaeemxo3byhtxxit6t4zsponyczee6ddjqxwi",
2765
+ testnet: true
2774
2766
  },
2775
2767
  "16718": {
2776
2768
  key: "16718",
@@ -2919,19 +2911,19 @@ var networks = {
2919
2911
  start: 62,
2920
2912
  logo: "ipfs://QmZNkpVgPbuVbDcsi6arwH1om3456FGnwfDqYQJWUfHDEx"
2921
2913
  },
2922
- "59140": {
2923
- key: "59140",
2924
- name: "Linea Goerli testnet",
2925
- shortName: "linea",
2926
- chainId: 59140,
2914
+ "59141": {
2915
+ key: "59141",
2916
+ name: "Linea Sepolia",
2917
+ shortName: "testnet",
2918
+ chainId: 59141,
2927
2919
  network: "testnet",
2928
2920
  multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
2929
2921
  rpc: [
2930
2922
  ],
2931
2923
  explorer: {
2932
- url: "https://goerli.lineascan.build/"
2924
+ url: "https://sepolia.lineascan.build/"
2933
2925
  },
2934
- start: 498623,
2926
+ start: 227427,
2935
2927
  logo: "ipfs://bafkreihtyzolub3sejuwc32hpdpjnt7ksowaguni2yuho3kyihhcqrtqce",
2936
2928
  testnet: true
2937
2929
  },
@@ -2971,21 +2963,36 @@ var networks = {
2971
2963
  start: 12011090,
2972
2964
  logo: "ipfs://bafkreihgr7zy7vi5kqddybfaezwuhvssg57qluwmyan4qq7l57nr7w7wey"
2973
2965
  },
2974
- "84531": {
2975
- key: "84531",
2976
- name: "Base Goerli Testnet",
2977
- chainId: 84531,
2978
- network: "Base",
2979
- testnet: true,
2980
- multicall: "0x0012989E982C2c473e36418384Ab707C72f2B782",
2966
+ "81457": {
2967
+ key: "81457",
2968
+ name: "Blast",
2969
+ shortName: "mainnet",
2970
+ chainId: 81457,
2971
+ network: "mainnet",
2972
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
2981
2973
  rpc: [
2982
- "https://goerli.base.org"
2983
2974
  ],
2984
2975
  explorer: {
2985
- url: "https://goerli.basescan.org/"
2976
+ url: "https://blastscan.io"
2986
2977
  },
2987
- start: 1151797,
2988
- logo: "ipfs://QmaxRoHpxZd8PqccAynherrMznMufG6sdmHZLihkECXmZv"
2978
+ start: 88189,
2979
+ logo: "ipfs://bafkreibfmkjg22cozxppzcoxswj45clvh2rqhxzax57cmmgudbtkf4dkce"
2980
+ },
2981
+ "84532": {
2982
+ key: "84532",
2983
+ name: "Base Sepolia",
2984
+ shortName: "testnet",
2985
+ chainId: 84532,
2986
+ network: "testnet",
2987
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
2988
+ rpc: [
2989
+ ],
2990
+ explorer: {
2991
+ url: "https://base-sepolia.blockscout.com/"
2992
+ },
2993
+ start: 1059647,
2994
+ logo: "ipfs://QmaxRoHpxZd8PqccAynherrMznMufG6sdmHZLihkECXmZv",
2995
+ testnet: true
2989
2996
  },
2990
2997
  "686868": {
2991
2998
  key: "686868",
@@ -3018,6 +3025,37 @@ var networks = {
3018
3025
  start: 1463669,
3019
3026
  logo: "ipfs://bafkreiammyt7uztbztqbcqv4bydnczsh2fqmnjf6jxj4xnskzzl6sjrigq",
3020
3027
  testnet: true
3028
+ },
3029
+ "810180": {
3030
+ key: "810180",
3031
+ name: "zkLink Nova",
3032
+ shortName: "zlink",
3033
+ chainId: 810180,
3034
+ network: "mainnet",
3035
+ multicall: "0x825267E0fA5CAe92F98540828a54198dcB3Eaeb5",
3036
+ rpc: [
3037
+ ],
3038
+ explorer: {
3039
+ url: "https://explorer.zklink.io"
3040
+ },
3041
+ start: 146055,
3042
+ logo: "ipfs://bafkreic6c3iems5235qapyhyrygha7akqrsfact2nok3y2uhljpzxrdu74"
3043
+ },
3044
+ "810181": {
3045
+ key: "810181",
3046
+ name: "zkLink Nova Sepolia",
3047
+ shortName: "testnet",
3048
+ chainId: 810181,
3049
+ network: "testnet",
3050
+ multicall: "0x97148F8fDdd9A1620f72EC1Bb2932916623d9da5",
3051
+ rpc: [
3052
+ ],
3053
+ explorer: {
3054
+ url: "https://sepolia.explorer.zklink.io/"
3055
+ },
3056
+ start: 43723,
3057
+ logo: "ipfs://bafkreic6c3iems5235qapyhyrygha7akqrsfact2nok3y2uhljpzxrdu74",
3058
+ testnet: true
3021
3059
  },
3022
3060
  "11155111": {
3023
3061
  key: "11155111",
@@ -3041,6 +3079,54 @@ var networks = {
3041
3079
  },
3042
3080
  start: 751532,
3043
3081
  logo: "ipfs://bafkreid7ndxh6y2ljw2jhbisodiyrhcy2udvnwqgon5wgells3kh4si5z4"
3082
+ },
3083
+ "11155420": {
3084
+ key: "11155420",
3085
+ name: "OP Sepolia",
3086
+ shortName: "testnet",
3087
+ chainId: 11155420,
3088
+ network: "testnet",
3089
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
3090
+ rpc: [
3091
+ ],
3092
+ explorer: {
3093
+ url: "https://sepolia-optimism.etherscan.io"
3094
+ },
3095
+ start: 1620204,
3096
+ logo: "ipfs://QmfF4kwhGL8QosUXvgq2KWCmavhKBvwD6kbhs7L4p5ZAWb",
3097
+ testnet: true
3098
+ },
3099
+ "111557560": {
3100
+ key: "111557560",
3101
+ name: "Cyber Testnet",
3102
+ shortName: "testnet",
3103
+ chainId: 111557560,
3104
+ network: "testnet",
3105
+ multicall: "0xffc391F0018269d4758AEA1a144772E8FB99545E",
3106
+ rpc: [
3107
+ ],
3108
+ explorer: {
3109
+ url: "https://testnet.cyberscan.co/"
3110
+ },
3111
+ start: 304545,
3112
+ logo: "ipfs://bafkreifm2bbehoqpz4454o7gixnxfi6cgvqlxigqr3f6ipj7l2omtgfgnm",
3113
+ testnet: true
3114
+ },
3115
+ "168587773": {
3116
+ key: "168587773",
3117
+ name: "Blast Sepolia",
3118
+ shortName: "testnet",
3119
+ chainId: 168587773,
3120
+ network: "testnet",
3121
+ multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
3122
+ rpc: [
3123
+ ],
3124
+ explorer: {
3125
+ url: "https://sepolia.blastexplorer.io"
3126
+ },
3127
+ start: 756690,
3128
+ logo: "ipfs://bafkreibfmkjg22cozxppzcoxswj45clvh2rqhxzax57cmmgudbtkf4dkce",
3129
+ testnet: true
3044
3130
  },
3045
3131
  "245022926": {
3046
3132
  key: "245022926",
@@ -3115,1149 +3201,985 @@ var networks = {
3115
3201
  }
3116
3202
  };
3117
3203
 
3118
- var SingleChoiceVoting = /** @class */ (function () {
3119
- function SingleChoiceVoting(proposal, votes, strategies, selected) {
3120
- this.proposal = proposal;
3121
- this.votes = votes;
3122
- this.strategies = strategies;
3123
- this.selected = selected;
3124
- }
3125
- SingleChoiceVoting.isValidChoice = function (voteChoice, proposalChoices) {
3126
- return (typeof voteChoice === 'number' &&
3127
- (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[voteChoice - 1]) !== undefined);
3128
- };
3129
- SingleChoiceVoting.prototype.getValidVotes = function () {
3130
- var _this = this;
3131
- return this.votes.filter(function (vote) {
3132
- return SingleChoiceVoting.isValidChoice(vote.choice, _this.proposal.choices);
3133
- });
3134
- };
3135
- SingleChoiceVoting.prototype.getScores = function () {
3136
- var _this = this;
3137
- return this.proposal.choices.map(function (choice, i) {
3138
- var votes = _this.getValidVotes().filter(function (vote) { return vote.choice === i + 1; });
3139
- var balanceSum = votes.reduce(function (a, b) { return a + b.balance; }, 0);
3140
- return balanceSum;
3141
- });
3142
- };
3143
- SingleChoiceVoting.prototype.getScoresByStrategy = function () {
3144
- var _this = this;
3145
- return this.proposal.choices.map(function (choice, i) {
3146
- var scores = _this.strategies.map(function (strategy, sI) {
3147
- var votes = _this.getValidVotes().filter(function (vote) { return vote.choice === i + 1; });
3148
- var scoreSum = votes.reduce(function (a, b) { return a + b.scores[sI]; }, 0);
3149
- return scoreSum;
3150
- });
3151
- return scores;
3152
- });
3153
- };
3154
- SingleChoiceVoting.prototype.getScoresTotal = function () {
3155
- return this.votes.reduce(function (a, b) { return a + b.balance; }, 0);
3156
- };
3157
- SingleChoiceVoting.prototype.getChoiceString = function () {
3158
- return this.proposal.choices[this.selected - 1];
3159
- };
3160
- return SingleChoiceVoting;
3161
- }());
3204
+ class SingleChoiceVoting {
3205
+ constructor(proposal, votes, strategies, selected) {
3206
+ this.proposal = proposal;
3207
+ this.votes = votes;
3208
+ this.strategies = strategies;
3209
+ this.selected = selected;
3210
+ }
3211
+ static isValidChoice(voteChoice, proposalChoices) {
3212
+ return (typeof voteChoice === 'number' &&
3213
+ (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[voteChoice - 1]) !== undefined);
3214
+ }
3215
+ getValidVotes() {
3216
+ return this.votes.filter((vote) => SingleChoiceVoting.isValidChoice(vote.choice, this.proposal.choices));
3217
+ }
3218
+ getScores() {
3219
+ return this.proposal.choices.map((choice, i) => {
3220
+ const votes = this.getValidVotes().filter((vote) => vote.choice === i + 1);
3221
+ const balanceSum = votes.reduce((a, b) => a + b.balance, 0);
3222
+ return balanceSum;
3223
+ });
3224
+ }
3225
+ getScoresByStrategy() {
3226
+ return this.proposal.choices.map((choice, i) => {
3227
+ const scores = this.strategies.map((strategy, sI) => {
3228
+ const votes = this.getValidVotes().filter((vote) => vote.choice === i + 1);
3229
+ const scoreSum = votes.reduce((a, b) => a + b.scores[sI], 0);
3230
+ return scoreSum;
3231
+ });
3232
+ return scores;
3233
+ });
3234
+ }
3235
+ getScoresTotal() {
3236
+ return this.votes.reduce((a, b) => a + b.balance, 0);
3237
+ }
3238
+ getChoiceString() {
3239
+ return this.proposal.choices[this.selected - 1];
3240
+ }
3241
+ }
3162
3242
 
3163
- var ApprovalVoting = /** @class */ (function () {
3164
- function ApprovalVoting(proposal, votes, strategies, selected) {
3165
- this.proposal = proposal;
3166
- this.votes = votes;
3167
- this.strategies = strategies;
3168
- this.selected = selected;
3169
- }
3170
- ApprovalVoting.isValidChoice = function (voteChoice, proposalChoices) {
3171
- return (Array.isArray(voteChoice) &&
3172
- // If voteChoice index is not in proposalChoices, return false
3173
- voteChoice.every(function (choice) { return (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[choice - 1]) !== undefined; }) &&
3174
- // If any voteChoice is duplicated, return false
3175
- voteChoice.length === new Set(voteChoice).size);
3176
- };
3177
- ApprovalVoting.prototype.getValidVotes = function () {
3178
- var _this = this;
3179
- return this.votes.filter(function (vote) {
3180
- return ApprovalVoting.isValidChoice(vote.choice, _this.proposal.choices);
3181
- });
3182
- };
3183
- ApprovalVoting.prototype.getScores = function () {
3184
- var _this = this;
3185
- return this.proposal.choices.map(function (choice, i) {
3186
- return _this.getValidVotes()
3187
- .filter(function (vote) { return vote.choice.includes(i + 1); })
3188
- .reduce(function (a, b) { return a + b.balance; }, 0);
3189
- });
3190
- };
3191
- ApprovalVoting.prototype.getScoresByStrategy = function () {
3192
- var _this = this;
3193
- return this.proposal.choices.map(function (choice, i) {
3194
- return _this.strategies.map(function (strategy, sI) {
3195
- return _this.getValidVotes()
3196
- .filter(function (vote) { return vote.choice.includes(i + 1); })
3197
- .reduce(function (a, b) { return a + b.scores[sI]; }, 0);
3198
- });
3199
- });
3200
- };
3201
- ApprovalVoting.prototype.getScoresTotal = function () {
3202
- return this.votes.reduce(function (a, b) { return a + b.balance; }, 0);
3203
- };
3204
- ApprovalVoting.prototype.getChoiceString = function () {
3205
- var _this = this;
3206
- if (!this.selected)
3207
- return '';
3208
- return this.proposal.choices
3209
- .filter(function (choice, i) { return _this.selected.includes(i + 1); })
3210
- .join(', ');
3211
- };
3212
- return ApprovalVoting;
3213
- }());
3243
+ class ApprovalVoting {
3244
+ constructor(proposal, votes, strategies, selected) {
3245
+ this.proposal = proposal;
3246
+ this.votes = votes;
3247
+ this.strategies = strategies;
3248
+ this.selected = selected;
3249
+ }
3250
+ static isValidChoice(voteChoice, proposalChoices) {
3251
+ return (Array.isArray(voteChoice) &&
3252
+ // If voteChoice index is not in proposalChoices, return false
3253
+ voteChoice.every((choice) => (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[choice - 1]) !== undefined) &&
3254
+ // If any voteChoice is duplicated, return false
3255
+ voteChoice.length === new Set(voteChoice).size);
3256
+ }
3257
+ getValidVotes() {
3258
+ return this.votes.filter((vote) => ApprovalVoting.isValidChoice(vote.choice, this.proposal.choices));
3259
+ }
3260
+ getScores() {
3261
+ return this.proposal.choices.map((choice, i) => this.getValidVotes()
3262
+ .filter((vote) => vote.choice.includes(i + 1))
3263
+ .reduce((a, b) => a + b.balance, 0));
3264
+ }
3265
+ getScoresByStrategy() {
3266
+ return this.proposal.choices.map((choice, i) => this.strategies.map((strategy, sI) => this.getValidVotes()
3267
+ .filter((vote) => vote.choice.includes(i + 1))
3268
+ .reduce((a, b) => a + b.scores[sI], 0)));
3269
+ }
3270
+ getScoresTotal() {
3271
+ return this.votes.reduce((a, b) => a + b.balance, 0);
3272
+ }
3273
+ getChoiceString() {
3274
+ if (!this.selected)
3275
+ return '';
3276
+ return this.proposal.choices
3277
+ .filter((choice, i) => this.selected.includes(i + 1))
3278
+ .join(', ');
3279
+ }
3280
+ }
3214
3281
 
3215
- function calcPercentageOfSum(part, wholeArray) {
3216
- var whole = wholeArray.reduce(function (a, b) { return a + b; }, 0);
3217
- var percent = part / whole;
3218
- return isNaN(percent) ? 0 : percent;
3219
- }
3220
- function calcSqrt(percentageWeight, votingPower) {
3221
- return Math.sqrt(percentageWeight * votingPower);
3222
- }
3223
- function calcSquare(num) {
3224
- return num * num;
3225
- }
3226
- function calcReducedQuadraticScores(percentages, scoresTotal) {
3227
- // Reduce each quadratic score so that the sum of quadratic scores matches
3228
- // the total scores.
3229
- // This is done to unsure that features like quorum still work as expected.
3230
- return percentages.map(function (p) { return scoresTotal * p; });
3231
- }
3232
- var QuadraticVoting = /** @class */ (function () {
3233
- function QuadraticVoting(proposal, votes, strategies, selected) {
3234
- this.proposal = proposal;
3235
- this.votes = votes;
3236
- this.strategies = strategies;
3237
- this.selected = selected;
3238
- }
3239
- QuadraticVoting.isValidChoice = function (voteChoice, proposalChoices) {
3240
- return (typeof voteChoice === 'object' &&
3241
- !Array.isArray(voteChoice) &&
3242
- voteChoice !== null &&
3243
- // If voteChoice object keys are not in choices, return false
3244
- Object.keys(voteChoice).every(function (key) { return (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[Number(key) - 1]) !== undefined; }) &&
3245
- // If voteChoice object is empty, return false
3246
- Object.keys(voteChoice).length > 0 &&
3247
- // If voteChoice object values have a negative number, return false
3248
- Object.values(voteChoice).every(function (value) { return typeof value === 'number' && value >= 0; }) &&
3249
- // If voteChoice doesn't have any positive value, return false
3250
- Object.values(voteChoice).some(function (value) { return typeof value === 'number' && value > 0; }));
3251
- };
3252
- QuadraticVoting.prototype.getValidVotes = function () {
3253
- var _this = this;
3254
- return this.votes.filter(function (vote) {
3255
- return QuadraticVoting.isValidChoice(vote.choice, _this.proposal.choices);
3256
- });
3257
- };
3258
- QuadraticVoting.prototype.getScores = function () {
3259
- var validVotes = this.getValidVotes();
3260
- var scoresTotal = this.getValidVotes().reduce(function (a, b) { return a + b.balance; }, 0);
3261
- var quadraticScores = this.proposal.choices.map(function (_, i) {
3262
- var votingPowerSqrt = validVotes
3263
- .map(function (vote) {
3264
- var choiceWeightPercent = calcPercentageOfSum(vote.choice[i + 1], Object.values(vote.choice));
3265
- return calcSqrt(choiceWeightPercent, vote.balance);
3266
- })
3267
- .reduce(function (a, b) { return a + b; }, 0);
3268
- return calcSquare(votingPowerSqrt);
3269
- });
3270
- var percentagesOfScores = quadraticScores.map(function (_, i) {
3271
- return calcPercentageOfSum(quadraticScores[i], quadraticScores);
3272
- });
3273
- return calcReducedQuadraticScores(percentagesOfScores, scoresTotal);
3274
- };
3275
- QuadraticVoting.prototype.getScoresByStrategy = function () {
3276
- var _this = this;
3277
- var validVotes = this.getValidVotes();
3278
- var scoresTotal = this.getValidVotes().reduce(function (a, b) { return a + b.balance; }, 0);
3279
- var quadraticScoresByStrategy = this.proposal.choices
3280
- .map(function (_, i) {
3281
- return _this.strategies.map(function (_, sI) {
3282
- return validVotes
3283
- .map(function (vote) {
3284
- var choiceWeightPercentByStrategy = calcPercentageOfSum(vote.choice[i + 1], Object.values(vote.choice));
3285
- return calcSqrt(choiceWeightPercentByStrategy, vote.scores[sI]);
3286
- })
3287
- .reduce(function (a, b) { return a + b; }, 0);
3288
- });
3289
- })
3290
- .map(function (arr) { return arr.map(function (num) { return [calcSquare(num)]; }); });
3291
- var reducedQuadraticScores = quadraticScoresByStrategy.map(function (_, i) {
3292
- var percentagesOfScores = _this.strategies.map(function (_, sI) {
3293
- return calcPercentageOfSum(quadraticScoresByStrategy[i][sI][0], quadraticScoresByStrategy.flat(2));
3294
- });
3295
- return calcReducedQuadraticScores(percentagesOfScores, scoresTotal);
3296
- });
3297
- return reducedQuadraticScores;
3298
- };
3299
- QuadraticVoting.prototype.getScoresTotal = function () {
3300
- return this.votes.reduce(function (a, b) { return a + b.balance; }, 0);
3301
- };
3302
- QuadraticVoting.prototype.getChoiceString = function () {
3303
- var _this = this;
3304
- return this.proposal.choices
3305
- .map(function (choice, i) {
3306
- if (_this.selected[i + 1]) {
3307
- var percent = calcPercentageOfSum(_this.selected[i + 1], Object.values(_this.selected));
3308
- return Math.round(percent * 1000) / 10 + "% for " + choice;
3309
- }
3310
- })
3311
- .filter(function (el) { return el != null; })
3312
- .join(', ');
3313
- };
3314
- return QuadraticVoting;
3315
- }());
3282
+ function calcPercentageOfSum(part, wholeArray) {
3283
+ const whole = wholeArray.reduce((a, b) => a + b, 0);
3284
+ const percent = part / whole;
3285
+ return isNaN(percent) ? 0 : percent;
3286
+ }
3287
+ function calcSqrt(percentageWeight, votingPower) {
3288
+ return Math.sqrt(percentageWeight * votingPower);
3289
+ }
3290
+ function calcSquare(num) {
3291
+ return num * num;
3292
+ }
3293
+ function calcReducedQuadraticScores(percentages, scoresTotal) {
3294
+ // Reduce each quadratic score so that the sum of quadratic scores matches
3295
+ // the total scores.
3296
+ // This is done to unsure that features like quorum still work as expected.
3297
+ return percentages.map((p) => scoresTotal * p);
3298
+ }
3299
+ class QuadraticVoting {
3300
+ constructor(proposal, votes, strategies, selected) {
3301
+ this.proposal = proposal;
3302
+ this.votes = votes;
3303
+ this.strategies = strategies;
3304
+ this.selected = selected;
3305
+ }
3306
+ static isValidChoice(voteChoice, proposalChoices) {
3307
+ return (typeof voteChoice === 'object' &&
3308
+ !Array.isArray(voteChoice) &&
3309
+ voteChoice !== null &&
3310
+ // If voteChoice object keys are not in choices, return false
3311
+ Object.keys(voteChoice).every((key) => (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[Number(key) - 1]) !== undefined) &&
3312
+ // If voteChoice object is empty, return false
3313
+ Object.keys(voteChoice).length > 0 &&
3314
+ // If voteChoice object values have a negative number, return false
3315
+ Object.values(voteChoice).every((value) => typeof value === 'number' && value >= 0) &&
3316
+ // If voteChoice doesn't have any positive value, return false
3317
+ Object.values(voteChoice).some((value) => typeof value === 'number' && value > 0));
3318
+ }
3319
+ getValidVotes() {
3320
+ return this.votes.filter((vote) => QuadraticVoting.isValidChoice(vote.choice, this.proposal.choices));
3321
+ }
3322
+ getScores() {
3323
+ const validVotes = this.getValidVotes();
3324
+ const scoresTotal = this.getValidVotes().reduce((a, b) => a + b.balance, 0);
3325
+ const quadraticScores = this.proposal.choices.map((_, i) => {
3326
+ const votingPowerSqrt = validVotes
3327
+ .map((vote) => {
3328
+ const choiceWeightPercent = calcPercentageOfSum(vote.choice[i + 1], Object.values(vote.choice));
3329
+ return calcSqrt(choiceWeightPercent, vote.balance);
3330
+ })
3331
+ .reduce((a, b) => a + b, 0);
3332
+ return calcSquare(votingPowerSqrt);
3333
+ });
3334
+ const percentagesOfScores = quadraticScores.map((_, i) => calcPercentageOfSum(quadraticScores[i], quadraticScores));
3335
+ return calcReducedQuadraticScores(percentagesOfScores, scoresTotal);
3336
+ }
3337
+ getScoresByStrategy() {
3338
+ const validVotes = this.getValidVotes();
3339
+ const scoresTotal = this.getValidVotes().reduce((a, b) => a + b.balance, 0);
3340
+ const quadraticScoresByStrategy = this.proposal.choices
3341
+ .map((_, i) => this.strategies.map((_, sI) => validVotes
3342
+ .map((vote) => {
3343
+ const choiceWeightPercentByStrategy = calcPercentageOfSum(vote.choice[i + 1], Object.values(vote.choice));
3344
+ return calcSqrt(choiceWeightPercentByStrategy, vote.scores[sI]);
3345
+ })
3346
+ .reduce((a, b) => a + b, 0)))
3347
+ .map((arr) => arr.map((num) => [calcSquare(num)]));
3348
+ const reducedQuadraticScores = quadraticScoresByStrategy.map((_, i) => {
3349
+ const percentagesOfScores = this.strategies.map((_, sI) => calcPercentageOfSum(quadraticScoresByStrategy[i][sI][0], quadraticScoresByStrategy.flat(2)));
3350
+ return calcReducedQuadraticScores(percentagesOfScores, scoresTotal);
3351
+ });
3352
+ return reducedQuadraticScores;
3353
+ }
3354
+ getScoresTotal() {
3355
+ return this.votes.reduce((a, b) => a + b.balance, 0);
3356
+ }
3357
+ getChoiceString() {
3358
+ return this.proposal.choices
3359
+ .map((choice, i) => {
3360
+ if (this.selected[i + 1]) {
3361
+ const percent = calcPercentageOfSum(this.selected[i + 1], Object.values(this.selected));
3362
+ return `${Math.round(percent * 1000) / 10}% for ${choice}`;
3363
+ }
3364
+ })
3365
+ .filter((el) => el != null)
3366
+ .join(', ');
3367
+ }
3368
+ }
3316
3369
 
3317
- function irv(ballots, rounds) {
3318
- var candidates = __spread(new Set(ballots.map(function (vote) { return vote[0]; }).flat()));
3319
- var votes = Object.entries(ballots.reduce(function (votes, _a, i, src) {
3320
- var _b = __read(_a, 1), v = _b[0];
3321
- var balance = src[i][1];
3322
- votes[v[0]][0] += balance;
3323
- var score = src[i][2];
3324
- if (score.length > 1) {
3325
- votes[v[0]][1] = score.map(function (s, sI) { return s + votes[v[0]][1][sI] || s; });
3326
- }
3327
- else
3328
- votes[v[0]][1] = [
3329
- votes[v[0]][1].concat(score).reduce(function (a, b) { return a + b; }, 0)
3330
- ];
3331
- return votes;
3332
- }, Object.assign.apply(Object, __spread([{}], candidates.map(function (c) {
3333
- var _a;
3334
- return (_a = {}, _a[c] = [0, []], _a);
3335
- })))));
3336
- var votesWithoutScore = votes.map(function (vote) { return [vote[0], vote[1][0]]; });
3337
- /* eslint-disable @typescript-eslint/no-unused-vars */
3338
- var _a = __read(votesWithoutScore.reduce(function (_a, _b) {
3339
- var _c = __read(_a, 2), n = _c[0], m = _c[1];
3340
- var _d = __read(_b, 2), v = _d[0], c = _d[1];
3341
- return (c > m ? [v, c] : [n, m]);
3342
- }, ['?', -Infinity]), 2), topCand = _a[0], topCount = _a[1];
3343
- var _b = __read(votesWithoutScore.reduce(function (_a, _b) {
3344
- var _c = __read(_a, 2), n = _c[0], m = _c[1];
3345
- var _d = __read(_b, 2), v = _d[0], c = _d[1];
3346
- return (c < m ? [v, c] : [n, m]);
3347
- }, ['?', Infinity]), 2), bottomCand = _b[0], bottomCount = _b[1];
3348
- /* eslint-enable @typescript-eslint/no-unused-vars */
3349
- var sortedByHighest = votes.sort(function (a, b) { return b[1][0] - a[1][0]; });
3350
- var totalPowerOfVotes = ballots
3351
- .map(function (bal) { return bal[1]; })
3352
- .reduce(function (a, b) { return a + b; }, 0);
3353
- rounds.push({
3354
- round: rounds.length + 1,
3355
- sortedByHighest: sortedByHighest
3356
- });
3357
- return topCount > totalPowerOfVotes / 2 ||
3358
- sortedByHighest.length < 3
3359
- ? rounds
3360
- : irv(ballots
3361
- .map(function (ballot) { return [
3362
- ballot[0].filter(function (c) { return c != bottomCand; }),
3363
- ballot[1],
3364
- ballot[2]
3365
- ]; })
3366
- .filter(function (ballot) { return ballot[0].length > 0; }), rounds);
3367
- }
3368
- function getFinalRound(votes) {
3369
- var rounds = irv(votes.map(function (vote) { return [vote.choice, vote.balance, vote.scores]; }), []);
3370
- var finalRound = rounds[rounds.length - 1];
3371
- return finalRound.sortedByHighest;
3372
- }
3373
- function getScoresMethod(votes, proposal) {
3374
- var finalRound = getFinalRound(votes);
3375
- return proposal.choices.map(function (choice, i) {
3376
- return finalRound
3377
- .filter(function (res) { return Number(res[0]) === i + 1; })
3378
- .reduce(function (a, b) { return a + b[1][0]; }, 0);
3379
- });
3380
- }
3381
- var RankedChoiceVoting = /** @class */ (function () {
3382
- function RankedChoiceVoting(proposal, votes, strategies, selected) {
3383
- this.proposal = proposal;
3384
- this.votes = votes;
3385
- this.strategies = strategies;
3386
- this.selected = selected;
3387
- }
3388
- RankedChoiceVoting.isValidChoice = function (voteChoice, proposalChoices) {
3389
- return (Array.isArray(voteChoice) &&
3390
- // If voteChoice index is not in choices, return false
3391
- voteChoice.every(function (voteChoice) { return (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[voteChoice - 1]) !== undefined; }) &&
3392
- // If any voteChoice is duplicated, return false
3393
- voteChoice.length === new Set(voteChoice).size &&
3394
- // If voteChoice is empty, return false
3395
- voteChoice.length > 0 &&
3396
- // If not all proposalChoices are selected, return false
3397
- // TODO: We should add support for pacial bailout in the future
3398
- voteChoice.length === proposalChoices.length);
3399
- };
3400
- RankedChoiceVoting.prototype.getValidVotes = function () {
3401
- var _this = this;
3402
- return this.votes.filter(function (vote) {
3403
- return RankedChoiceVoting.isValidChoice(vote.choice, _this.proposal.choices);
3404
- });
3405
- };
3406
- RankedChoiceVoting.prototype.getScores = function () {
3407
- return getScoresMethod(this.getValidVotes(), this.proposal);
3408
- };
3409
- RankedChoiceVoting.prototype.getScoresByStrategy = function () {
3410
- var _this = this;
3411
- var finalRound = getFinalRound(this.getValidVotes());
3412
- return this.proposal.choices.map(function (choice, i) {
3413
- return _this.strategies.map(function (strategy, sI) {
3414
- return finalRound
3415
- .filter(function (res) { return Number(res[0]) === i + 1; })
3416
- .reduce(function (a, b) { return a + b[1][1][sI]; }, 0);
3417
- });
3418
- });
3419
- };
3420
- RankedChoiceVoting.prototype.getScoresTotal = function () {
3421
- return this.votes.reduce(function (a, b) { return a + b.balance; }, 0);
3422
- };
3423
- RankedChoiceVoting.prototype.getChoiceString = function () {
3424
- var _this = this;
3425
- return this.selected
3426
- .map(function (choice) {
3427
- if (_this.proposal.choices[choice - 1])
3428
- return _this.proposal.choices[choice - 1];
3429
- })
3430
- .map(function (el, i) { return "(" + getNumberWithOrdinal(i + 1) + ") " + el; })
3431
- .join(', ');
3432
- };
3433
- return RankedChoiceVoting;
3434
- }());
3370
+ function irv(ballots, rounds) {
3371
+ const candidates = [
3372
+ ...new Set(ballots.map((vote) => vote[0]).flat())
3373
+ ];
3374
+ const votes = Object.entries(ballots.reduce((votes, [v], i, src) => {
3375
+ const balance = src[i][1];
3376
+ votes[v[0]][0] += balance;
3377
+ const score = src[i][2];
3378
+ if (score.length > 1) {
3379
+ votes[v[0]][1] = score.map((s, sI) => s + votes[v[0]][1][sI] || s);
3380
+ }
3381
+ else
3382
+ votes[v[0]][1] = [
3383
+ votes[v[0]][1].concat(score).reduce((a, b) => a + b, 0)
3384
+ ];
3385
+ return votes;
3386
+ }, Object.assign({}, ...candidates.map((c) => ({ [c]: [0, []] })))));
3387
+ const votesWithoutScore = votes.map((vote) => [vote[0], vote[1][0]]);
3388
+ /* eslint-disable @typescript-eslint/no-unused-vars */
3389
+ const [topCand, topCount] = votesWithoutScore.reduce(([n, m], [v, c]) => (c > m ? [v, c] : [n, m]), ['?', -Infinity]);
3390
+ const [bottomCand, bottomCount] = votesWithoutScore.reduce(([n, m], [v, c]) => (c < m ? [v, c] : [n, m]), ['?', Infinity]);
3391
+ /* eslint-enable @typescript-eslint/no-unused-vars */
3392
+ const sortedByHighest = votes.sort((a, b) => b[1][0] - a[1][0]);
3393
+ const totalPowerOfVotes = ballots
3394
+ .map((bal) => bal[1])
3395
+ .reduce((a, b) => a + b, 0);
3396
+ rounds.push({
3397
+ round: rounds.length + 1,
3398
+ sortedByHighest
3399
+ });
3400
+ return topCount > totalPowerOfVotes / 2 ||
3401
+ sortedByHighest.length < 3
3402
+ ? rounds
3403
+ : irv(ballots
3404
+ .map((ballot) => [
3405
+ ballot[0].filter((c) => c != bottomCand),
3406
+ ballot[1],
3407
+ ballot[2]
3408
+ ])
3409
+ .filter((ballot) => ballot[0].length > 0), rounds);
3410
+ }
3411
+ function getFinalRound(votes) {
3412
+ const rounds = irv(votes.map((vote) => [vote.choice, vote.balance, vote.scores]), []);
3413
+ const finalRound = rounds[rounds.length - 1];
3414
+ return finalRound.sortedByHighest;
3415
+ }
3416
+ function getScoresMethod(votes, proposal) {
3417
+ const finalRound = getFinalRound(votes);
3418
+ return proposal.choices.map((choice, i) => finalRound
3419
+ .filter((res) => Number(res[0]) === i + 1)
3420
+ .reduce((a, b) => a + b[1][0], 0));
3421
+ }
3422
+ class RankedChoiceVoting {
3423
+ constructor(proposal, votes, strategies, selected) {
3424
+ this.proposal = proposal;
3425
+ this.votes = votes;
3426
+ this.strategies = strategies;
3427
+ this.selected = selected;
3428
+ }
3429
+ static isValidChoice(voteChoice, proposalChoices) {
3430
+ return (Array.isArray(voteChoice) &&
3431
+ // If voteChoice index is not in choices, return false
3432
+ voteChoice.every((voteChoice) => (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[voteChoice - 1]) !== undefined) &&
3433
+ // If any voteChoice is duplicated, return false
3434
+ voteChoice.length === new Set(voteChoice).size &&
3435
+ // If voteChoice is empty, return false
3436
+ voteChoice.length > 0 &&
3437
+ // If not all proposalChoices are selected, return false
3438
+ // TODO: We should add support for pacial bailout in the future
3439
+ voteChoice.length === proposalChoices.length);
3440
+ }
3441
+ getValidVotes() {
3442
+ return this.votes.filter((vote) => RankedChoiceVoting.isValidChoice(vote.choice, this.proposal.choices));
3443
+ }
3444
+ getScores() {
3445
+ return getScoresMethod(this.getValidVotes(), this.proposal);
3446
+ }
3447
+ getScoresByStrategy() {
3448
+ const finalRound = getFinalRound(this.getValidVotes());
3449
+ return this.proposal.choices.map((choice, i) => this.strategies.map((strategy, sI) => {
3450
+ return finalRound
3451
+ .filter((res) => Number(res[0]) === i + 1)
3452
+ .reduce((a, b) => a + b[1][1][sI], 0);
3453
+ }));
3454
+ }
3455
+ getScoresTotal() {
3456
+ return this.votes.reduce((a, b) => a + b.balance, 0);
3457
+ }
3458
+ getChoiceString() {
3459
+ return this.selected
3460
+ .map((choice) => {
3461
+ if (this.proposal.choices[choice - 1])
3462
+ return this.proposal.choices[choice - 1];
3463
+ })
3464
+ .map((el, i) => `(${getNumberWithOrdinal(i + 1)}) ${el}`)
3465
+ .join(', ');
3466
+ }
3467
+ }
3435
3468
 
3436
- function percentageOfTotal(i, values, total) {
3437
- var reducedTotal = total.reduce(function (a, b) { return a + b; }, 0);
3438
- var percent = (values[i] / reducedTotal) * 100;
3439
- return isNaN(percent) ? 0 : percent;
3440
- }
3441
- function weightedPower(i, choice, balance) {
3442
- return ((percentageOfTotal(i + 1, choice, Object.values(choice)) / 100) * balance);
3443
- }
3444
- var WeightedVoting = /** @class */ (function () {
3445
- function WeightedVoting(proposal, votes, strategies, selected) {
3446
- this.proposal = proposal;
3447
- this.votes = votes;
3448
- this.strategies = strategies;
3449
- this.selected = selected;
3450
- }
3451
- WeightedVoting.isValidChoice = function (voteChoice, proposalChoices) {
3452
- return (typeof voteChoice === 'object' &&
3453
- !Array.isArray(voteChoice) &&
3454
- voteChoice !== null &&
3455
- // If voteChoice object keys are not in choices, return false
3456
- Object.keys(voteChoice).every(function (key) { return (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[Number(key) - 1]) !== undefined; }) &&
3457
- // If voteChoice object is empty, return false
3458
- Object.keys(voteChoice).length > 0 &&
3459
- // If voteChoice object values have a negative number, return false
3460
- Object.values(voteChoice).every(function (value) { return typeof value === 'number' && value >= 0; }) &&
3461
- // If voteChoice doesn't have any positive value, return false
3462
- Object.values(voteChoice).some(function (value) { return typeof value === 'number' && value > 0; }));
3463
- };
3464
- WeightedVoting.prototype.getValidVotes = function () {
3465
- var _this = this;
3466
- return this.votes.filter(function (vote) {
3467
- return WeightedVoting.isValidChoice(vote.choice, _this.proposal.choices);
3468
- });
3469
- };
3470
- WeightedVoting.prototype.getScores = function () {
3471
- var _this = this;
3472
- var results = this.proposal.choices.map(function (choice, i) {
3473
- return _this.getValidVotes()
3474
- .map(function (vote) { return weightedPower(i, vote.choice, vote.balance); })
3475
- .reduce(function (a, b) { return a + b; }, 0);
3476
- });
3477
- var validScoresTotal = this.getValidVotes().reduce(function (a, b) { return a + b.balance; }, 0);
3478
- return results
3479
- .map(function (res, i) { return percentageOfTotal(i, results, results); })
3480
- .map(function (p) { return (validScoresTotal / 100) * p; });
3481
- };
3482
- WeightedVoting.prototype.getScoresByStrategy = function () {
3483
- var _this = this;
3484
- var results = this.proposal.choices
3485
- .map(function (choice, i) {
3486
- return _this.strategies.map(function (strategy, sI) {
3487
- return _this.getValidVotes()
3488
- .map(function (vote) { return weightedPower(i, vote.choice, vote.scores[sI]); })
3489
- .reduce(function (a, b) { return a + b; }, 0);
3490
- });
3491
- })
3492
- .map(function (arr) { return arr.map(function (pwr) { return [pwr]; }); });
3493
- var validScoresTotal = this.getValidVotes().reduce(function (a, b) { return a + b.balance; }, 0);
3494
- return results.map(function (res, i) {
3495
- return _this.strategies
3496
- .map(function (strategy, sI) {
3497
- return percentageOfTotal(0, results[i][sI], results.flat(2));
3498
- })
3499
- .map(function (p) { return [(validScoresTotal / 100) * p]; })
3500
- .flat();
3501
- });
3502
- };
3503
- WeightedVoting.prototype.getScoresTotal = function () {
3504
- return this.votes.reduce(function (a, b) { return a + b.balance; }, 0);
3505
- };
3506
- WeightedVoting.prototype.getChoiceString = function () {
3507
- var _this = this;
3508
- return this.proposal.choices
3509
- .map(function (choice, i) {
3510
- if (_this.selected[i + 1]) {
3511
- return Math.round(percentageOfTotal(i + 1, _this.selected, Object.values(_this.selected)) * 10) / 10 + "% for " + choice;
3512
- }
3513
- })
3514
- .filter(function (el) { return el != null; })
3515
- .join(', ');
3516
- };
3517
- return WeightedVoting;
3518
- }());
3469
+ function percentageOfTotal(i, values, total) {
3470
+ const reducedTotal = total.reduce((a, b) => a + b, 0);
3471
+ const percent = (values[i] / reducedTotal) * 100;
3472
+ return isNaN(percent) ? 0 : percent;
3473
+ }
3474
+ function weightedPower(i, choice, balance) {
3475
+ return ((percentageOfTotal(i + 1, choice, Object.values(choice)) / 100) * balance);
3476
+ }
3477
+ class WeightedVoting {
3478
+ constructor(proposal, votes, strategies, selected) {
3479
+ this.proposal = proposal;
3480
+ this.votes = votes;
3481
+ this.strategies = strategies;
3482
+ this.selected = selected;
3483
+ }
3484
+ static isValidChoice(voteChoice, proposalChoices) {
3485
+ return (typeof voteChoice === 'object' &&
3486
+ !Array.isArray(voteChoice) &&
3487
+ voteChoice !== null &&
3488
+ // If voteChoice object keys are not in choices, return false
3489
+ Object.keys(voteChoice).every((key) => (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[Number(key) - 1]) !== undefined) &&
3490
+ // If voteChoice object is empty, return false
3491
+ Object.keys(voteChoice).length > 0 &&
3492
+ // If voteChoice object values have a negative number, return false
3493
+ Object.values(voteChoice).every((value) => typeof value === 'number' && value >= 0) &&
3494
+ // If voteChoice doesn't have any positive value, return false
3495
+ Object.values(voteChoice).some((value) => typeof value === 'number' && value > 0));
3496
+ }
3497
+ getValidVotes() {
3498
+ return this.votes.filter((vote) => WeightedVoting.isValidChoice(vote.choice, this.proposal.choices));
3499
+ }
3500
+ getScores() {
3501
+ const results = this.proposal.choices.map((choice, i) => this.getValidVotes()
3502
+ .map((vote) => weightedPower(i, vote.choice, vote.balance))
3503
+ .reduce((a, b) => a + b, 0));
3504
+ const validScoresTotal = this.getValidVotes().reduce((a, b) => a + b.balance, 0);
3505
+ return results
3506
+ .map((res, i) => percentageOfTotal(i, results, results))
3507
+ .map((p) => (validScoresTotal / 100) * p);
3508
+ }
3509
+ getScoresByStrategy() {
3510
+ const results = this.proposal.choices
3511
+ .map((choice, i) => this.strategies.map((strategy, sI) => this.getValidVotes()
3512
+ .map((vote) => weightedPower(i, vote.choice, vote.scores[sI]))
3513
+ .reduce((a, b) => a + b, 0)))
3514
+ .map((arr) => arr.map((pwr) => [pwr]));
3515
+ const validScoresTotal = this.getValidVotes().reduce((a, b) => a + b.balance, 0);
3516
+ return results.map((res, i) => this.strategies
3517
+ .map((strategy, sI) => percentageOfTotal(0, results[i][sI], results.flat(2)))
3518
+ .map((p) => [(validScoresTotal / 100) * p])
3519
+ .flat());
3520
+ }
3521
+ getScoresTotal() {
3522
+ return this.votes.reduce((a, b) => a + b.balance, 0);
3523
+ }
3524
+ getChoiceString() {
3525
+ return this.proposal.choices
3526
+ .map((choice, i) => {
3527
+ if (this.selected[i + 1]) {
3528
+ return `${Math.round(percentageOfTotal(i + 1, this.selected, Object.values(this.selected)) * 10) / 10}% for ${choice}`;
3529
+ }
3530
+ })
3531
+ .filter((el) => el != null)
3532
+ .join(', ');
3533
+ }
3534
+ }
3519
3535
 
3520
- var voting = {
3521
- 'single-choice': SingleChoiceVoting,
3522
- approval: ApprovalVoting,
3523
- quadratic: QuadraticVoting,
3524
- 'ranked-choice': RankedChoiceVoting,
3525
- weighted: WeightedVoting,
3526
- basic: SingleChoiceVoting
3536
+ var voting = {
3537
+ 'single-choice': SingleChoiceVoting,
3538
+ approval: ApprovalVoting,
3539
+ quadratic: QuadraticVoting,
3540
+ 'ranked-choice': RankedChoiceVoting,
3541
+ weighted: WeightedVoting,
3542
+ basic: SingleChoiceVoting
3527
3543
  };
3528
3544
 
3529
3545
  var delegationSubgraphs = {
3530
- "1": "https://subgrapher.snapshot.org/gateway-arbitrum.network.thegraph.com/api/0f15b42bdeff7a063a4e1757d7e2f99e/subgraphs/id/4YgtogVaqoM8CErHWDK8mKQ825BcVdKB8vBYmb4avAQo",
3531
- "5": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-goerli",
3532
- "10": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-optimism",
3533
- "56": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-binance-smart-chain",
3534
- "100": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-gnosis-chain",
3535
- "137": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-polygon",
3536
- "250": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-fantom",
3537
- "42161": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-arbitrum"
3546
+ "1": "https://subgrapher.snapshot.org/delegation/1",
3547
+ "10": "https://subgrapher.snapshot.org/delegation/10",
3548
+ "56": "https://subgrapher.snapshot.org/delegation/56",
3549
+ "100": "https://subgrapher.snapshot.org/delegation/100",
3550
+ "137": "https://subgrapher.snapshot.org/delegation/137",
3551
+ "250": "https://subgrapher.snapshot.org/delegation/250",
3552
+ "42161": "https://subgrapher.snapshot.org/delegation/42161",
3553
+ "11155111": "https://subgrapher.snapshot.org/delegation/11155111"
3538
3554
  };
3539
3555
 
3540
- var SNAPSHOT_SUBGRAPH_URL = delegationSubgraphs;
3541
- var PAGE_SIZE = 1000;
3542
- function getDelegatesBySpace(network, space, snapshot, options) {
3543
- if (snapshot === void 0) { snapshot = 'latest'; }
3544
- if (options === void 0) { options = {}; }
3545
- return __awaiter(this, void 0, void 0, function () {
3546
- var subgraphUrl, pivot, result, spaceIn, newResults;
3547
- return __generator(this, function (_a) {
3548
- switch (_a.label) {
3549
- case 0:
3550
- subgraphUrl = options.subgraphUrl || SNAPSHOT_SUBGRAPH_URL[network];
3551
- if (!subgraphUrl) {
3552
- return [2 /*return*/, Promise.reject("Delegation subgraph not available for network " + network)];
3553
- }
3554
- pivot = 0;
3555
- result = new Map();
3556
- spaceIn = buildSpaceIn(space);
3557
- _a.label = 1;
3558
- case 1:
3559
- return [4 /*yield*/, fetchData({
3560
- url: subgraphUrl,
3561
- spaces: spaceIn,
3562
- pivot: pivot,
3563
- snapshot: snapshot
3564
- })];
3565
- case 2:
3566
- newResults = _a.sent();
3567
- if (checkAllDuplicates(newResults)) {
3568
- throw new Error('Unable to paginate delegation');
3569
- }
3570
- newResults.forEach(function (delegation) {
3571
- concatUniqueDelegation(result, delegation);
3572
- pivot = delegation.timestamp;
3573
- });
3574
- if (newResults.length < PAGE_SIZE)
3575
- return [3 /*break*/, 3];
3576
- return [3 /*break*/, 1];
3577
- case 3: return [2 /*return*/, __spread(result.values())];
3578
- }
3579
- });
3580
- });
3581
- }
3582
- function checkAllDuplicates(delegations) {
3583
- return (delegations.length === PAGE_SIZE &&
3584
- delegations[0].timestamp === delegations[delegations.length - 1].timestamp);
3585
- }
3586
- function delegationKey(delegation) {
3587
- return delegation.delegator + "-" + delegation.delegate + "-" + delegation.space;
3588
- }
3589
- function concatUniqueDelegation(result, delegation) {
3590
- var key = delegationKey(delegation);
3591
- if (!result.has(key)) {
3592
- result.set(key, delegation);
3593
- }
3594
- }
3595
- function buildSpaceIn(space) {
3596
- var spaces = ['', space];
3597
- if (space.includes('.eth'))
3598
- spaces.push(space.replace('.eth', ''));
3599
- return spaces;
3600
- }
3601
- function fetchData(_a) {
3602
- var url = _a.url, spaces = _a.spaces, pivot = _a.pivot, snapshot = _a.snapshot;
3603
- return __awaiter(this, void 0, void 0, function () {
3604
- var params;
3605
- return __generator(this, function (_b) {
3606
- switch (_b.label) {
3607
- case 0:
3608
- params = {
3609
- delegations: {
3610
- __args: {
3611
- where: {
3612
- space_in: spaces,
3613
- timestamp_gte: pivot
3614
- },
3615
- first: PAGE_SIZE,
3616
- skip: 0,
3617
- orderBy: 'timestamp',
3618
- orderDirection: 'asc'
3619
- },
3620
- delegator: true,
3621
- space: true,
3622
- delegate: true,
3623
- timestamp: true
3624
- }
3625
- };
3626
- if (snapshot !== 'latest') {
3627
- params.delegations.__args.block = { number: snapshot };
3628
- }
3629
- return [4 /*yield*/, subgraphRequest(url, params)];
3630
- case 1: return [2 /*return*/, (_b.sent()).delegations || []];
3631
- }
3632
- });
3633
- });
3556
+ const SNAPSHOT_SUBGRAPH_URL = delegationSubgraphs;
3557
+ const PAGE_SIZE = 1000;
3558
+ function getDelegatesBySpace(network_1, space_1) {
3559
+ return __awaiter(this, arguments, void 0, function* (network, space, snapshot = 'latest', options = {}) {
3560
+ const subgraphUrl = options.subgraphUrl || SNAPSHOT_SUBGRAPH_URL[network];
3561
+ if (!subgraphUrl) {
3562
+ return Promise.reject(`Delegation subgraph not available for network ${network}`);
3563
+ }
3564
+ let pivot = 0;
3565
+ const result = new Map();
3566
+ const spaceIn = buildSpaceIn(space);
3567
+ while (true) {
3568
+ const newResults = yield fetchData({
3569
+ url: subgraphUrl,
3570
+ spaces: spaceIn,
3571
+ pivot,
3572
+ snapshot
3573
+ });
3574
+ if (checkAllDuplicates(newResults)) {
3575
+ throw new Error('Unable to paginate delegation');
3576
+ }
3577
+ newResults.forEach((delegation) => {
3578
+ concatUniqueDelegation(result, delegation);
3579
+ pivot = delegation.timestamp;
3580
+ });
3581
+ if (newResults.length < PAGE_SIZE)
3582
+ break;
3583
+ }
3584
+ return [...result.values()];
3585
+ });
3586
+ }
3587
+ function checkAllDuplicates(delegations) {
3588
+ return (delegations.length === PAGE_SIZE &&
3589
+ delegations[0].timestamp === delegations[delegations.length - 1].timestamp);
3590
+ }
3591
+ function delegationKey(delegation) {
3592
+ return `${delegation.delegator}-${delegation.delegate}-${delegation.space}`;
3593
+ }
3594
+ function concatUniqueDelegation(result, delegation) {
3595
+ const key = delegationKey(delegation);
3596
+ if (!result.has(key)) {
3597
+ result.set(key, delegation);
3598
+ }
3599
+ }
3600
+ function buildSpaceIn(space) {
3601
+ const spaces = ['', space];
3602
+ if (space.includes('.eth'))
3603
+ spaces.push(space.replace('.eth', ''));
3604
+ return spaces;
3605
+ }
3606
+ function fetchData(_a) {
3607
+ return __awaiter(this, arguments, void 0, function* ({ url, spaces, pivot, snapshot }) {
3608
+ const params = {
3609
+ delegations: {
3610
+ __args: {
3611
+ where: {
3612
+ space_in: spaces,
3613
+ timestamp_gte: pivot
3614
+ },
3615
+ first: PAGE_SIZE,
3616
+ skip: 0,
3617
+ orderBy: 'timestamp',
3618
+ orderDirection: 'asc'
3619
+ },
3620
+ delegator: true,
3621
+ space: true,
3622
+ delegate: true,
3623
+ timestamp: true
3624
+ }
3625
+ };
3626
+ if (snapshot !== 'latest') {
3627
+ params.delegations.__args.block = { number: snapshot };
3628
+ }
3629
+ return (yield subgraphRequest(url, params)).delegations || [];
3630
+ });
3634
3631
  }
3635
3632
 
3636
- var ENS_RESOLVER_ABI = [
3637
- 'function text(bytes32 node, string calldata key) external view returns (string memory)'
3638
- ];
3639
- var EMPTY_ADDRESS = '0x0000000000000000000000000000000000000000';
3640
- var scoreApiHeaders = {
3641
- Accept: 'application/json',
3642
- 'Content-Type': 'application/json'
3643
- };
3644
- var ajv = new Ajv__default['default']({
3645
- allErrors: true,
3646
- allowUnionTypes: true,
3647
- $data: true,
3648
- passContext: true
3649
- });
3650
- // @ts-ignore
3651
- addFormats__default['default'](ajv);
3652
- addErrors__default['default'](ajv);
3653
- ajv.addFormat('address', {
3654
- validate: function (value) {
3655
- try {
3656
- return address.isAddress(value);
3657
- }
3658
- catch (err) {
3659
- return false;
3660
- }
3661
- }
3662
- });
3663
- ajv.addFormat('long', {
3664
- validate: function () { return true; }
3665
- });
3666
- ajv.addFormat('ethValue', {
3667
- validate: function (value) {
3668
- if (!value.match(/^([0-9]|[1-9][0-9]+)(\.[0-9]+)?$/))
3669
- return false;
3670
- try {
3671
- units.parseUnits(value, 18);
3672
- return true;
3673
- }
3674
- catch (_a) {
3675
- return false;
3676
- }
3677
- }
3678
- });
3679
- var networksIds = Object.keys(networks);
3680
- var mainnetNetworkIds = Object.keys(networks).filter(function (id) { return !networks[id].testnet; });
3681
- ajv.addKeyword({
3682
- keyword: 'snapshotNetwork',
3683
- validate: function (schema, data) {
3684
- // @ts-ignore
3685
- var snapshotEnv = this.snapshotEnv || 'default';
3686
- if (snapshotEnv === 'mainnet')
3687
- return mainnetNetworkIds.includes(data);
3688
- return networksIds.includes(data);
3689
- },
3690
- error: {
3691
- message: 'network not allowed'
3692
- }
3693
- });
3694
- ajv.addKeyword({
3695
- keyword: 'maxLengthWithSpaceType',
3696
- validate: function validate(schema, data) {
3697
- // @ts-ignore
3698
- var spaceType = this.spaceType || 'default';
3699
- var isValid = data.length <= schema[spaceType];
3700
- if (!isValid) {
3701
- // @ts-ignore
3702
- validate.errors = [
3703
- {
3704
- keyword: 'maxLengthWithSpaceType',
3705
- message: "must NOT have more than " + schema[spaceType] + " characters",
3706
- params: { limit: schema[spaceType] }
3707
- }
3708
- ];
3709
- }
3710
- return isValid;
3711
- },
3712
- errors: true
3713
- });
3714
- ajv.addKeyword({
3715
- keyword: 'maxItemsWithSpaceType',
3716
- validate: function validate(schema, data) {
3717
- // @ts-ignore
3718
- var spaceType = this.spaceType || 'default';
3719
- var isValid = data.length <= schema[spaceType];
3720
- if (!isValid) {
3721
- // @ts-ignore
3722
- validate.errors = [
3723
- {
3724
- keyword: 'maxItemsWithSpaceType',
3725
- message: "must NOT have more than " + schema[spaceType] + " items",
3726
- params: { limit: schema[spaceType] }
3727
- }
3728
- ];
3729
- }
3730
- return isValid;
3731
- },
3732
- errors: true
3733
- });
3734
- // Custom URL format to allow empty string values
3735
- // https://github.com/snapshot-labs/snapshot.js/pull/541/files
3736
- ajv.addFormat('customUrl', {
3737
- type: 'string',
3738
- validate: function (str) {
3739
- if (!str.length)
3740
- return true;
3741
- return (str.startsWith('http://') ||
3742
- str.startsWith('https://') ||
3743
- str.startsWith('ipfs://') ||
3744
- str.startsWith('ipns://') ||
3745
- str.startsWith('snapshot://'));
3746
- }
3747
- });
3748
- function call(provider, abi, call, options) {
3749
- return __awaiter(this, void 0, void 0, function () {
3750
- var contract, params, e_1;
3751
- return __generator(this, function (_a) {
3752
- switch (_a.label) {
3753
- case 0:
3754
- contract = new contracts.Contract(call[0], abi, provider);
3755
- _a.label = 1;
3756
- case 1:
3757
- _a.trys.push([1, 3, , 4]);
3758
- params = call[2] || [];
3759
- return [4 /*yield*/, contract[call[1]].apply(contract, __spread(params, [options || {}]))];
3760
- case 2: return [2 /*return*/, _a.sent()];
3761
- case 3:
3762
- e_1 = _a.sent();
3763
- return [2 /*return*/, Promise.reject(e_1)];
3764
- case 4: return [2 /*return*/];
3765
- }
3766
- });
3767
- });
3768
- }
3769
- function multicall(network, provider, abi$1, calls, options) {
3770
- return __awaiter(this, void 0, void 0, function () {
3771
- var multicallAbi, multicallAddress, multi, itf, max_1, pages, promises_1, results, e_2;
3772
- return __generator(this, function (_a) {
3773
- switch (_a.label) {
3774
- case 0:
3775
- multicallAbi = [
3776
- 'function aggregate(tuple(address target, bytes callData)[] calls) view returns (uint256 blockNumber, bytes[] returnData)'
3777
- ];
3778
- multicallAddress = (options === null || options === void 0 ? void 0 : options.multicallAddress) || networks[network].multicall;
3779
- multi = new contracts.Contract(multicallAddress, multicallAbi, provider);
3780
- itf = new abi.Interface(abi$1);
3781
- _a.label = 1;
3782
- case 1:
3783
- _a.trys.push([1, 3, , 4]);
3784
- max_1 = (options === null || options === void 0 ? void 0 : options.limit) || 500;
3785
- if (options === null || options === void 0 ? void 0 : options.limit)
3786
- delete options.limit;
3787
- pages = Math.ceil(calls.length / max_1);
3788
- promises_1 = [];
3789
- Array.from(Array(pages)).forEach(function (x, i) {
3790
- var callsInPage = calls.slice(max_1 * i, max_1 * (i + 1));
3791
- promises_1.push(multi.aggregate(callsInPage.map(function (call) { return [
3792
- call[0].toLowerCase(),
3793
- itf.encodeFunctionData(call[1], call[2])
3794
- ]; }), options || {}));
3795
- });
3796
- return [4 /*yield*/, Promise.all(promises_1)];
3797
- case 2:
3798
- results = _a.sent();
3799
- results = results.reduce(function (prev, _a) {
3800
- var _b = __read(_a, 2), res = _b[1];
3801
- return prev.concat(res);
3802
- }, []);
3803
- return [2 /*return*/, results.map(function (call, i) {
3804
- return itf.decodeFunctionResult(calls[i][1], call);
3805
- })];
3806
- case 3:
3807
- e_2 = _a.sent();
3808
- return [2 /*return*/, Promise.reject(e_2)];
3809
- case 4: return [2 /*return*/];
3810
- }
3811
- });
3812
- });
3813
- }
3814
- function subgraphRequest(url, query, options) {
3815
- if (options === void 0) { options = {}; }
3816
- return __awaiter(this, void 0, void 0, function () {
3817
- var res, responseData, data;
3818
- return __generator(this, function (_a) {
3819
- switch (_a.label) {
3820
- case 0: return [4 /*yield*/, fetch__default['default'](url, {
3821
- method: 'POST',
3822
- headers: __assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers),
3823
- body: JSON.stringify({ query: jsonToGraphqlQuery.jsonToGraphQLQuery({ query: query }) })
3824
- })];
3825
- case 1:
3826
- res = _a.sent();
3827
- return [4 /*yield*/, res.text()];
3828
- case 2:
3829
- responseData = _a.sent();
3830
- try {
3831
- responseData = JSON.parse(responseData);
3832
- }
3833
- catch (e) {
3834
- throw new Error("Errors found in subgraphRequest: URL: " + url + ", Status: " + res.status + ", Response: " + responseData.substring(0, 400));
3835
- }
3836
- if (responseData.errors) {
3837
- throw new Error("Errors found in subgraphRequest: URL: " + url + ", Status: " + res.status + ", Response: " + JSON.stringify(responseData.errors).substring(0, 400));
3838
- }
3839
- data = responseData.data;
3840
- return [2 /*return*/, data || {}];
3841
- }
3842
- });
3843
- });
3844
- }
3845
- function getUrl(uri, gateway) {
3846
- if (gateway === void 0) { gateway = gateways[0]; }
3847
- var ipfsGateway = "https://" + gateway;
3848
- if (!uri)
3849
- return null;
3850
- if (!uri.startsWith('ipfs://') &&
3851
- !uri.startsWith('ipns://') &&
3852
- !uri.startsWith('https://') &&
3853
- !uri.startsWith('http://'))
3854
- return ipfsGateway + "/ipfs/" + uri;
3855
- var uriScheme = uri.split('://')[0];
3856
- if (uriScheme === 'ipfs')
3857
- return uri.replace('ipfs://', ipfsGateway + "/ipfs/");
3858
- if (uriScheme === 'ipns')
3859
- return uri.replace('ipns://', ipfsGateway + "/ipns/");
3860
- return uri;
3861
- }
3862
- function getJSON(uri, options) {
3863
- if (options === void 0) { options = {}; }
3864
- return __awaiter(this, void 0, void 0, function () {
3865
- var url;
3866
- return __generator(this, function (_a) {
3867
- url = getUrl(uri, options.gateways);
3868
- return [2 /*return*/, fetch__default['default'](url).then(function (res) { return res.json(); })];
3869
- });
3870
- });
3871
- }
3872
- function ipfsGet(gateway, ipfsHash, protocolType) {
3873
- if (protocolType === void 0) { protocolType = 'ipfs'; }
3874
- return __awaiter(this, void 0, void 0, function () {
3875
- var url;
3876
- return __generator(this, function (_a) {
3877
- url = "https://" + gateway + "/" + protocolType + "/" + ipfsHash;
3878
- return [2 /*return*/, fetch__default['default'](url).then(function (res) { return res.json(); })];
3879
- });
3880
- });
3881
- }
3882
- function sendTransaction(web3, contractAddress, abi, action, params, overrides) {
3883
- if (overrides === void 0) { overrides = {}; }
3884
- return __awaiter(this, void 0, void 0, function () {
3885
- var signer, contract, contractWithSigner;
3886
- return __generator(this, function (_a) {
3887
- switch (_a.label) {
3888
- case 0:
3889
- signer = web3.getSigner();
3890
- contract = new contracts.Contract(contractAddress, abi, web3);
3891
- contractWithSigner = contract.connect(signer);
3892
- return [4 /*yield*/, contractWithSigner[action].apply(contractWithSigner, __spread(params, [overrides]))];
3893
- case 1:
3894
- // overrides.gasLimit = 12e6;
3895
- return [2 /*return*/, _a.sent()];
3896
- }
3897
- });
3898
- });
3899
- }
3900
- function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl, options) {
3901
- if (snapshot === void 0) { snapshot = 'latest'; }
3902
- if (scoreApiUrl === void 0) { scoreApiUrl = 'https://score.snapshot.org'; }
3903
- if (options === void 0) { options = {}; }
3904
- return __awaiter(this, void 0, void 0, function () {
3905
- var invalidAddress, invalidStrategy, url, params, res, obj, e_3;
3906
- return __generator(this, function (_a) {
3907
- switch (_a.label) {
3908
- case 0:
3909
- if (!Array.isArray(addresses)) {
3910
- return [2 /*return*/, inputError('addresses should be an array of addresses')];
3911
- }
3912
- if (addresses.length === 0) {
3913
- return [2 /*return*/, inputError('addresses can not be empty')];
3914
- }
3915
- invalidAddress = addresses.find(function (address) { return !isValidAddress(address); });
3916
- if (invalidAddress) {
3917
- return [2 /*return*/, inputError("Invalid address: " + invalidAddress)];
3918
- }
3919
- if (!isValidNetwork(network)) {
3920
- return [2 /*return*/, inputError("Invalid network: " + network)];
3921
- }
3922
- invalidStrategy = strategies.find(function (strategy) { return strategy.network && !isValidNetwork(strategy.network); });
3923
- if (invalidStrategy) {
3924
- return [2 /*return*/, inputError("Invalid network (" + invalidStrategy.network + ") in strategy " + invalidStrategy.name)];
3925
- }
3926
- if (!isValidSnapshot(snapshot, network)) {
3927
- return [2 /*return*/, inputError("Snapshot (" + snapshot + ") must be 'latest' or greater than network start block (" + networks[network].start + ")")];
3928
- }
3929
- url = new URL(scoreApiUrl);
3930
- url.pathname = '/api/scores';
3931
- scoreApiUrl = url.toString();
3932
- _a.label = 1;
3933
- case 1:
3934
- _a.trys.push([1, 4, , 5]);
3935
- params = {
3936
- space: space,
3937
- network: network,
3938
- snapshot: snapshot,
3939
- strategies: strategies,
3940
- addresses: addresses
3941
- };
3942
- return [4 /*yield*/, fetch__default['default'](scoreApiUrl, {
3943
- method: 'POST',
3944
- headers: scoreApiHeaders,
3945
- body: JSON.stringify({ params: params })
3946
- })];
3947
- case 2:
3948
- res = _a.sent();
3949
- return [4 /*yield*/, res.json()];
3950
- case 3:
3951
- obj = _a.sent();
3952
- if (obj.error) {
3953
- return [2 /*return*/, Promise.reject(obj.error)];
3954
- }
3955
- return [2 /*return*/, options.returnValue === 'all'
3956
- ? obj.result
3957
- : obj.result[options.returnValue || 'scores']];
3958
- case 4:
3959
- e_3 = _a.sent();
3960
- if (e_3.errno) {
3961
- return [2 /*return*/, Promise.reject({ code: e_3.errno, message: e_3.toString(), data: '' })];
3962
- }
3963
- return [2 /*return*/, Promise.reject(e_3)];
3964
- case 5: return [2 /*return*/];
3965
- }
3966
- });
3967
- });
3968
- }
3969
- function getVp(address, network, strategies, snapshot, space, delegation, options) {
3970
- return __awaiter(this, void 0, void 0, function () {
3971
- var invalidStrategy, init, res, json, e_4;
3972
- return __generator(this, function (_a) {
3973
- switch (_a.label) {
3974
- case 0:
3975
- if (!options)
3976
- options = {};
3977
- if (!options.url)
3978
- options.url = 'https://score.snapshot.org';
3979
- if (!isValidAddress(address)) {
3980
- return [2 /*return*/, inputError("Invalid voter address: " + address)];
3981
- }
3982
- if (!isValidNetwork(network)) {
3983
- return [2 /*return*/, inputError("Invalid network: " + network)];
3984
- }
3985
- invalidStrategy = strategies.find(function (strategy) { return strategy.network && !isValidNetwork(strategy.network); });
3986
- if (invalidStrategy) {
3987
- return [2 /*return*/, inputError("Invalid network (" + invalidStrategy.network + ") in strategy " + invalidStrategy.name)];
3988
- }
3989
- if (!isValidSnapshot(snapshot, network)) {
3990
- return [2 /*return*/, inputError("Snapshot (" + snapshot + ") must be 'latest' or greater than network start block (" + networks[network].start + ")")];
3991
- }
3992
- init = {
3993
- method: 'POST',
3994
- headers: scoreApiHeaders,
3995
- body: JSON.stringify({
3996
- jsonrpc: '2.0',
3997
- method: 'get_vp',
3998
- params: {
3999
- address: address,
4000
- network: network,
4001
- strategies: strategies,
4002
- snapshot: snapshot,
4003
- space: space,
4004
- delegation: delegation
4005
- }
4006
- })
4007
- };
4008
- _a.label = 1;
4009
- case 1:
4010
- _a.trys.push([1, 4, , 5]);
4011
- return [4 /*yield*/, fetch__default['default'](options.url, init)];
4012
- case 2:
4013
- res = _a.sent();
4014
- return [4 /*yield*/, res.json()];
4015
- case 3:
4016
- json = _a.sent();
4017
- if (json.error)
4018
- return [2 /*return*/, Promise.reject(json.error)];
4019
- if (json.result)
4020
- return [2 /*return*/, json.result];
4021
- return [3 /*break*/, 5];
4022
- case 4:
4023
- e_4 = _a.sent();
4024
- if (e_4.errno) {
4025
- return [2 /*return*/, Promise.reject({ code: e_4.errno, message: e_4.toString(), data: '' })];
4026
- }
4027
- return [2 /*return*/, Promise.reject(e_4)];
4028
- case 5: return [2 /*return*/];
4029
- }
4030
- });
4031
- });
4032
- }
4033
- function validate(validation, author, space, network, snapshot, params, options) {
4034
- return __awaiter(this, void 0, void 0, function () {
4035
- var init, res, json, e_5;
4036
- return __generator(this, function (_a) {
4037
- switch (_a.label) {
4038
- case 0:
4039
- if (!isValidAddress(author)) {
4040
- return [2 /*return*/, inputError("Invalid author: " + author)];
4041
- }
4042
- if (!isValidNetwork(network)) {
4043
- return [2 /*return*/, inputError("Invalid network: " + network)];
4044
- }
4045
- if (!isValidSnapshot(snapshot, network)) {
4046
- return [2 /*return*/, inputError("Snapshot (" + snapshot + ") must be 'latest' or greater than network start block (" + networks[network].start + ")")];
4047
- }
4048
- if (!options)
4049
- options = {};
4050
- if (!options.url)
4051
- options.url = 'https://score.snapshot.org';
4052
- init = {
4053
- method: 'POST',
4054
- headers: scoreApiHeaders,
4055
- body: JSON.stringify({
4056
- jsonrpc: '2.0',
4057
- method: 'validate',
4058
- params: {
4059
- validation: validation,
4060
- author: author,
4061
- space: space,
4062
- network: network,
4063
- snapshot: snapshot,
4064
- params: params
4065
- }
4066
- })
4067
- };
4068
- _a.label = 1;
4069
- case 1:
4070
- _a.trys.push([1, 4, , 5]);
4071
- return [4 /*yield*/, fetch__default['default'](options.url, init)];
4072
- case 2:
4073
- res = _a.sent();
4074
- return [4 /*yield*/, res.json()];
4075
- case 3:
4076
- json = _a.sent();
4077
- if (json.error)
4078
- return [2 /*return*/, Promise.reject(json.error)];
4079
- return [2 /*return*/, json.result];
4080
- case 4:
4081
- e_5 = _a.sent();
4082
- if (e_5.errno) {
4083
- return [2 /*return*/, Promise.reject({ code: e_5.errno, message: e_5.toString(), data: '' })];
4084
- }
4085
- return [2 /*return*/, Promise.reject(e_5)];
4086
- case 5: return [2 /*return*/];
4087
- }
4088
- });
4089
- });
4090
- }
4091
- function validateSchema(schema, data, options) {
4092
- if (options === void 0) { options = {
4093
- snapshotEnv: 'default',
4094
- spaceType: 'default'
4095
- }; }
4096
- var ajvValidate = ajv.compile(schema);
4097
- var valid = ajvValidate.call(options, data);
4098
- return valid ? valid : ajvValidate.errors;
4099
- }
4100
- function getEnsTextRecord(ens, record, network, options) {
4101
- if (network === void 0) { network = '1'; }
4102
- if (options === void 0) { options = {}; }
4103
- return __awaiter(this, void 0, void 0, function () {
4104
- var ensResolversOpt, broviderUrl, multicallOptions, ensResolvers, ensHash, provider, result;
4105
- return __generator(this, function (_a) {
4106
- switch (_a.label) {
4107
- case 0:
4108
- ensResolversOpt = options.ensResolvers, broviderUrl = options.broviderUrl, multicallOptions = __rest(options, ["ensResolvers", "broviderUrl"]);
4109
- ensResolvers = ensResolversOpt ||
4110
- networks[network].ensResolvers ||
4111
- networks['1'].ensResolvers;
4112
- ensHash = hash.namehash(hash.ensNormalize(ens));
4113
- provider = getProvider(network, { broviderUrl: broviderUrl });
4114
- return [4 /*yield*/, multicall(network, provider, ENS_RESOLVER_ABI, ensResolvers.map(function (address) { return [address, 'text', [ensHash, record]]; }), multicallOptions)];
4115
- case 1:
4116
- result = _a.sent();
4117
- return [2 /*return*/, result.flat().find(function (r) { return r; }) || ''];
4118
- }
4119
- });
4120
- });
4121
- }
4122
- function getSpaceUri(id, network, options) {
4123
- if (network === void 0) { network = '1'; }
4124
- if (options === void 0) { options = {}; }
4125
- return __awaiter(this, void 0, void 0, function () {
4126
- var e_6;
4127
- return __generator(this, function (_a) {
4128
- switch (_a.label) {
4129
- case 0:
4130
- _a.trys.push([0, 2, , 3]);
4131
- return [4 /*yield*/, getEnsTextRecord(id, 'snapshot', network, options)];
4132
- case 1: return [2 /*return*/, _a.sent()];
4133
- case 2:
4134
- e_6 = _a.sent();
4135
- console.log(e_6);
4136
- return [2 /*return*/, null];
4137
- case 3: return [2 /*return*/];
4138
- }
4139
- });
4140
- });
4141
- }
4142
- function getEnsOwner(ens, network, options) {
4143
- if (network === void 0) { network = '1'; }
4144
- if (options === void 0) { options = {}; }
4145
- return __awaiter(this, void 0, void 0, function () {
4146
- var registryAddress, provider, ensRegistry, ensNameWrapper, ensHash, owner, ensNameWrapperContract;
4147
- return __generator(this, function (_a) {
4148
- switch (_a.label) {
4149
- case 0:
4150
- registryAddress = '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e';
4151
- provider = getProvider(network, options);
4152
- ensRegistry = new contracts.Contract(registryAddress, ['function owner(bytes32) view returns (address)'], provider);
4153
- ensNameWrapper = options.ensNameWrapper || networks[network].ensNameWrapper;
4154
- ensHash = hash.namehash(hash.ensNormalize(ens));
4155
- return [4 /*yield*/, ensRegistry.owner(ensHash)];
4156
- case 1:
4157
- owner = _a.sent();
4158
- if (!(owner === ensNameWrapper)) return [3 /*break*/, 3];
4159
- ensNameWrapperContract = new contracts.Contract(ensNameWrapper, ['function ownerOf(uint256) view returns (address)'], provider);
4160
- return [4 /*yield*/, ensNameWrapperContract.ownerOf(ensHash)];
4161
- case 2:
4162
- owner = _a.sent();
4163
- _a.label = 3;
4164
- case 3: return [2 /*return*/, owner];
4165
- }
4166
- });
4167
- });
4168
- }
4169
- function getSpaceController(id, network, options) {
4170
- if (network === void 0) { network = '1'; }
4171
- if (options === void 0) { options = {}; }
4172
- return __awaiter(this, void 0, void 0, function () {
4173
- var spaceUri, isUriAddress, uriParts, position, address$1;
4174
- return __generator(this, function (_a) {
4175
- switch (_a.label) {
4176
- case 0: return [4 /*yield*/, getSpaceUri(id, network, options)];
4177
- case 1:
4178
- spaceUri = _a.sent();
4179
- if (spaceUri) {
4180
- isUriAddress = address.isAddress(spaceUri);
4181
- if (isUriAddress)
4182
- return [2 /*return*/, spaceUri];
4183
- uriParts = spaceUri.split('/');
4184
- position = uriParts.includes('testnet') ? 5 : 4;
4185
- address$1 = uriParts[position];
4186
- isUriAddress = address.isAddress(address$1);
4187
- if (isUriAddress)
4188
- return [2 /*return*/, address$1];
4189
- }
4190
- return [4 /*yield*/, getEnsOwner(id, network, options)];
4191
- case 2: return [2 /*return*/, _a.sent()];
4192
- }
4193
- });
4194
- });
4195
- }
4196
- function clone(item) {
4197
- return JSON.parse(JSON.stringify(item));
4198
- }
4199
- function sleep(time) {
4200
- return __awaiter(this, void 0, void 0, function () {
4201
- return __generator(this, function (_a) {
4202
- return [2 /*return*/, new Promise(function (resolve) {
4203
- setTimeout(resolve, time);
4204
- })];
4205
- });
4206
- });
4207
- }
4208
- function getNumberWithOrdinal(n) {
4209
- var s = ['th', 'st', 'nd', 'rd'], v = n % 100;
4210
- return n + (s[(v - 20) % 10] || s[v] || s[0]);
4211
- }
4212
- function isValidNetwork(network) {
4213
- return !!networks[network];
4214
- }
4215
- function isValidAddress(address$1) {
4216
- return address.isAddress(address$1) && address$1 !== EMPTY_ADDRESS;
4217
- }
4218
- function isValidSnapshot(snapshot, network) {
4219
- return (snapshot === 'latest' ||
4220
- (typeof snapshot === 'number' && snapshot >= networks[network].start));
4221
- }
4222
- function inputError(message) {
4223
- return Promise.reject(new Error(message));
4224
- }
4225
- var utils = {
4226
- call: call,
4227
- multicall: multicall,
4228
- subgraphRequest: subgraphRequest,
4229
- ipfsGet: ipfsGet,
4230
- getUrl: getUrl,
4231
- getJSON: getJSON,
4232
- sendTransaction: sendTransaction,
4233
- getScores: getScores,
4234
- getVp: getVp,
4235
- validateSchema: validateSchema,
4236
- getEnsTextRecord: getEnsTextRecord,
4237
- getSpaceUri: getSpaceUri,
4238
- getEnsOwner: getEnsOwner,
4239
- getSpaceController: getSpaceController,
4240
- getDelegatesBySpace: getDelegatesBySpace,
4241
- clone: clone,
4242
- sleep: sleep,
4243
- getNumberWithOrdinal: getNumberWithOrdinal,
4244
- voting: voting,
4245
- getProvider: getProvider,
4246
- signMessage: signMessage,
4247
- getBlockNumber: getBlockNumber,
4248
- Multicaller: Multicaller,
4249
- getSnapshots: getSnapshots,
4250
- getHash: getHash,
4251
- verify: verify$1,
4252
- validate: validate,
4253
- SNAPSHOT_SUBGRAPH_URL: SNAPSHOT_SUBGRAPH_URL
3633
+ const ENS_RESOLVER_ABI = [
3634
+ 'function text(bytes32 node, string calldata key) external view returns (string memory)'
3635
+ ];
3636
+ const EMPTY_ADDRESS = '0x0000000000000000000000000000000000000000';
3637
+ const scoreApiHeaders = {
3638
+ Accept: 'application/json',
3639
+ 'Content-Type': 'application/json'
3640
+ };
3641
+ const DEFAULT_SCORE_API_URL = 'https://score.snapshot.org';
3642
+ function formatScoreAPIUrl(url = DEFAULT_SCORE_API_URL, options = {
3643
+ path: ''
3644
+ }) {
3645
+ const scoreURL = new URL(url);
3646
+ if (options.path)
3647
+ scoreURL.pathname = options.path;
3648
+ const apiKey = scoreURL.searchParams.get('apiKey');
3649
+ let headers = Object.assign({}, scoreApiHeaders);
3650
+ if (apiKey) {
3651
+ scoreURL.searchParams.delete('apiKey');
3652
+ headers = Object.assign(Object.assign({}, scoreApiHeaders), { 'X-API-KEY': apiKey });
3653
+ }
3654
+ return {
3655
+ url: scoreURL.toString(),
3656
+ headers
3657
+ };
3658
+ }
3659
+ function parseScoreAPIResponse(res) {
3660
+ return __awaiter(this, void 0, void 0, function* () {
3661
+ let data = yield res.text();
3662
+ try {
3663
+ data = JSON.parse(data);
3664
+ }
3665
+ catch (e) {
3666
+ return Promise.reject({
3667
+ code: res.status || 500,
3668
+ message: 'Failed to parse response from score API',
3669
+ data
3670
+ });
3671
+ }
3672
+ if (data.error)
3673
+ return Promise.reject(data.error);
3674
+ return data;
3675
+ });
3676
+ }
3677
+ const ajv = new Ajv__default['default']({
3678
+ allErrors: true,
3679
+ allowUnionTypes: true,
3680
+ $data: true,
3681
+ passContext: true
3682
+ });
3683
+ // @ts-ignore
3684
+ addFormats__default['default'](ajv);
3685
+ addErrors__default['default'](ajv);
3686
+ ajv.addFormat('address', {
3687
+ validate: (value) => {
3688
+ try {
3689
+ return address.isAddress(value);
3690
+ }
3691
+ catch (e) {
3692
+ return false;
3693
+ }
3694
+ }
3695
+ });
3696
+ ajv.addFormat('starknetAddress', {
3697
+ validate: (value) => {
3698
+ try {
3699
+ return isStarknetAddress(value);
3700
+ }
3701
+ catch (e) {
3702
+ return false;
3703
+ }
3704
+ }
3705
+ });
3706
+ ajv.addFormat('long', {
3707
+ validate: () => true
3708
+ });
3709
+ ajv.addFormat('ethValue', {
3710
+ validate: (value) => {
3711
+ if (!value.match(/^([0-9]|[1-9][0-9]+)(\.[0-9]+)?$/))
3712
+ return false;
3713
+ try {
3714
+ units.parseUnits(value, 18);
3715
+ return true;
3716
+ }
3717
+ catch (_a) {
3718
+ return false;
3719
+ }
3720
+ }
3721
+ });
3722
+ const networksIds = Object.keys(networks);
3723
+ const mainnetNetworkIds = Object.keys(networks).filter((id) => !networks[id].testnet);
3724
+ ajv.addKeyword({
3725
+ keyword: 'snapshotNetwork',
3726
+ validate: function (schema, data) {
3727
+ // @ts-ignore
3728
+ const snapshotEnv = this.snapshotEnv || 'default';
3729
+ if (snapshotEnv === 'mainnet')
3730
+ return mainnetNetworkIds.includes(data);
3731
+ return networksIds.includes(data);
3732
+ },
3733
+ error: {
3734
+ message: 'network not allowed'
3735
+ }
3736
+ });
3737
+ ajv.addKeyword({
3738
+ keyword: 'maxLengthWithSpaceType',
3739
+ validate: function validate(schema, data) {
3740
+ // @ts-ignore
3741
+ const spaceType = this.spaceType || 'default';
3742
+ const isValid = data.length <= schema[spaceType];
3743
+ if (!isValid) {
3744
+ // @ts-ignore
3745
+ validate.errors = [
3746
+ {
3747
+ keyword: 'maxLengthWithSpaceType',
3748
+ message: `must NOT have more than ${schema[spaceType]} characters`,
3749
+ params: { limit: schema[spaceType] }
3750
+ }
3751
+ ];
3752
+ }
3753
+ return isValid;
3754
+ },
3755
+ errors: true
3756
+ });
3757
+ ajv.addKeyword({
3758
+ keyword: 'maxItemsWithSpaceType',
3759
+ validate: function validate(schema, data) {
3760
+ // @ts-ignore
3761
+ const spaceType = this.spaceType || 'default';
3762
+ const isValid = data.length <= schema[spaceType];
3763
+ if (!isValid) {
3764
+ // @ts-ignore
3765
+ validate.errors = [
3766
+ {
3767
+ keyword: 'maxItemsWithSpaceType',
3768
+ message: `must NOT have more than ${schema[spaceType]} items`,
3769
+ params: { limit: schema[spaceType] }
3770
+ }
3771
+ ];
3772
+ }
3773
+ return isValid;
3774
+ },
3775
+ errors: true
3776
+ });
3777
+ // Custom URL format to allow empty string values
3778
+ // https://github.com/snapshot-labs/snapshot.js/pull/541/files
3779
+ ajv.addFormat('customUrl', {
3780
+ type: 'string',
3781
+ validate: (str) => {
3782
+ if (!str.length)
3783
+ return true;
3784
+ return (str.startsWith('http://') ||
3785
+ str.startsWith('https://') ||
3786
+ str.startsWith('ipfs://') ||
3787
+ str.startsWith('ipns://') ||
3788
+ str.startsWith('snapshot://'));
3789
+ }
3790
+ });
3791
+ function call(provider, abi, call, options) {
3792
+ return __awaiter(this, void 0, void 0, function* () {
3793
+ const contract = new contracts.Contract(call[0], abi, provider);
3794
+ try {
3795
+ const params = call[2] || [];
3796
+ return yield contract[call[1]](...params, options || {});
3797
+ }
3798
+ catch (e) {
3799
+ return Promise.reject(e);
3800
+ }
3801
+ });
3802
+ }
3803
+ function multicall(network, provider, abi$1, calls, options) {
3804
+ return __awaiter(this, void 0, void 0, function* () {
3805
+ const multicallAbi = [
3806
+ 'function aggregate(tuple(address target, bytes callData)[] calls) view returns (uint256 blockNumber, bytes[] returnData)'
3807
+ ];
3808
+ const multicallAddress = (options === null || options === void 0 ? void 0 : options.multicallAddress) || networks[network].multicall;
3809
+ const multi = new contracts.Contract(multicallAddress, multicallAbi, provider);
3810
+ const itf = new abi.Interface(abi$1);
3811
+ try {
3812
+ const max = (options === null || options === void 0 ? void 0 : options.limit) || 500;
3813
+ if (options === null || options === void 0 ? void 0 : options.limit)
3814
+ delete options.limit;
3815
+ const pages = Math.ceil(calls.length / max);
3816
+ const promises = [];
3817
+ Array.from(Array(pages)).forEach((x, i) => {
3818
+ const callsInPage = calls.slice(max * i, max * (i + 1));
3819
+ promises.push(multi.aggregate(callsInPage.map((call) => [
3820
+ call[0].toLowerCase(),
3821
+ itf.encodeFunctionData(call[1], call[2])
3822
+ ]), options || {}));
3823
+ });
3824
+ let results = yield Promise.all(promises);
3825
+ results = results.reduce((prev, [, res]) => prev.concat(res), []);
3826
+ return results.map((call, i) => itf.decodeFunctionResult(calls[i][1], call));
3827
+ }
3828
+ catch (e) {
3829
+ return Promise.reject(e);
3830
+ }
3831
+ });
3832
+ }
3833
+ function subgraphRequest(url_1, query_1) {
3834
+ return __awaiter(this, arguments, void 0, function* (url, query, options = {}) {
3835
+ const res = yield fetch__default['default'](url, {
3836
+ method: 'POST',
3837
+ headers: Object.assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers),
3838
+ body: JSON.stringify({ query: jsonToGraphqlQuery.jsonToGraphQLQuery({ query }) })
3839
+ });
3840
+ let responseData = yield res.text();
3841
+ try {
3842
+ responseData = JSON.parse(responseData);
3843
+ }
3844
+ catch (e) {
3845
+ throw new Error(`Errors found in subgraphRequest: URL: ${url}, Status: ${res.status}, Response: ${responseData.substring(0, 400)}`);
3846
+ }
3847
+ if (responseData.errors) {
3848
+ throw new Error(`Errors found in subgraphRequest: URL: ${url}, Status: ${res.status}, Response: ${JSON.stringify(responseData.errors).substring(0, 400)}`);
3849
+ }
3850
+ const { data } = responseData;
3851
+ return data || {};
3852
+ });
3853
+ }
3854
+ function getUrl(uri, gateway = gateways[0]) {
3855
+ const ipfsGateway = `https://${gateway}`;
3856
+ if (!uri)
3857
+ return null;
3858
+ if (!uri.startsWith('ipfs://') &&
3859
+ !uri.startsWith('ipns://') &&
3860
+ !uri.startsWith('https://') &&
3861
+ !uri.startsWith('http://'))
3862
+ return `${ipfsGateway}/ipfs/${uri}`;
3863
+ const uriScheme = uri.split('://')[0];
3864
+ if (uriScheme === 'ipfs')
3865
+ return uri.replace('ipfs://', `${ipfsGateway}/ipfs/`);
3866
+ if (uriScheme === 'ipns')
3867
+ return uri.replace('ipns://', `${ipfsGateway}/ipns/`);
3868
+ return uri;
3869
+ }
3870
+ function getJSON(uri_1) {
3871
+ return __awaiter(this, arguments, void 0, function* (uri, options = {}) {
3872
+ const url = getUrl(uri, options.gateways);
3873
+ return fetch__default['default'](url).then((res) => res.json());
3874
+ });
3875
+ }
3876
+ function ipfsGet(gateway_1, ipfsHash_1) {
3877
+ return __awaiter(this, arguments, void 0, function* (gateway, ipfsHash, protocolType = 'ipfs') {
3878
+ const url = `https://${gateway}/${protocolType}/${ipfsHash}`;
3879
+ return fetch__default['default'](url).then((res) => res.json());
3880
+ });
3881
+ }
3882
+ function sendTransaction(web3_1, contractAddress_1, abi_1, action_1, params_1) {
3883
+ return __awaiter(this, arguments, void 0, function* (web3, contractAddress, abi, action, params, overrides = {}) {
3884
+ const signer = web3.getSigner();
3885
+ const contract = new contracts.Contract(contractAddress, abi, web3);
3886
+ const contractWithSigner = contract.connect(signer);
3887
+ // overrides.gasLimit = 12e6;
3888
+ return yield contractWithSigner[action](...params, overrides);
3889
+ });
3890
+ }
3891
+ function getScores(space_1, strategies_1, network_1, addresses_1) {
3892
+ return __awaiter(this, arguments, void 0, function* (space, strategies, network, addresses, snapshot = 'latest', scoreApiUrl = DEFAULT_SCORE_API_URL, options = {}) {
3893
+ if (!Array.isArray(addresses)) {
3894
+ return inputError('addresses should be an array of addresses');
3895
+ }
3896
+ if (addresses.length === 0) {
3897
+ return inputError('addresses can not be empty');
3898
+ }
3899
+ const invalidAddress = addresses.find((address) => !isValidAddress(address));
3900
+ if (invalidAddress) {
3901
+ return inputError(`Invalid address: ${invalidAddress}`);
3902
+ }
3903
+ if (!isValidNetwork(network)) {
3904
+ return inputError(`Invalid network: ${network}`);
3905
+ }
3906
+ const invalidStrategy = strategies.find((strategy) => strategy.network && !isValidNetwork(strategy.network));
3907
+ if (invalidStrategy) {
3908
+ return inputError(`Invalid network (${invalidStrategy.network}) in strategy ${invalidStrategy.name}`);
3909
+ }
3910
+ if (!isValidSnapshot(snapshot, network)) {
3911
+ return inputError(`Snapshot (${snapshot}) must be 'latest' or greater than network start block (${networks[network].start})`);
3912
+ }
3913
+ const urlObject = new URL(scoreApiUrl);
3914
+ urlObject.pathname = '/api/scores';
3915
+ const { url, headers } = formatScoreAPIUrl(scoreApiUrl, {
3916
+ path: '/api/scores'
3917
+ });
3918
+ try {
3919
+ const params = {
3920
+ space,
3921
+ network,
3922
+ snapshot,
3923
+ strategies,
3924
+ addresses
3925
+ };
3926
+ const res = yield fetch__default['default'](url, {
3927
+ method: 'POST',
3928
+ headers,
3929
+ body: JSON.stringify({ params })
3930
+ });
3931
+ const response = yield parseScoreAPIResponse(res);
3932
+ return options.returnValue === 'all'
3933
+ ? response.result
3934
+ : response.result[options.returnValue || 'scores'];
3935
+ }
3936
+ catch (e) {
3937
+ if (e.errno) {
3938
+ return Promise.reject({ code: e.errno, message: e.toString(), data: '' });
3939
+ }
3940
+ return Promise.reject(e);
3941
+ }
3942
+ });
3943
+ }
3944
+ function getVp(address, network, strategies, snapshot, space, delegation, options) {
3945
+ return __awaiter(this, void 0, void 0, function* () {
3946
+ const { url, headers } = formatScoreAPIUrl(options === null || options === void 0 ? void 0 : options.url);
3947
+ if (!isValidAddress(address)) {
3948
+ return inputError(`Invalid voter address: ${address}`);
3949
+ }
3950
+ if (!isValidNetwork(network)) {
3951
+ return inputError(`Invalid network: ${network}`);
3952
+ }
3953
+ const invalidStrategy = strategies.find((strategy) => strategy.network && !isValidNetwork(strategy.network));
3954
+ if (invalidStrategy) {
3955
+ return inputError(`Invalid network (${invalidStrategy.network}) in strategy ${invalidStrategy.name}`);
3956
+ }
3957
+ if (!isValidSnapshot(snapshot, network)) {
3958
+ return inputError(`Snapshot (${snapshot}) must be 'latest' or greater than network start block (${networks[network].start})`);
3959
+ }
3960
+ const init = {
3961
+ method: 'POST',
3962
+ headers,
3963
+ body: JSON.stringify({
3964
+ jsonrpc: '2.0',
3965
+ method: 'get_vp',
3966
+ params: {
3967
+ address,
3968
+ network,
3969
+ strategies,
3970
+ snapshot,
3971
+ space,
3972
+ delegation
3973
+ }
3974
+ })
3975
+ };
3976
+ try {
3977
+ const res = yield fetch__default['default'](url, init);
3978
+ const response = yield parseScoreAPIResponse(res);
3979
+ return response.result;
3980
+ }
3981
+ catch (e) {
3982
+ if (e.errno) {
3983
+ return Promise.reject({ code: e.errno, message: e.toString(), data: '' });
3984
+ }
3985
+ return Promise.reject(e);
3986
+ }
3987
+ });
3988
+ }
3989
+ function validate(validation, author, space, network, snapshot, params, options) {
3990
+ return __awaiter(this, void 0, void 0, function* () {
3991
+ if (!isValidAddress(author)) {
3992
+ return inputError(`Invalid author: ${author}`);
3993
+ }
3994
+ if (!isValidNetwork(network)) {
3995
+ return inputError(`Invalid network: ${network}`);
3996
+ }
3997
+ if (!isValidSnapshot(snapshot, network)) {
3998
+ return inputError(`Snapshot (${snapshot}) must be 'latest' or greater than network start block (${networks[network].start})`);
3999
+ }
4000
+ if (!options)
4001
+ options = {};
4002
+ const { url, headers } = formatScoreAPIUrl(options.url);
4003
+ const init = {
4004
+ method: 'POST',
4005
+ headers,
4006
+ body: JSON.stringify({
4007
+ jsonrpc: '2.0',
4008
+ method: 'validate',
4009
+ params: {
4010
+ validation,
4011
+ author,
4012
+ space,
4013
+ network,
4014
+ snapshot,
4015
+ params
4016
+ }
4017
+ })
4018
+ };
4019
+ try {
4020
+ const res = yield fetch__default['default'](url, init);
4021
+ const response = yield parseScoreAPIResponse(res);
4022
+ return response.result;
4023
+ }
4024
+ catch (e) {
4025
+ if (e.errno) {
4026
+ return Promise.reject({ code: e.errno, message: e.toString(), data: '' });
4027
+ }
4028
+ return Promise.reject(e);
4029
+ }
4030
+ });
4031
+ }
4032
+ function validateSchema(schema, data, options = {
4033
+ snapshotEnv: 'default',
4034
+ spaceType: 'default'
4035
+ }) {
4036
+ const ajvValidate = ajv.compile(schema);
4037
+ const valid = ajvValidate.call(options, data);
4038
+ return valid ? valid : ajvValidate.errors;
4039
+ }
4040
+ function getEnsTextRecord(ens_1, record_1) {
4041
+ return __awaiter(this, arguments, void 0, function* (ens, record, network = '1', options = {}) {
4042
+ const { ensResolvers: ensResolversOpt, broviderUrl } = options, multicallOptions = __rest(options, ["ensResolvers", "broviderUrl"]);
4043
+ const ensResolvers = ensResolversOpt ||
4044
+ networks[network].ensResolvers ||
4045
+ networks['1'].ensResolvers;
4046
+ const ensHash = hash.namehash(hash.ensNormalize(ens));
4047
+ const provider = getProvider(network, { broviderUrl });
4048
+ const result = yield multicall(network, provider, ENS_RESOLVER_ABI, ensResolvers.map((address) => [address, 'text', [ensHash, record]]), multicallOptions);
4049
+ return result.flat().find((r) => r) || '';
4050
+ });
4051
+ }
4052
+ function getSpaceUri(id_1) {
4053
+ return __awaiter(this, arguments, void 0, function* (id, network = '1', options = {}) {
4054
+ try {
4055
+ return yield getEnsTextRecord(id, 'snapshot', network, options);
4056
+ }
4057
+ catch (e) {
4058
+ console.log(e);
4059
+ return null;
4060
+ }
4061
+ });
4062
+ }
4063
+ function getEnsOwner(ens_1) {
4064
+ return __awaiter(this, arguments, void 0, function* (ens, network = '1', options = {}) {
4065
+ const registryAddress = '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e';
4066
+ const provider = getProvider(network, options);
4067
+ const ensRegistry = new contracts.Contract(registryAddress, ['function owner(bytes32) view returns (address)'], provider);
4068
+ const ensNameWrapper = options.ensNameWrapper || networks[network].ensNameWrapper;
4069
+ const ensHash = hash.namehash(hash.ensNormalize(ens));
4070
+ let owner = yield ensRegistry.owner(ensHash);
4071
+ // If owner is the ENSNameWrapper contract, resolve the owner of the name
4072
+ if (owner === ensNameWrapper) {
4073
+ const ensNameWrapperContract = new contracts.Contract(ensNameWrapper, ['function ownerOf(uint256) view returns (address)'], provider);
4074
+ owner = yield ensNameWrapperContract.ownerOf(ensHash);
4075
+ }
4076
+ return owner;
4077
+ });
4078
+ }
4079
+ function getSpaceController(id_1) {
4080
+ return __awaiter(this, arguments, void 0, function* (id, network = '1', options = {}) {
4081
+ const spaceUri = yield getSpaceUri(id, network, options);
4082
+ if (spaceUri) {
4083
+ let isUriAddress = address.isAddress(spaceUri);
4084
+ if (isUriAddress)
4085
+ return spaceUri;
4086
+ const uriParts = spaceUri.split('/');
4087
+ const position = uriParts.includes('testnet') ? 5 : 4;
4088
+ const address$1 = uriParts[position];
4089
+ isUriAddress = address.isAddress(address$1);
4090
+ if (isUriAddress)
4091
+ return address$1;
4092
+ }
4093
+ return yield getEnsOwner(id, network, options);
4094
+ });
4095
+ }
4096
+ function clone(item) {
4097
+ return JSON.parse(JSON.stringify(item));
4098
+ }
4099
+ function sleep(time) {
4100
+ return __awaiter(this, void 0, void 0, function* () {
4101
+ return new Promise((resolve) => {
4102
+ setTimeout(resolve, time);
4103
+ });
4104
+ });
4105
+ }
4106
+ function getNumberWithOrdinal(n) {
4107
+ const s = ['th', 'st', 'nd', 'rd'], v = n % 100;
4108
+ return n + (s[(v - 20) % 10] || s[v] || s[0]);
4109
+ }
4110
+ function isValidNetwork(network) {
4111
+ return !!networks[network];
4112
+ }
4113
+ function isValidAddress(address$1) {
4114
+ return address.isAddress(address$1) && address$1 !== EMPTY_ADDRESS;
4115
+ }
4116
+ function isValidSnapshot(snapshot, network) {
4117
+ return (snapshot === 'latest' ||
4118
+ (typeof snapshot === 'number' && snapshot >= networks[network].start));
4119
+ }
4120
+ function isStarknetAddress(address) {
4121
+ if (!address)
4122
+ return false;
4123
+ try {
4124
+ starknet$1.validateAndParseAddress(address);
4125
+ return true;
4126
+ }
4127
+ catch (e) {
4128
+ return false;
4129
+ }
4130
+ }
4131
+ function isEvmAddress(address$1) {
4132
+ return address.isAddress(address$1);
4133
+ }
4134
+ function getFormattedAddress(address$1, format = ['evm', 'starknet']) {
4135
+ if (format.includes('evm') && address.isAddress(address$1))
4136
+ return address.getAddress(address$1);
4137
+ if (format.includes('starknet') && isStarknetAddress(address$1))
4138
+ return starknet$1.validateAndParseAddress(address$1);
4139
+ throw new Error(`Invalid address: ${address$1}`);
4140
+ }
4141
+ function inputError(message) {
4142
+ return Promise.reject(new Error(message));
4143
+ }
4144
+ var utils = {
4145
+ call,
4146
+ multicall,
4147
+ subgraphRequest,
4148
+ ipfsGet,
4149
+ getUrl,
4150
+ getJSON,
4151
+ sendTransaction,
4152
+ getScores,
4153
+ getVp,
4154
+ validateSchema,
4155
+ getEnsTextRecord,
4156
+ getSpaceUri,
4157
+ getEnsOwner,
4158
+ getSpaceController,
4159
+ getDelegatesBySpace,
4160
+ clone,
4161
+ sleep,
4162
+ getNumberWithOrdinal,
4163
+ voting,
4164
+ getProvider,
4165
+ signMessage,
4166
+ getBlockNumber,
4167
+ Multicaller,
4168
+ getSnapshots,
4169
+ getHash: getHash$2,
4170
+ verify: verify$2,
4171
+ validate,
4172
+ isStarknetAddress,
4173
+ isEvmAddress,
4174
+ getFormattedAddress,
4175
+ SNAPSHOT_SUBGRAPH_URL
4254
4176
  };
4255
4177
 
4256
- var index = {
4257
- Client: Client,
4258
- Client712: Client,
4259
- schemas: schemas,
4260
- utils: utils
4178
+ var index = {
4179
+ Client: Client,
4180
+ Client712: Client,
4181
+ schemas,
4182
+ utils
4261
4183
  };
4262
4184
 
4263
4185
  module.exports = index;