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