@snapshot-labs/snapshot.js 0.4.5 → 0.4.8

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.
@@ -1146,6 +1146,255 @@ function getSnapshots(network, snapshot, provider, networks) {
1146
1146
  });
1147
1147
  }
1148
1148
 
1149
+ var providers = {};
1150
+ function getProvider(network) {
1151
+ var url = "https://brovider.xyz/" + network;
1152
+ if (providers[network])
1153
+ return providers[network];
1154
+ providers[network] = new providers$1.StaticJsonRpcProvider({ url: url, timeout: 25000 });
1155
+ return providers[network];
1156
+ }
1157
+
1158
+ function validate(author, space, proposal, options) {
1159
+ var _a, _b;
1160
+ return __awaiter(this, void 0, void 0, function () {
1161
+ var strategies, onlyMembers, minScore, members, scores, totalScore;
1162
+ return __generator(this, function (_c) {
1163
+ switch (_c.label) {
1164
+ case 0:
1165
+ strategies = options.strategies || space.strategies;
1166
+ onlyMembers = options.onlyMembers || ((_a = space.filters) === null || _a === void 0 ? void 0 : _a.onlyMembers);
1167
+ minScore = options.minScore || ((_b = space.filters) === null || _b === void 0 ? void 0 : _b.minScore);
1168
+ members = (space.members || []).map(function (address) { return address.toLowerCase(); });
1169
+ if (members.includes(author.toLowerCase()))
1170
+ return [2 /*return*/, true];
1171
+ if (onlyMembers)
1172
+ return [2 /*return*/, false];
1173
+ if (!minScore) return [3 /*break*/, 2];
1174
+ return [4 /*yield*/, getScores(space.id || space.key, strategies, space.network, [author])];
1175
+ case 1:
1176
+ scores = _c.sent();
1177
+ totalScore = scores
1178
+ .map(function (score) { return Object.values(score).reduce(function (a, b) { return a + b; }, 0); })
1179
+ .reduce(function (a, b) { return a + b; }, 0);
1180
+ if (totalScore < minScore)
1181
+ return [2 /*return*/, false];
1182
+ _c.label = 2;
1183
+ case 2: return [2 /*return*/, true];
1184
+ }
1185
+ });
1186
+ });
1187
+ }
1188
+
1189
+ /**
1190
+ * Aave Space Validation proposal validation uses:
1191
+ * - Proposition power of GovernanceStrategy contract
1192
+ * - Other active Aave Snapshot voting strategies
1193
+ *
1194
+ * The current validation implementation mutates the "strategies" field of the space
1195
+ * to be able to use proposition power instead of voting power for "aave-governance-power".
1196
+ *
1197
+ */
1198
+ function validate$1(author, space, proposal, options) {
1199
+ var _a, _b;
1200
+ return __awaiter(this, void 0, void 0, function () {
1201
+ var onlyMembers, minScore, members, strategies, aaveGovernanceStrategyIndex, scores, totalScore;
1202
+ return __generator(this, function (_c) {
1203
+ switch (_c.label) {
1204
+ case 0:
1205
+ onlyMembers = options.onlyMembers || ((_a = space.filters) === null || _a === void 0 ? void 0 : _a.onlyMembers);
1206
+ minScore = options.minScore || ((_b = space.filters) === null || _b === void 0 ? void 0 : _b.minScore);
1207
+ members = (space.members || []).map(function (address) { return address.toLowerCase(); });
1208
+ strategies = __spread(space.strategies);
1209
+ aaveGovernanceStrategyIndex = strategies.findIndex(function (_a) {
1210
+ var name = _a.name;
1211
+ return name === 'aave-governance-power';
1212
+ });
1213
+ // Use the proposition power instead of voting power
1214
+ if (aaveGovernanceStrategyIndex >= 0) {
1215
+ strategies[aaveGovernanceStrategyIndex].params.powerType = 'proposition';
1216
+ }
1217
+ if (members.includes(author.toLowerCase()))
1218
+ return [2 /*return*/, true];
1219
+ if (onlyMembers)
1220
+ return [2 /*return*/, false];
1221
+ if (!minScore) return [3 /*break*/, 2];
1222
+ return [4 /*yield*/, getScores(space.id || space.key, strategies, space.network, [author])];
1223
+ case 1:
1224
+ scores = _c.sent();
1225
+ totalScore = scores
1226
+ .map(function (score) { return Object.values(score).reduce(function (a, b) { return a + b; }, 0); })
1227
+ .reduce(function (a, b) { return a + b; }, 0);
1228
+ if (totalScore < minScore)
1229
+ return [2 /*return*/, false];
1230
+ _c.label = 2;
1231
+ case 2: return [2 /*return*/, true];
1232
+ }
1233
+ });
1234
+ });
1235
+ }
1236
+
1237
+ /**
1238
+ * Nouns Space Validation proposal validation uses:
1239
+ *
1240
+ * The current validation implementation mutates the "strategies" field of the space
1241
+ * to be able to use proposition power instead of voting power for "nouns-rfp-power".
1242
+ *
1243
+ */
1244
+ function validate$2(author, space, proposal, options) {
1245
+ var _a, _b;
1246
+ return __awaiter(this, void 0, void 0, function () {
1247
+ var onlyMembers, minScore, members, strategies, nounsRFPStrategyIndex, scores, totalScore;
1248
+ return __generator(this, function (_c) {
1249
+ switch (_c.label) {
1250
+ case 0:
1251
+ onlyMembers = options.onlyMembers || ((_a = space.filters) === null || _a === void 0 ? void 0 : _a.onlyMembers);
1252
+ minScore = options.minScore || ((_b = space.filters) === null || _b === void 0 ? void 0 : _b.minScore);
1253
+ members = (space.members || []).map(function (address) { return address.toLowerCase(); });
1254
+ strategies = __spread(space.strategies);
1255
+ nounsRFPStrategyIndex = strategies.findIndex(function (_a) {
1256
+ var name = _a.name;
1257
+ return name === 'nouns-rfp-power';
1258
+ });
1259
+ // Use the proposition power instead of the voting power
1260
+ if (nounsRFPStrategyIndex >= 0) {
1261
+ strategies[nounsRFPStrategyIndex].params.powerType = 'proposition';
1262
+ }
1263
+ if (members.includes(author.toLowerCase()))
1264
+ return [2 /*return*/, true];
1265
+ if (onlyMembers)
1266
+ return [2 /*return*/, false];
1267
+ if (!minScore) return [3 /*break*/, 2];
1268
+ return [4 /*yield*/, getScores(space.id || space.key, strategies, space.network, [author])];
1269
+ case 1:
1270
+ scores = _c.sent();
1271
+ totalScore = scores
1272
+ .map(function (score) { return Object.values(score).reduce(function (a, b) { return a + b; }, 0); })
1273
+ .reduce(function (a, b) { return a + b; }, 0);
1274
+ if (totalScore < minScore)
1275
+ return [2 /*return*/, false];
1276
+ _c.label = 2;
1277
+ case 2: return [2 /*return*/, true];
1278
+ }
1279
+ });
1280
+ });
1281
+ }
1282
+
1283
+ var validations = {
1284
+ basic: validate,
1285
+ aave: validate$1,
1286
+ nouns: validate$2
1287
+ };
1288
+
1289
+ function verifyDefault(address, sig, hash, provider) {
1290
+ return __awaiter(this, void 0, void 0, function () {
1291
+ var returnValue, magicValue, abi, e_1;
1292
+ return __generator(this, function (_a) {
1293
+ switch (_a.label) {
1294
+ case 0:
1295
+ magicValue = '0x1626ba7e';
1296
+ abi = 'function isValidSignature(bytes32 _hash, bytes memory _signature) public view returns (bytes4 magicValue)';
1297
+ _a.label = 1;
1298
+ case 1:
1299
+ _a.trys.push([1, 3, , 4]);
1300
+ return [4 /*yield*/, call(provider, [abi], [address, 'isValidSignature', [bytes.arrayify(hash), sig]])];
1301
+ case 2:
1302
+ returnValue = _a.sent();
1303
+ return [3 /*break*/, 4];
1304
+ case 3:
1305
+ e_1 = _a.sent();
1306
+ console.log(e_1);
1307
+ return [2 /*return*/, false];
1308
+ case 4: return [2 /*return*/, returnValue.toLowerCase() === magicValue.toLowerCase()];
1309
+ }
1310
+ });
1311
+ });
1312
+ }
1313
+ function verifyOldVersion(address, sig, hash, provider) {
1314
+ return __awaiter(this, void 0, void 0, function () {
1315
+ var returnValue, magicValue, abi, e_2;
1316
+ return __generator(this, function (_a) {
1317
+ switch (_a.label) {
1318
+ case 0:
1319
+ magicValue = '0x20c13b0b';
1320
+ abi = 'function isValidSignature(bytes _hash, bytes memory _signature) public view returns (bytes4 magicValue)';
1321
+ _a.label = 1;
1322
+ case 1:
1323
+ _a.trys.push([1, 3, , 4]);
1324
+ return [4 /*yield*/, call(provider, [abi], [address, 'isValidSignature', [bytes.arrayify(hash), sig]])];
1325
+ case 2:
1326
+ returnValue = _a.sent();
1327
+ return [3 /*break*/, 4];
1328
+ case 3:
1329
+ e_2 = _a.sent();
1330
+ console.log(e_2);
1331
+ return [2 /*return*/, false];
1332
+ case 4: return [2 /*return*/, returnValue.toLowerCase() === magicValue.toLowerCase()];
1333
+ }
1334
+ });
1335
+ });
1336
+ }
1337
+ function verify(address, sig, hash, network) {
1338
+ if (network === void 0) { network = '1'; }
1339
+ return __awaiter(this, void 0, void 0, function () {
1340
+ var provider;
1341
+ return __generator(this, function (_a) {
1342
+ switch (_a.label) {
1343
+ case 0:
1344
+ provider = getProvider(network);
1345
+ return [4 /*yield*/, verifyDefault(address, sig, hash, provider)];
1346
+ case 1:
1347
+ if (_a.sent())
1348
+ return [2 /*return*/, true];
1349
+ return [4 /*yield*/, verifyOldVersion(address, sig, hash, provider)];
1350
+ case 2: return [2 /*return*/, _a.sent()];
1351
+ }
1352
+ });
1353
+ });
1354
+ }
1355
+
1356
+ function getHash(data) {
1357
+ var domain = data.domain, types = data.types, message = data.message;
1358
+ return hash._TypedDataEncoder.hash(domain, types, message);
1359
+ }
1360
+ function verify$1(address, sig, data, network) {
1361
+ if (network === void 0) { network = '1'; }
1362
+ return __awaiter(this, void 0, void 0, function () {
1363
+ var domain, types, message, hash, recoverAddress;
1364
+ return __generator(this, function (_a) {
1365
+ switch (_a.label) {
1366
+ case 0:
1367
+ domain = data.domain, types = data.types, message = data.message;
1368
+ hash = getHash(data);
1369
+ console.log('Hash', hash);
1370
+ console.log('Address', address);
1371
+ try {
1372
+ recoverAddress = wallet.verifyTypedData(domain, types, message, sig);
1373
+ console.log('Recover address', recoverAddress);
1374
+ if (address === recoverAddress)
1375
+ return [2 /*return*/, true];
1376
+ }
1377
+ catch (e) {
1378
+ console.log('Could not recoverAddress:' + e.message);
1379
+ }
1380
+ console.log('Check EIP1271 signature');
1381
+ return [4 /*yield*/, verify(address, sig, hash, network)];
1382
+ case 1: return [2 /*return*/, _a.sent()];
1383
+ }
1384
+ });
1385
+ });
1386
+ }
1387
+
1388
+ var gateways = [
1389
+ "cloudflare-ipfs.com",
1390
+ "cf-ipfs.com",
1391
+ "ipfs.io",
1392
+ "ipfs.fleek.co",
1393
+ "gateway.pinata.cloud",
1394
+ "dweb.link",
1395
+ "ipfs.infura.io"
1396
+ ];
1397
+
1149
1398
  var networks = {
1150
1399
  "1": {
1151
1400
  key: "1",
@@ -1736,6 +1985,7 @@ var networks = {
1736
1985
  network: "Mainnet",
1737
1986
  multicall: "0x7f6A10218264a22B4309F3896745687E712962a0",
1738
1987
  rpc: [
1988
+ "https://rpc.ankr.com/fantom",
1739
1989
  "https://rpc.ftm.tools",
1740
1990
  "https://rpcapi.fantom.network"
1741
1991
  ],
@@ -1853,6 +2103,23 @@ var networks = {
1853
2103
  explorer: "https://explorer.thetatoken.org",
1854
2104
  start: 12559216,
1855
2105
  logo: "ipfs://QmcMP9s9mUqfT2SCiP75sZgAVVev7H7RQAKiSx9xWEDKwe"
2106
+ },
2107
+ "416": {
2108
+ key: "416",
2109
+ name: "SX Network",
2110
+ shortName: "SX",
2111
+ chainId: 416,
2112
+ network: "mainnet",
2113
+ multicall: "0x834a005DDCF990Ba1a79f259e840e58F2D14F49a",
2114
+ rpc: [
2115
+ "https://rpc.sx.technology"
2116
+ ],
2117
+ ws: [
2118
+ "wss://rpc.sx.technology/ws"
2119
+ ],
2120
+ explorer: "https://explorer.sx.technology",
2121
+ start: 2680605,
2122
+ logo: "ipfs://QmSXLXqyr2H6Ja5XrmznXbWTEvF2gFaL8RXNXgyLmDHjAF"
1856
2123
  },
1857
2124
  "499": {
1858
2125
  key: "499",
@@ -2252,9 +2519,9 @@ var networks = {
2252
2519
  network: "Arbitrum mainnet",
2253
2520
  multicall: "0x7A7443F8c577d537f1d8cD4a629d40a3148Dd7ee",
2254
2521
  rpc: [
2522
+ "https://rpc.ankr.com/arbitrum",
2255
2523
  "https://speedy-nodes-nyc.moralis.io/9e03baabdc27be2a35bdec4a/arbitrum/mainnet",
2256
- "https://arb-mainnet.g.alchemy.com/v2/JDvtNGwnHhTltIwfnxQocKwKkCTKA1DL",
2257
- "https://rpc.ankr.com/arbitrum"
2524
+ "https://arb-mainnet.g.alchemy.com/v2/JDvtNGwnHhTltIwfnxQocKwKkCTKA1DL"
2258
2525
  ],
2259
2526
  explorer: "https://arbiscan.io",
2260
2527
  start: 256508,
@@ -2527,268 +2794,6 @@ var networks = {
2527
2794
  }
2528
2795
  };
2529
2796
 
2530
- var providers = {};
2531
- function getProvider(network, type) {
2532
- if (type === void 0) { type = 'archive'; }
2533
- var _a;
2534
- var url = networks[network].rpc[0];
2535
- if (type === 'light' && ((_a = networks[network].light) === null || _a === void 0 ? void 0 : _a.length))
2536
- url = networks[network].light[0];
2537
- if (type === 'brovider')
2538
- url = "https://brovider.xyz/" + network;
2539
- var connectionInfo = typeof url === 'object'
2540
- ? __assign(__assign({}, url), { timeout: 25000 }) : { url: url, timeout: 25000 };
2541
- if (!providers[network] || !providers[network][type]) {
2542
- providers[network] = __assign({}, providers[network]);
2543
- providers[network][type] = new providers$1.StaticJsonRpcProvider(connectionInfo);
2544
- }
2545
- return providers[network][type];
2546
- }
2547
-
2548
- function validate(author, space, proposal, options) {
2549
- var _a, _b;
2550
- return __awaiter(this, void 0, void 0, function () {
2551
- var strategies, onlyMembers, minScore, members, scores, totalScore;
2552
- return __generator(this, function (_c) {
2553
- switch (_c.label) {
2554
- case 0:
2555
- strategies = options.strategies || space.strategies;
2556
- onlyMembers = options.onlyMembers || ((_a = space.filters) === null || _a === void 0 ? void 0 : _a.onlyMembers);
2557
- minScore = options.minScore || ((_b = space.filters) === null || _b === void 0 ? void 0 : _b.minScore);
2558
- members = (space.members || []).map(function (address) { return address.toLowerCase(); });
2559
- if (members.includes(author.toLowerCase()))
2560
- return [2 /*return*/, true];
2561
- if (onlyMembers)
2562
- return [2 /*return*/, false];
2563
- if (!minScore) return [3 /*break*/, 2];
2564
- return [4 /*yield*/, getScores(space.id || space.key, strategies, space.network, [author])];
2565
- case 1:
2566
- scores = _c.sent();
2567
- totalScore = scores
2568
- .map(function (score) { return Object.values(score).reduce(function (a, b) { return a + b; }, 0); })
2569
- .reduce(function (a, b) { return a + b; }, 0);
2570
- if (totalScore < minScore)
2571
- return [2 /*return*/, false];
2572
- _c.label = 2;
2573
- case 2: return [2 /*return*/, true];
2574
- }
2575
- });
2576
- });
2577
- }
2578
-
2579
- /**
2580
- * Aave Space Validation proposal validation uses:
2581
- * - Proposition power of GovernanceStrategy contract
2582
- * - Other active Aave Snapshot voting strategies
2583
- *
2584
- * The current validation implementation mutates the "strategies" field of the space
2585
- * to be able to use proposition power instead of voting power for "aave-governance-power".
2586
- *
2587
- */
2588
- function validate$1(author, space, proposal, options) {
2589
- var _a, _b;
2590
- return __awaiter(this, void 0, void 0, function () {
2591
- var onlyMembers, minScore, members, strategies, aaveGovernanceStrategyIndex, scores, totalScore;
2592
- return __generator(this, function (_c) {
2593
- switch (_c.label) {
2594
- case 0:
2595
- onlyMembers = options.onlyMembers || ((_a = space.filters) === null || _a === void 0 ? void 0 : _a.onlyMembers);
2596
- minScore = options.minScore || ((_b = space.filters) === null || _b === void 0 ? void 0 : _b.minScore);
2597
- members = (space.members || []).map(function (address) { return address.toLowerCase(); });
2598
- strategies = __spread(space.strategies);
2599
- aaveGovernanceStrategyIndex = strategies.findIndex(function (_a) {
2600
- var name = _a.name;
2601
- return name === 'aave-governance-power';
2602
- });
2603
- // Use the proposition power instead of voting power
2604
- if (aaveGovernanceStrategyIndex >= 0) {
2605
- strategies[aaveGovernanceStrategyIndex].params.powerType = 'proposition';
2606
- }
2607
- if (members.includes(author.toLowerCase()))
2608
- return [2 /*return*/, true];
2609
- if (onlyMembers)
2610
- return [2 /*return*/, false];
2611
- if (!minScore) return [3 /*break*/, 2];
2612
- return [4 /*yield*/, getScores(space.id || space.key, strategies, space.network, [author])];
2613
- case 1:
2614
- scores = _c.sent();
2615
- totalScore = scores
2616
- .map(function (score) { return Object.values(score).reduce(function (a, b) { return a + b; }, 0); })
2617
- .reduce(function (a, b) { return a + b; }, 0);
2618
- if (totalScore < minScore)
2619
- return [2 /*return*/, false];
2620
- _c.label = 2;
2621
- case 2: return [2 /*return*/, true];
2622
- }
2623
- });
2624
- });
2625
- }
2626
-
2627
- /**
2628
- * Nouns Space Validation proposal validation uses:
2629
- *
2630
- * The current validation implementation mutates the "strategies" field of the space
2631
- * to be able to use proposition power instead of voting power for "nouns-rfp-power".
2632
- *
2633
- */
2634
- function validate$2(author, space, proposal, options) {
2635
- var _a, _b;
2636
- return __awaiter(this, void 0, void 0, function () {
2637
- var onlyMembers, minScore, members, strategies, nounsRFPStrategyIndex, scores, totalScore;
2638
- return __generator(this, function (_c) {
2639
- switch (_c.label) {
2640
- case 0:
2641
- onlyMembers = options.onlyMembers || ((_a = space.filters) === null || _a === void 0 ? void 0 : _a.onlyMembers);
2642
- minScore = options.minScore || ((_b = space.filters) === null || _b === void 0 ? void 0 : _b.minScore);
2643
- members = (space.members || []).map(function (address) { return address.toLowerCase(); });
2644
- strategies = __spread(space.strategies);
2645
- nounsRFPStrategyIndex = strategies.findIndex(function (_a) {
2646
- var name = _a.name;
2647
- return name === 'nouns-rfp-power';
2648
- });
2649
- // Use the proposition power instead of the voting power
2650
- if (nounsRFPStrategyIndex >= 0) {
2651
- strategies[nounsRFPStrategyIndex].params.powerType = 'proposition';
2652
- }
2653
- if (members.includes(author.toLowerCase()))
2654
- return [2 /*return*/, true];
2655
- if (onlyMembers)
2656
- return [2 /*return*/, false];
2657
- if (!minScore) return [3 /*break*/, 2];
2658
- return [4 /*yield*/, getScores(space.id || space.key, strategies, space.network, [author])];
2659
- case 1:
2660
- scores = _c.sent();
2661
- totalScore = scores
2662
- .map(function (score) { return Object.values(score).reduce(function (a, b) { return a + b; }, 0); })
2663
- .reduce(function (a, b) { return a + b; }, 0);
2664
- if (totalScore < minScore)
2665
- return [2 /*return*/, false];
2666
- _c.label = 2;
2667
- case 2: return [2 /*return*/, true];
2668
- }
2669
- });
2670
- });
2671
- }
2672
-
2673
- var validations = {
2674
- basic: validate,
2675
- aave: validate$1,
2676
- nouns: validate$2
2677
- };
2678
-
2679
- function verifyDefault(address, sig, hash, provider) {
2680
- return __awaiter(this, void 0, void 0, function () {
2681
- var returnValue, magicValue, abi, e_1;
2682
- return __generator(this, function (_a) {
2683
- switch (_a.label) {
2684
- case 0:
2685
- magicValue = '0x1626ba7e';
2686
- abi = 'function isValidSignature(bytes32 _hash, bytes memory _signature) public view returns (bytes4 magicValue)';
2687
- _a.label = 1;
2688
- case 1:
2689
- _a.trys.push([1, 3, , 4]);
2690
- return [4 /*yield*/, call(provider, [abi], [address, 'isValidSignature', [bytes.arrayify(hash), sig]])];
2691
- case 2:
2692
- returnValue = _a.sent();
2693
- return [3 /*break*/, 4];
2694
- case 3:
2695
- e_1 = _a.sent();
2696
- console.log(e_1);
2697
- return [2 /*return*/, false];
2698
- case 4: return [2 /*return*/, returnValue.toLowerCase() === magicValue.toLowerCase()];
2699
- }
2700
- });
2701
- });
2702
- }
2703
- function verifyOldVersion(address, sig, hash, provider) {
2704
- return __awaiter(this, void 0, void 0, function () {
2705
- var returnValue, magicValue, abi, e_2;
2706
- return __generator(this, function (_a) {
2707
- switch (_a.label) {
2708
- case 0:
2709
- magicValue = '0x20c13b0b';
2710
- abi = 'function isValidSignature(bytes _hash, bytes memory _signature) public view returns (bytes4 magicValue)';
2711
- _a.label = 1;
2712
- case 1:
2713
- _a.trys.push([1, 3, , 4]);
2714
- return [4 /*yield*/, call(provider, [abi], [address, 'isValidSignature', [bytes.arrayify(hash), sig]])];
2715
- case 2:
2716
- returnValue = _a.sent();
2717
- return [3 /*break*/, 4];
2718
- case 3:
2719
- e_2 = _a.sent();
2720
- console.log(e_2);
2721
- return [2 /*return*/, false];
2722
- case 4: return [2 /*return*/, returnValue.toLowerCase() === magicValue.toLowerCase()];
2723
- }
2724
- });
2725
- });
2726
- }
2727
- function verify(address, sig, hash, network) {
2728
- if (network === void 0) { network = '1'; }
2729
- return __awaiter(this, void 0, void 0, function () {
2730
- var provider;
2731
- return __generator(this, function (_a) {
2732
- switch (_a.label) {
2733
- case 0:
2734
- provider = getProvider(network, 'brovider');
2735
- return [4 /*yield*/, verifyDefault(address, sig, hash, provider)];
2736
- case 1:
2737
- if (_a.sent())
2738
- return [2 /*return*/, true];
2739
- return [4 /*yield*/, verifyOldVersion(address, sig, hash, provider)];
2740
- case 2: return [2 /*return*/, _a.sent()];
2741
- }
2742
- });
2743
- });
2744
- }
2745
-
2746
- function getHash(data) {
2747
- var domain = data.domain, types = data.types, message = data.message;
2748
- return hash._TypedDataEncoder.hash(domain, types, message);
2749
- }
2750
- function verify$1(address, sig, data, network) {
2751
- if (network === void 0) { network = '1'; }
2752
- return __awaiter(this, void 0, void 0, function () {
2753
- var domain, types, message, hash, recoverAddress;
2754
- return __generator(this, function (_a) {
2755
- switch (_a.label) {
2756
- case 0:
2757
- domain = data.domain, types = data.types, message = data.message;
2758
- hash = getHash(data);
2759
- console.log('Hash', hash);
2760
- console.log('Address', address);
2761
- try {
2762
- recoverAddress = wallet.verifyTypedData(domain, types, message, sig);
2763
- console.log('Recover address', recoverAddress);
2764
- if (address === recoverAddress)
2765
- return [2 /*return*/, true];
2766
- }
2767
- catch (e) {
2768
- console.log('Could not recoverAddress:' + e.message);
2769
- }
2770
- console.log('Check EIP1271 signature');
2771
- return [4 /*yield*/, verify(address, sig, hash, network)];
2772
- case 1: return [2 /*return*/, _a.sent()];
2773
- }
2774
- });
2775
- });
2776
- }
2777
-
2778
- var gateways = [
2779
- "cloudflare-ipfs.com",
2780
- "cf-ipfs.com",
2781
- "ipfs.io",
2782
- "ipfs.fleek.co",
2783
- "gateway.pinata.cloud",
2784
- "dweb.link",
2785
- "ipfs.infura.io"
2786
- ];
2787
-
2788
- function isValidChoice(voteChoice, proposalChoices) {
2789
- return (typeof voteChoice === 'number' &&
2790
- (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[voteChoice - 1]) !== undefined);
2791
- }
2792
2797
  var SingleChoiceVoting = /** @class */ (function () {
2793
2798
  function SingleChoiceVoting(proposal, votes, strategies, selected) {
2794
2799
  this.proposal = proposal;
@@ -2796,10 +2801,14 @@ var SingleChoiceVoting = /** @class */ (function () {
2796
2801
  this.strategies = strategies;
2797
2802
  this.selected = selected;
2798
2803
  }
2804
+ SingleChoiceVoting.prototype.isValidChoice = function (voteChoice, proposalChoices) {
2805
+ return (typeof voteChoice === 'number' &&
2806
+ (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[voteChoice - 1]) !== undefined);
2807
+ };
2799
2808
  SingleChoiceVoting.prototype.getValidVotes = function () {
2800
2809
  var _this = this;
2801
2810
  return this.votes.filter(function (vote) {
2802
- return isValidChoice(vote.choice, _this.proposal.choices);
2811
+ return _this.isValidChoice(vote.choice, _this.proposal.choices);
2803
2812
  });
2804
2813
  };
2805
2814
  SingleChoiceVoting.prototype.getScores = function () {
@@ -2830,15 +2839,6 @@ var SingleChoiceVoting = /** @class */ (function () {
2830
2839
  return SingleChoiceVoting;
2831
2840
  }());
2832
2841
 
2833
- function isValidChoice$1(voteChoice, proposalChoices) {
2834
- return (Array.isArray(voteChoice) &&
2835
- // If voteChoice index is not in proposalChoices, return false
2836
- voteChoice.every(function (choice) { return (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[choice - 1]) !== undefined; }) &&
2837
- // If any voteChoice is duplicated, return false
2838
- voteChoice.length === new Set(voteChoice).size &&
2839
- // If voteChoice is empty, return false
2840
- voteChoice.length > 0);
2841
- }
2842
2842
  var ApprovalVoting = /** @class */ (function () {
2843
2843
  function ApprovalVoting(proposal, votes, strategies, selected) {
2844
2844
  this.proposal = proposal;
@@ -2846,10 +2846,19 @@ var ApprovalVoting = /** @class */ (function () {
2846
2846
  this.strategies = strategies;
2847
2847
  this.selected = selected;
2848
2848
  }
2849
+ ApprovalVoting.prototype.isValidChoice = function (voteChoice, proposalChoices) {
2850
+ return (Array.isArray(voteChoice) &&
2851
+ // If voteChoice index is not in proposalChoices, return false
2852
+ voteChoice.every(function (choice) { return (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[choice - 1]) !== undefined; }) &&
2853
+ // If any voteChoice is duplicated, return false
2854
+ voteChoice.length === new Set(voteChoice).size &&
2855
+ // If voteChoice is empty, return false
2856
+ voteChoice.length > 0);
2857
+ };
2849
2858
  ApprovalVoting.prototype.getValidVotes = function () {
2850
2859
  var _this = this;
2851
2860
  return this.votes.filter(function (vote) {
2852
- return isValidChoice$1(vote.choice, _this.proposal.choices);
2861
+ return _this.isValidChoice(vote.choice, _this.proposal.choices);
2853
2862
  });
2854
2863
  };
2855
2864
  ApprovalVoting.prototype.getScores = function () {
@@ -2884,17 +2893,6 @@ var ApprovalVoting = /** @class */ (function () {
2884
2893
  return ApprovalVoting;
2885
2894
  }());
2886
2895
 
2887
- function isValidChoice$2(voteChoice, proposalChoices) {
2888
- return (typeof voteChoice === 'object' &&
2889
- !Array.isArray(voteChoice) &&
2890
- voteChoice !== null &&
2891
- // If voteChoice object keys are not in choices, return false
2892
- Object.keys(voteChoice).every(function (key) { return (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[Number(key) - 1]) !== undefined; }) &&
2893
- // If voteChoice object is empty, return false
2894
- Object.keys(voteChoice).length > 0 &&
2895
- // If voteChoice object values are not a positive integer, return false
2896
- Object.values(voteChoice).every(function (value) { return typeof value === 'number' && value > 0; }));
2897
- }
2898
2896
  function percentageOfTotal(i, values, total) {
2899
2897
  var reducedTotal = total.reduce(function (a, b) { return a + b; }, 0);
2900
2898
  var percent = (values[i] / reducedTotal) * 100;
@@ -2910,10 +2908,21 @@ var QuadraticVoting = /** @class */ (function () {
2910
2908
  this.strategies = strategies;
2911
2909
  this.selected = selected;
2912
2910
  }
2911
+ QuadraticVoting.prototype.isValidChoice = function (voteChoice, proposalChoices) {
2912
+ return (typeof voteChoice === 'object' &&
2913
+ !Array.isArray(voteChoice) &&
2914
+ voteChoice !== null &&
2915
+ // If voteChoice object keys are not in choices, return false
2916
+ Object.keys(voteChoice).every(function (key) { return (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[Number(key) - 1]) !== undefined; }) &&
2917
+ // If voteChoice object is empty, return false
2918
+ Object.keys(voteChoice).length > 0 &&
2919
+ // If voteChoice object values are not a positive integer, return false
2920
+ Object.values(voteChoice).every(function (value) { return typeof value === 'number' && value > 0; }));
2921
+ };
2913
2922
  QuadraticVoting.prototype.getValidVotes = function () {
2914
2923
  var _this = this;
2915
2924
  return this.votes.filter(function (vote) {
2916
- return isValidChoice$2(vote.choice, _this.proposal.choices);
2925
+ return _this.isValidChoice(vote.choice, _this.proposal.choices);
2917
2926
  });
2918
2927
  };
2919
2928
  QuadraticVoting.prototype.getScores = function () {
@@ -2966,18 +2975,6 @@ var QuadraticVoting = /** @class */ (function () {
2966
2975
  return QuadraticVoting;
2967
2976
  }());
2968
2977
 
2969
- function isValidChoice$3(voteChoice, proposalChoices) {
2970
- return (Array.isArray(voteChoice) &&
2971
- // If voteChoice index is not in choices, return false
2972
- voteChoice.every(function (voteChoice) { return (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[voteChoice - 1]) !== undefined; }) &&
2973
- // If any voteChoice is duplicated, return false
2974
- voteChoice.length === new Set(voteChoice).size &&
2975
- // If voteChoice is empty, return false
2976
- voteChoice.length > 0 &&
2977
- // If not all proposalChoices are selected, return false
2978
- // TODO: We should add support for pacial bailout in the future
2979
- voteChoice.length === proposalChoices.length);
2980
- }
2981
2978
  function irv(ballots, rounds) {
2982
2979
  var candidates = __spread(new Set(ballots.map(function (vote) { return vote[0]; }).flat()));
2983
2980
  var votes = Object.entries(ballots.reduce(function (votes, _a, i, src) {
@@ -3041,10 +3038,22 @@ var RankedChoiceVoting = /** @class */ (function () {
3041
3038
  this.strategies = strategies;
3042
3039
  this.selected = selected;
3043
3040
  }
3041
+ RankedChoiceVoting.prototype.isValidChoice = function (voteChoice, proposalChoices) {
3042
+ return (Array.isArray(voteChoice) &&
3043
+ // If voteChoice index is not in choices, return false
3044
+ voteChoice.every(function (voteChoice) { return (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[voteChoice - 1]) !== undefined; }) &&
3045
+ // If any voteChoice is duplicated, return false
3046
+ voteChoice.length === new Set(voteChoice).size &&
3047
+ // If voteChoice is empty, return false
3048
+ voteChoice.length > 0 &&
3049
+ // If not all proposalChoices are selected, return false
3050
+ // TODO: We should add support for pacial bailout in the future
3051
+ voteChoice.length === proposalChoices.length);
3052
+ };
3044
3053
  RankedChoiceVoting.prototype.getValidVotes = function () {
3045
3054
  var _this = this;
3046
3055
  return this.votes.filter(function (vote) {
3047
- return isValidChoice$3(vote.choice, _this.proposal.choices);
3056
+ return _this.isValidChoice(vote.choice, _this.proposal.choices);
3048
3057
  });
3049
3058
  };
3050
3059
  RankedChoiceVoting.prototype.getScores = function () {
@@ -3082,19 +3091,6 @@ var RankedChoiceVoting = /** @class */ (function () {
3082
3091
  return RankedChoiceVoting;
3083
3092
  }());
3084
3093
 
3085
- function isValidChoice$4(voteChoice, proposalChoices) {
3086
- return (typeof voteChoice === 'object' &&
3087
- !Array.isArray(voteChoice) &&
3088
- voteChoice !== null &&
3089
- // If voteChoice object keys are not in choices, return false
3090
- Object.keys(voteChoice).every(function (key) { return (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[Number(key) - 1]) !== undefined; }) &&
3091
- // If voteChoice object is empty, return false
3092
- Object.keys(voteChoice).length > 0 &&
3093
- // If voteChoice object values are not a positive integer, return false
3094
- Object.values(voteChoice).every(function (value) { return typeof value === 'number' && value > 0; }) &&
3095
- // If voteChoice is empty, return false
3096
- Object.keys(voteChoice).length > 0);
3097
- }
3098
3094
  function percentageOfTotal$1(i, values, total) {
3099
3095
  var reducedTotal = total.reduce(function (a, b) { return a + b; }, 0);
3100
3096
  var percent = (values[i] / reducedTotal) * 100;
@@ -3110,10 +3106,23 @@ var WeightedVoting = /** @class */ (function () {
3110
3106
  this.strategies = strategies;
3111
3107
  this.selected = selected;
3112
3108
  }
3109
+ WeightedVoting.prototype.isValidChoice = function (voteChoice, proposalChoices) {
3110
+ return (typeof voteChoice === 'object' &&
3111
+ !Array.isArray(voteChoice) &&
3112
+ voteChoice !== null &&
3113
+ // If voteChoice object keys are not in choices, return false
3114
+ Object.keys(voteChoice).every(function (key) { return (proposalChoices === null || proposalChoices === void 0 ? void 0 : proposalChoices[Number(key) - 1]) !== undefined; }) &&
3115
+ // If voteChoice object is empty, return false
3116
+ Object.keys(voteChoice).length > 0 &&
3117
+ // If voteChoice object values are not a positive integer, return false
3118
+ Object.values(voteChoice).every(function (value) { return typeof value === 'number' && value > 0; }) &&
3119
+ // If voteChoice is empty, return false
3120
+ Object.keys(voteChoice).length > 0);
3121
+ };
3113
3122
  WeightedVoting.prototype.getValidVotes = function () {
3114
3123
  var _this = this;
3115
3124
  return this.votes.filter(function (vote) {
3116
- return isValidChoice$4(vote.choice, _this.proposal.choices);
3125
+ return _this.isValidChoice(vote.choice, _this.proposal.choices);
3117
3126
  });
3118
3127
  };
3119
3128
  WeightedVoting.prototype.getScores = function () {
@@ -3390,7 +3399,7 @@ function getEnsTextRecord(ens, record, network) {
3390
3399
  if (network === void 0) { network = '1'; }
3391
3400
  var address = networks[network].ensResolver || networks['1'].ensResolver;
3392
3401
  var ensHash = ethEnsNamehash.hash(ethEnsNamehash.normalize(ens));
3393
- var provider = getProvider(network, 'brovider');
3402
+ var provider = getProvider(network);
3394
3403
  return call(provider, ENS_RESOLVER_ABI, [address, 'text', [ensHash, record]]);
3395
3404
  }
3396
3405
  function getSpaceUri(id, network) {