@snapshot-labs/snapshot.js 0.11.38 → 0.12.0-beta.1
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/LICENSE +0 -0
- package/dist/index.d.ts +2 -29
- package/dist/schemas/index.d.ts +2 -29
- package/dist/sign/types.d.ts +0 -3
- package/dist/snapshot.cjs.js +1549 -1906
- package/dist/snapshot.esm.js +1550 -1907
- package/dist/snapshot.js/src/index.d.ts +677 -0
- package/dist/snapshot.js/src/sign/index.d.ts +28 -0
- 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/package.json +5 -3
- package/src/sign/hashedTypes.json +5 -1
- package/src/utils/dist/provider.js +47 -0
- package/src/utils/provider.ts +8 -2
- package/src/utils/web3.ts +1 -1
- package/src/utils.spec.js +36 -1
- package/src/utils.ts +44 -14
- 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,256 +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: 'network', type: 'string' },
|
|
264
|
-
{ name: 'space', type: 'string' },
|
|
265
|
-
{ name: 'timestamp', type: 'uint64' }
|
|
266
|
-
]
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
Unfollow: [
|
|
270
|
-
{ name: 'from', type: 'address' },
|
|
271
|
-
{ name: 'network', type: 'string' },
|
|
272
|
-
{ name: 'space', type: 'string' },
|
|
273
|
-
{ name: 'timestamp', type: 'uint64' }
|
|
274
|
-
]
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
Subscribe: [
|
|
278
|
-
{ name: 'from', type: 'address' },
|
|
279
|
-
{ name: 'space', type: 'string' },
|
|
280
|
-
{ name: 'timestamp', type: 'uint64' }
|
|
281
|
-
]
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
Unsubscribe: [
|
|
285
|
-
{ name: 'from', type: 'address' },
|
|
286
|
-
{ name: 'space', type: 'string' },
|
|
287
|
-
{ name: 'timestamp', type: 'uint64' }
|
|
288
|
-
]
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
Profile: [
|
|
292
|
-
{ name: 'from', type: 'address' },
|
|
293
|
-
{ name: 'timestamp', type: 'uint64' },
|
|
294
|
-
{ name: 'profile', type: 'string' }
|
|
295
|
-
]
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
Statement: [
|
|
299
|
-
{ name: 'from', type: 'address' },
|
|
300
|
-
{ name: 'timestamp', type: 'uint64' },
|
|
301
|
-
{ name: 'space', type: 'string' },
|
|
302
|
-
{ name: 'about', type: 'string' },
|
|
303
|
-
{ name: 'statement', type: 'string' },
|
|
304
|
-
{ name: 'discourse', type: 'string' },
|
|
305
|
-
{ name: 'status', type: 'string' },
|
|
306
|
-
{ name: 'network', type: 'string' }
|
|
307
|
-
]
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
Alias: [
|
|
311
|
-
{ name: 'from', type: 'address' },
|
|
312
|
-
{ name: 'alias', type: 'address' },
|
|
313
|
-
{ name: 'timestamp', type: 'uint64' }
|
|
314
|
-
]
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
DeleteSpace: [
|
|
318
|
-
{ name: 'from', type: 'address' },
|
|
319
|
-
{ name: 'space', type: 'string' },
|
|
320
|
-
{ name: 'timestamp', type: 'uint64' }
|
|
321
|
-
]
|
|
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
|
+
]
|
|
322
261
|
};
|
|
323
262
|
|
|
324
263
|
var livenet = {
|
|
@@ -339,255 +278,163 @@ var constants = {
|
|
|
339
278
|
local: local
|
|
340
279
|
};
|
|
341
280
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
name: NAME,
|
|
346
|
-
version: VERSION
|
|
347
|
-
// chainId: 1
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
address = address.replace(constants.
|
|
354
|
-
address = address
|
|
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
|
-
return
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
type = type2 ? voteString2Types : voteStringTypes;
|
|
500
|
-
delete message.privacy;
|
|
501
|
-
// @ts-ignore
|
|
502
|
-
delete message.type;
|
|
503
|
-
return [4 /*yield*/, this.sign(web3, address, message, type)];
|
|
504
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
505
|
-
}
|
|
506
|
-
});
|
|
507
|
-
});
|
|
508
|
-
};
|
|
509
|
-
Client.prototype.follow = function (web3, address, message) {
|
|
510
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
511
|
-
return __generator(this, function (_a) {
|
|
512
|
-
switch (_a.label) {
|
|
513
|
-
case 0: return [4 /*yield*/, this.sign(web3, address, message, followTypes)];
|
|
514
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
515
|
-
}
|
|
516
|
-
});
|
|
517
|
-
});
|
|
518
|
-
};
|
|
519
|
-
Client.prototype.unfollow = function (web3, address, message) {
|
|
520
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
521
|
-
return __generator(this, function (_a) {
|
|
522
|
-
switch (_a.label) {
|
|
523
|
-
case 0: return [4 /*yield*/, this.sign(web3, address, message, unfollowTypes)];
|
|
524
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
525
|
-
}
|
|
526
|
-
});
|
|
527
|
-
});
|
|
528
|
-
};
|
|
529
|
-
Client.prototype.subscribe = function (web3, address, message) {
|
|
530
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
531
|
-
return __generator(this, function (_a) {
|
|
532
|
-
switch (_a.label) {
|
|
533
|
-
case 0: return [4 /*yield*/, this.sign(web3, address, message, subscribeTypes)];
|
|
534
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
535
|
-
}
|
|
536
|
-
});
|
|
537
|
-
});
|
|
538
|
-
};
|
|
539
|
-
Client.prototype.unsubscribe = function (web3, address, message) {
|
|
540
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
541
|
-
return __generator(this, function (_a) {
|
|
542
|
-
switch (_a.label) {
|
|
543
|
-
case 0: return [4 /*yield*/, this.sign(web3, address, message, unsubscribeTypes)];
|
|
544
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
});
|
|
548
|
-
};
|
|
549
|
-
Client.prototype.profile = function (web3, address, message) {
|
|
550
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
551
|
-
return __generator(this, function (_a) {
|
|
552
|
-
switch (_a.label) {
|
|
553
|
-
case 0: return [4 /*yield*/, this.sign(web3, address, message, profileTypes)];
|
|
554
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
555
|
-
}
|
|
556
|
-
});
|
|
557
|
-
});
|
|
558
|
-
};
|
|
559
|
-
Client.prototype.statement = function (web3, address, message) {
|
|
560
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
561
|
-
return __generator(this, function (_a) {
|
|
562
|
-
switch (_a.label) {
|
|
563
|
-
case 0: return [4 /*yield*/, this.sign(web3, address, message, statementTypes)];
|
|
564
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
});
|
|
568
|
-
};
|
|
569
|
-
Client.prototype.alias = function (web3, address, message) {
|
|
570
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
571
|
-
return __generator(this, function (_a) {
|
|
572
|
-
switch (_a.label) {
|
|
573
|
-
case 0: return [4 /*yield*/, this.sign(web3, address, message, aliasTypes)];
|
|
574
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
575
|
-
}
|
|
576
|
-
});
|
|
577
|
-
});
|
|
578
|
-
};
|
|
579
|
-
Client.prototype.deleteSpace = function (web3, address, message) {
|
|
580
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
581
|
-
return __generator(this, function (_a) {
|
|
582
|
-
switch (_a.label) {
|
|
583
|
-
case 0: return [4 /*yield*/, this.sign(web3, address, message, deleteSpaceType)];
|
|
584
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
|
-
});
|
|
588
|
-
};
|
|
589
|
-
return Client;
|
|
590
|
-
}());
|
|
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
|
+
}
|
|
591
438
|
|
|
592
439
|
var $schema = "http://json-schema.org/draft-07/schema#";
|
|
593
440
|
var $ref = "#/definitions/Space";
|
|
@@ -1436,250 +1283,254 @@ var alias = {
|
|
|
1436
1283
|
definitions: definitions$7
|
|
1437
1284
|
};
|
|
1438
1285
|
|
|
1439
|
-
var schemas = {
|
|
1440
|
-
space: space.definitions.Space,
|
|
1441
|
-
proposal: proposal.definitions.Proposal,
|
|
1442
|
-
updateProposal: updateProposal.definitions.UpdateProposal,
|
|
1443
|
-
vote: vote.definitions.Vote,
|
|
1444
|
-
profile: profile.definitions.Profile,
|
|
1445
|
-
statement: statement.definitions.Statement,
|
|
1446
|
-
zodiac: zodiac.definitions.Zodiac,
|
|
1447
|
-
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
|
|
1448
1295
|
};
|
|
1449
1296
|
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
this.options = {};
|
|
1453
|
-
this.calls = [];
|
|
1454
|
-
this.paths = [];
|
|
1455
|
-
this.network = network;
|
|
1456
|
-
this.provider = provider;
|
|
1457
|
-
this.abi = abi;
|
|
1458
|
-
this.options = options || {};
|
|
1459
|
-
}
|
|
1460
|
-
|
|
1461
|
-
this.calls.push([address, fn, params]);
|
|
1462
|
-
this.paths.push(path);
|
|
1463
|
-
return this;
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
result.forEach(function (r, i) { return set__default['default'](obj, _this.paths[i], r.length > 1 ? r : r[0]); });
|
|
1477
|
-
this.calls = [];
|
|
1478
|
-
this.paths = [];
|
|
1479
|
-
return [2 /*return*/, obj];
|
|
1480
|
-
}
|
|
1481
|
-
});
|
|
1482
|
-
});
|
|
1483
|
-
};
|
|
1484
|
-
return Multicaller;
|
|
1485
|
-
}());
|
|
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
|
+
}
|
|
1486
1323
|
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
function getSnapshots(
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
return [4 /*yield*/, subgraphRequest(url, query)];
|
|
1533
|
-
case 2:
|
|
1534
|
-
data = _a.sent();
|
|
1535
|
-
data.blocks.forEach(function (block) { return (snapshots[block.network] = block.number); });
|
|
1536
|
-
cache[cacheKey] = snapshots;
|
|
1537
|
-
return [2 /*return*/, snapshots];
|
|
1538
|
-
}
|
|
1539
|
-
});
|
|
1540
|
-
});
|
|
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
|
+
});
|
|
1541
1369
|
}
|
|
1542
1370
|
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
if (!providers[network])
|
|
1548
|
-
providers[network] = new providers$1.StaticJsonRpcProvider({
|
|
1549
|
-
url
|
|
1550
|
-
timeout: 25000,
|
|
1551
|
-
allowGzip: true
|
|
1552
|
-
}, Number(network));
|
|
1553
|
-
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];
|
|
1554
1382
|
}
|
|
1555
1383
|
|
|
1556
|
-
function signMessage(web3, msg, address) {
|
|
1557
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
}
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
switch (_a.label) {
|
|
1573
|
-
case 0:
|
|
1574
|
-
_a.trys.push([0, 2, , 3]);
|
|
1575
|
-
return [4 /*yield*/, provider.getBlockNumber()];
|
|
1576
|
-
case 1:
|
|
1577
|
-
blockNumber = _a.sent();
|
|
1578
|
-
return [2 /*return*/, parseInt(blockNumber)];
|
|
1579
|
-
case 2:
|
|
1580
|
-
e_1 = _a.sent();
|
|
1581
|
-
return [2 /*return*/, Promise.reject()];
|
|
1582
|
-
case 3: return [2 /*return*/];
|
|
1583
|
-
}
|
|
1584
|
-
});
|
|
1585
|
-
});
|
|
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
|
+
});
|
|
1586
1400
|
}
|
|
1587
1401
|
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
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
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
}
|
|
1631
|
-
function
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
return [4 /*yield*/, verifyOldVersion(address, sig, hash, provider)];
|
|
1645
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
1646
|
-
}
|
|
1647
|
-
});
|
|
1648
|
-
});
|
|
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
|
+
});
|
|
1649
1458
|
}
|
|
1650
1459
|
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
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
|
+
});
|
|
1683
1534
|
}
|
|
1684
1535
|
|
|
1685
1536
|
var gateways = [
|
|
@@ -3350,415 +3201,345 @@ var networks = {
|
|
|
3350
3201
|
}
|
|
3351
3202
|
};
|
|
3352
3203
|
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
this.proposal = proposal;
|
|
3356
|
-
this.votes = votes;
|
|
3357
|
-
this.strategies = strategies;
|
|
3358
|
-
this.selected = selected;
|
|
3359
|
-
}
|
|
3360
|
-
|
|
3361
|
-
return (typeof voteChoice === 'number' &&
|
|
3362
|
-
(proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[voteChoice - 1]) !== undefined);
|
|
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
|
-
|
|
3390
|
-
|
|
3391
|
-
};
|
|
3392
|
-
SingleChoiceVoting.prototype.getChoiceString = function () {
|
|
3393
|
-
return this.proposal.choices[this.selected - 1];
|
|
3394
|
-
};
|
|
3395
|
-
return SingleChoiceVoting;
|
|
3396
|
-
}());
|
|
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
|
+
}
|
|
3397
3242
|
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
this.proposal = proposal;
|
|
3401
|
-
this.votes = votes;
|
|
3402
|
-
this.strategies = strategies;
|
|
3403
|
-
this.selected = selected;
|
|
3404
|
-
}
|
|
3405
|
-
|
|
3406
|
-
return (Array.isArray(voteChoice) &&
|
|
3407
|
-
// If voteChoice index is not in proposalChoices, return false
|
|
3408
|
-
voteChoice.every(
|
|
3409
|
-
// If any voteChoice is duplicated, return false
|
|
3410
|
-
voteChoice.length === new Set(voteChoice).size);
|
|
3411
|
-
}
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
ApprovalVoting.prototype.getScoresTotal = function () {
|
|
3437
|
-
return this.votes.reduce(function (a, b) { return a + b.balance; }, 0);
|
|
3438
|
-
};
|
|
3439
|
-
ApprovalVoting.prototype.getChoiceString = function () {
|
|
3440
|
-
var _this = this;
|
|
3441
|
-
if (!this.selected)
|
|
3442
|
-
return '';
|
|
3443
|
-
return this.proposal.choices
|
|
3444
|
-
.filter(function (choice, i) { return _this.selected.includes(i + 1); })
|
|
3445
|
-
.join(', ');
|
|
3446
|
-
};
|
|
3447
|
-
return ApprovalVoting;
|
|
3448
|
-
}());
|
|
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
|
+
}
|
|
3449
3281
|
|
|
3450
|
-
function calcPercentageOfSum(part, wholeArray) {
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
return isNaN(percent) ? 0 : percent;
|
|
3454
|
-
}
|
|
3455
|
-
function calcSqrt(percentageWeight, votingPower) {
|
|
3456
|
-
return Math.sqrt(percentageWeight * votingPower);
|
|
3457
|
-
}
|
|
3458
|
-
function calcSquare(num) {
|
|
3459
|
-
return num * num;
|
|
3460
|
-
}
|
|
3461
|
-
function calcReducedQuadraticScores(percentages, scoresTotal) {
|
|
3462
|
-
// Reduce each quadratic score so that the sum of quadratic scores matches
|
|
3463
|
-
// the total scores.
|
|
3464
|
-
// This is done to unsure that features like quorum still work as expected.
|
|
3465
|
-
return percentages.map(
|
|
3466
|
-
}
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
this.proposal = proposal;
|
|
3470
|
-
this.votes = votes;
|
|
3471
|
-
this.strategies = strategies;
|
|
3472
|
-
this.selected = selected;
|
|
3473
|
-
}
|
|
3474
|
-
|
|
3475
|
-
return (typeof voteChoice === 'object' &&
|
|
3476
|
-
!Array.isArray(voteChoice) &&
|
|
3477
|
-
voteChoice !== null &&
|
|
3478
|
-
// If voteChoice object keys are not in choices, return false
|
|
3479
|
-
Object.keys(voteChoice).every(
|
|
3480
|
-
// If voteChoice object is empty, return false
|
|
3481
|
-
Object.keys(voteChoice).length > 0 &&
|
|
3482
|
-
// If voteChoice object values have a negative number, return false
|
|
3483
|
-
Object.values(voteChoice).every(
|
|
3484
|
-
// If voteChoice doesn't have any positive value, return false
|
|
3485
|
-
Object.values(voteChoice).some(
|
|
3486
|
-
}
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
.map(
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
QuadraticVoting.prototype.getChoiceString = function () {
|
|
3538
|
-
var _this = this;
|
|
3539
|
-
return this.proposal.choices
|
|
3540
|
-
.map(function (choice, i) {
|
|
3541
|
-
if (_this.selected[i + 1]) {
|
|
3542
|
-
var percent = calcPercentageOfSum(_this.selected[i + 1], Object.values(_this.selected));
|
|
3543
|
-
return Math.round(percent * 1000) / 10 + "% for " + choice;
|
|
3544
|
-
}
|
|
3545
|
-
})
|
|
3546
|
-
.filter(function (el) { return el != null; })
|
|
3547
|
-
.join(', ');
|
|
3548
|
-
};
|
|
3549
|
-
return QuadraticVoting;
|
|
3550
|
-
}());
|
|
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
|
+
}
|
|
3551
3369
|
|
|
3552
|
-
function irv(ballots, rounds) {
|
|
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
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
}
|
|
3623
|
-
|
|
3624
|
-
return (
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
.filter(function (res) { return Number(res[0]) === i + 1; })
|
|
3651
|
-
.reduce(function (a, b) { return a + b[1][1][sI]; }, 0);
|
|
3652
|
-
});
|
|
3653
|
-
});
|
|
3654
|
-
};
|
|
3655
|
-
RankedChoiceVoting.prototype.getScoresTotal = function () {
|
|
3656
|
-
return this.votes.reduce(function (a, b) { return a + b.balance; }, 0);
|
|
3657
|
-
};
|
|
3658
|
-
RankedChoiceVoting.prototype.getChoiceString = function () {
|
|
3659
|
-
var _this = this;
|
|
3660
|
-
return this.selected
|
|
3661
|
-
.map(function (choice) {
|
|
3662
|
-
if (_this.proposal.choices[choice - 1])
|
|
3663
|
-
return _this.proposal.choices[choice - 1];
|
|
3664
|
-
})
|
|
3665
|
-
.map(function (el, i) { return "(" + getNumberWithOrdinal(i + 1) + ") " + el; })
|
|
3666
|
-
.join(', ');
|
|
3667
|
-
};
|
|
3668
|
-
return RankedChoiceVoting;
|
|
3669
|
-
}());
|
|
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
|
+
}
|
|
3670
3468
|
|
|
3671
|
-
function percentageOfTotal(i, values, total) {
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
return isNaN(percent) ? 0 : percent;
|
|
3675
|
-
}
|
|
3676
|
-
function weightedPower(i, choice, balance) {
|
|
3677
|
-
return ((percentageOfTotal(i + 1, choice, Object.values(choice)) / 100) * balance);
|
|
3678
|
-
}
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
this.proposal = proposal;
|
|
3682
|
-
this.votes = votes;
|
|
3683
|
-
this.strategies = strategies;
|
|
3684
|
-
this.selected = selected;
|
|
3685
|
-
}
|
|
3686
|
-
|
|
3687
|
-
return (typeof voteChoice === 'object' &&
|
|
3688
|
-
!Array.isArray(voteChoice) &&
|
|
3689
|
-
voteChoice !== null &&
|
|
3690
|
-
// If voteChoice object keys are not in choices, return false
|
|
3691
|
-
Object.keys(voteChoice).every(
|
|
3692
|
-
// If voteChoice object is empty, return false
|
|
3693
|
-
Object.keys(voteChoice).length > 0 &&
|
|
3694
|
-
// If voteChoice object values have a negative number, return false
|
|
3695
|
-
Object.values(voteChoice).every(
|
|
3696
|
-
// If voteChoice doesn't have any positive value, return false
|
|
3697
|
-
Object.values(voteChoice).some(
|
|
3698
|
-
}
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
.map(
|
|
3715
|
-
.
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
.map(
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
};
|
|
3738
|
-
WeightedVoting.prototype.getScoresTotal = function () {
|
|
3739
|
-
return this.votes.reduce(function (a, b) { return a + b.balance; }, 0);
|
|
3740
|
-
};
|
|
3741
|
-
WeightedVoting.prototype.getChoiceString = function () {
|
|
3742
|
-
var _this = this;
|
|
3743
|
-
return this.proposal.choices
|
|
3744
|
-
.map(function (choice, i) {
|
|
3745
|
-
if (_this.selected[i + 1]) {
|
|
3746
|
-
return Math.round(percentageOfTotal(i + 1, _this.selected, Object.values(_this.selected)) * 10) / 10 + "% for " + choice;
|
|
3747
|
-
}
|
|
3748
|
-
})
|
|
3749
|
-
.filter(function (el) { return el != null; })
|
|
3750
|
-
.join(', ');
|
|
3751
|
-
};
|
|
3752
|
-
return WeightedVoting;
|
|
3753
|
-
}());
|
|
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
|
+
}
|
|
3754
3535
|
|
|
3755
|
-
var voting = {
|
|
3756
|
-
'single-choice': SingleChoiceVoting,
|
|
3757
|
-
approval: ApprovalVoting,
|
|
3758
|
-
quadratic: QuadraticVoting,
|
|
3759
|
-
'ranked-choice': RankedChoiceVoting,
|
|
3760
|
-
weighted: WeightedVoting,
|
|
3761
|
-
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
|
|
3762
3543
|
};
|
|
3763
3544
|
|
|
3764
3545
|
var delegationSubgraphs = {
|
|
@@ -3772,771 +3553,633 @@ var delegationSubgraphs = {
|
|
|
3772
3553
|
"11155111": "https://subgrapher.snapshot.org/delegation/11155111"
|
|
3773
3554
|
};
|
|
3774
3555
|
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
function getDelegatesBySpace(
|
|
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
|
-
first: PAGE_SIZE,
|
|
3851
|
-
skip: 0,
|
|
3852
|
-
orderBy: 'timestamp',
|
|
3853
|
-
orderDirection: 'asc'
|
|
3854
|
-
},
|
|
3855
|
-
delegator: true,
|
|
3856
|
-
space: true,
|
|
3857
|
-
delegate: true,
|
|
3858
|
-
timestamp: true
|
|
3859
|
-
}
|
|
3860
|
-
};
|
|
3861
|
-
if (snapshot !== 'latest') {
|
|
3862
|
-
params.delegations.__args.block = { number: snapshot };
|
|
3863
|
-
}
|
|
3864
|
-
return [4 /*yield*/, subgraphRequest(url, params)];
|
|
3865
|
-
case 1: return [2 /*return*/, (_b.sent()).delegations || []];
|
|
3866
|
-
}
|
|
3867
|
-
});
|
|
3868
|
-
});
|
|
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
|
+
});
|
|
3869
3631
|
}
|
|
3870
3632
|
|
|
3871
|
-
|
|
3872
|
-
'function text(bytes32 node, string calldata key) external view returns (string memory)'
|
|
3873
|
-
];
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
Accept: 'application/json',
|
|
3877
|
-
'Content-Type': 'application/json'
|
|
3878
|
-
};
|
|
3879
|
-
|
|
3880
|
-
function formatScoreAPIUrl(url, options
|
|
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
|
-
}
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
return
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
!
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
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
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
}
|
|
4187
|
-
}
|
|
4188
|
-
|
|
4189
|
-
}
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
}
|
|
4379
|
-
function
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
console.log(e_6);
|
|
4415
|
-
return [2 /*return*/, null];
|
|
4416
|
-
case 3: return [2 /*return*/];
|
|
4417
|
-
}
|
|
4418
|
-
});
|
|
4419
|
-
});
|
|
4420
|
-
}
|
|
4421
|
-
function getEnsOwner(ens, network, options) {
|
|
4422
|
-
if (network === void 0) { network = '1'; }
|
|
4423
|
-
if (options === void 0) { options = {}; }
|
|
4424
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
4425
|
-
var registryAddress, provider, ensRegistry, ensNameWrapper, ensHash, owner, ensNameWrapperContract;
|
|
4426
|
-
return __generator(this, function (_a) {
|
|
4427
|
-
switch (_a.label) {
|
|
4428
|
-
case 0:
|
|
4429
|
-
registryAddress = '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e';
|
|
4430
|
-
provider = getProvider(network, options);
|
|
4431
|
-
ensRegistry = new contracts.Contract(registryAddress, ['function owner(bytes32) view returns (address)'], provider);
|
|
4432
|
-
ensNameWrapper = options.ensNameWrapper || networks[network].ensNameWrapper;
|
|
4433
|
-
ensHash = hash.namehash(hash.ensNormalize(ens));
|
|
4434
|
-
return [4 /*yield*/, ensRegistry.owner(ensHash)];
|
|
4435
|
-
case 1:
|
|
4436
|
-
owner = _a.sent();
|
|
4437
|
-
if (!(owner === ensNameWrapper)) return [3 /*break*/, 3];
|
|
4438
|
-
ensNameWrapperContract = new contracts.Contract(ensNameWrapper, ['function ownerOf(uint256) view returns (address)'], provider);
|
|
4439
|
-
return [4 /*yield*/, ensNameWrapperContract.ownerOf(ensHash)];
|
|
4440
|
-
case 2:
|
|
4441
|
-
owner = _a.sent();
|
|
4442
|
-
_a.label = 3;
|
|
4443
|
-
case 3: return [2 /*return*/, owner];
|
|
4444
|
-
}
|
|
4445
|
-
});
|
|
4446
|
-
});
|
|
4447
|
-
}
|
|
4448
|
-
function getSpaceController(id, network, options) {
|
|
4449
|
-
if (network === void 0) { network = '1'; }
|
|
4450
|
-
if (options === void 0) { options = {}; }
|
|
4451
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
4452
|
-
var spaceUri, isUriAddress, uriParts, position, address$1;
|
|
4453
|
-
return __generator(this, function (_a) {
|
|
4454
|
-
switch (_a.label) {
|
|
4455
|
-
case 0: return [4 /*yield*/, getSpaceUri(id, network, options)];
|
|
4456
|
-
case 1:
|
|
4457
|
-
spaceUri = _a.sent();
|
|
4458
|
-
if (spaceUri) {
|
|
4459
|
-
isUriAddress = address.isAddress(spaceUri);
|
|
4460
|
-
if (isUriAddress)
|
|
4461
|
-
return [2 /*return*/, spaceUri];
|
|
4462
|
-
uriParts = spaceUri.split('/');
|
|
4463
|
-
position = uriParts.includes('testnet') ? 5 : 4;
|
|
4464
|
-
address$1 = uriParts[position];
|
|
4465
|
-
isUriAddress = address.isAddress(address$1);
|
|
4466
|
-
if (isUriAddress)
|
|
4467
|
-
return [2 /*return*/, address$1];
|
|
4468
|
-
}
|
|
4469
|
-
return [4 /*yield*/, getEnsOwner(id, network, options)];
|
|
4470
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
4471
|
-
}
|
|
4472
|
-
});
|
|
4473
|
-
});
|
|
4474
|
-
}
|
|
4475
|
-
function clone(item) {
|
|
4476
|
-
return JSON.parse(JSON.stringify(item));
|
|
4477
|
-
}
|
|
4478
|
-
function sleep(time) {
|
|
4479
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
4480
|
-
return __generator(this, function (_a) {
|
|
4481
|
-
return [2 /*return*/, new Promise(function (resolve) {
|
|
4482
|
-
setTimeout(resolve, time);
|
|
4483
|
-
})];
|
|
4484
|
-
});
|
|
4485
|
-
});
|
|
4486
|
-
}
|
|
4487
|
-
function getNumberWithOrdinal(n) {
|
|
4488
|
-
var s = ['th', 'st', 'nd', 'rd'], v = n % 100;
|
|
4489
|
-
return n + (s[(v - 20) % 10] || s[v] || s[0]);
|
|
4490
|
-
}
|
|
4491
|
-
function isValidNetwork(network) {
|
|
4492
|
-
return !!networks[network];
|
|
4493
|
-
}
|
|
4494
|
-
function isValidAddress(address$1) {
|
|
4495
|
-
return address.isAddress(address$1) && address$1 !== EMPTY_ADDRESS;
|
|
4496
|
-
}
|
|
4497
|
-
function isValidSnapshot(snapshot, network) {
|
|
4498
|
-
return (snapshot === 'latest' ||
|
|
4499
|
-
(typeof snapshot === 'number' && snapshot >= networks[network].start));
|
|
4500
|
-
}
|
|
4501
|
-
function inputError(message) {
|
|
4502
|
-
return Promise.reject(new Error(message));
|
|
4503
|
-
}
|
|
4504
|
-
var utils = {
|
|
4505
|
-
call: call,
|
|
4506
|
-
multicall: multicall,
|
|
4507
|
-
subgraphRequest: subgraphRequest,
|
|
4508
|
-
ipfsGet: ipfsGet,
|
|
4509
|
-
getUrl: getUrl,
|
|
4510
|
-
getJSON: getJSON,
|
|
4511
|
-
sendTransaction: sendTransaction,
|
|
4512
|
-
getScores: getScores,
|
|
4513
|
-
getVp: getVp,
|
|
4514
|
-
validateSchema: validateSchema,
|
|
4515
|
-
getEnsTextRecord: getEnsTextRecord,
|
|
4516
|
-
getSpaceUri: getSpaceUri,
|
|
4517
|
-
getEnsOwner: getEnsOwner,
|
|
4518
|
-
getSpaceController: getSpaceController,
|
|
4519
|
-
getDelegatesBySpace: getDelegatesBySpace,
|
|
4520
|
-
clone: clone,
|
|
4521
|
-
sleep: sleep,
|
|
4522
|
-
getNumberWithOrdinal: getNumberWithOrdinal,
|
|
4523
|
-
voting: voting,
|
|
4524
|
-
getProvider: getProvider,
|
|
4525
|
-
signMessage: signMessage,
|
|
4526
|
-
getBlockNumber: getBlockNumber,
|
|
4527
|
-
Multicaller: Multicaller,
|
|
4528
|
-
getSnapshots: getSnapshots,
|
|
4529
|
-
getHash: getHash,
|
|
4530
|
-
verify: verify$1,
|
|
4531
|
-
validate: validate,
|
|
4532
|
-
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
|
|
4533
4176
|
};
|
|
4534
4177
|
|
|
4535
|
-
var index = {
|
|
4536
|
-
Client: Client,
|
|
4537
|
-
Client712: Client,
|
|
4538
|
-
schemas
|
|
4539
|
-
utils
|
|
4178
|
+
var index = {
|
|
4179
|
+
Client: Client,
|
|
4180
|
+
Client712: Client,
|
|
4181
|
+
schemas,
|
|
4182
|
+
utils
|
|
4540
4183
|
};
|
|
4541
4184
|
|
|
4542
4185
|
module.exports = index;
|