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