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