@snapshot-labs/snapshot.js 0.10.0 → 0.11.0

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/dist/index.d.ts CHANGED
@@ -450,7 +450,10 @@ declare const _default: {
450
450
  type: string;
451
451
  title: string;
452
452
  minLength: number;
453
- maxLength: number;
453
+ maxLengthWithSpaceType: {
454
+ default: number;
455
+ turbo: number;
456
+ };
454
457
  };
455
458
  discussion: {
456
459
  type: string;
@@ -446,7 +446,10 @@ declare const _default: {
446
446
  type: string;
447
447
  title: string;
448
448
  minLength: number;
449
- maxLength: number;
449
+ maxLengthWithSpaceType: {
450
+ default: number;
451
+ turbo: number;
452
+ };
450
453
  };
451
454
  discussion: {
452
455
  type: string;
@@ -1098,7 +1098,10 @@ var definitions$2 = {
1098
1098
  type: "string",
1099
1099
  title: "body",
1100
1100
  minLength: 0,
1101
- maxLength: 20000
1101
+ maxLengthWithSpaceType: {
1102
+ "default": 10000,
1103
+ turbo: 20000
1104
+ }
1102
1105
  },
1103
1106
  discussion: {
1104
1107
  type: "string",
@@ -2987,17 +2990,6 @@ var networks = {
2987
2990
  }
2988
2991
  };
2989
2992
 
2990
- var delegationSubgraphs = {
2991
- "1": "https://subgrapher.snapshot.org/gateway-arbitrum.network.thegraph.com/api/0f15b42bdeff7a063a4e1757d7e2f99e/subgraphs/id/4YgtogVaqoM8CErHWDK8mKQ825BcVdKB8vBYmb4avAQo",
2992
- "5": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-goerli",
2993
- "10": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-optimism",
2994
- "56": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-binance-smart-chain",
2995
- "100": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-gnosis-chain",
2996
- "137": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-polygon",
2997
- "250": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-fantom",
2998
- "42161": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-arbitrum"
2999
- };
3000
-
3001
2993
  var SingleChoiceVoting = /** @class */ (function () {
3002
2994
  function SingleChoiceVoting(proposal, votes, strategies, selected) {
3003
2995
  this.proposal = proposal;
@@ -3409,7 +3401,113 @@ var voting = {
3409
3401
  basic: SingleChoiceVoting
3410
3402
  };
3411
3403
 
3404
+ var delegationSubgraphs = {
3405
+ "1": "https://subgrapher.snapshot.org/gateway-arbitrum.network.thegraph.com/api/0f15b42bdeff7a063a4e1757d7e2f99e/subgraphs/id/4YgtogVaqoM8CErHWDK8mKQ825BcVdKB8vBYmb4avAQo",
3406
+ "5": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-goerli",
3407
+ "10": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-optimism",
3408
+ "56": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-binance-smart-chain",
3409
+ "100": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-gnosis-chain",
3410
+ "137": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-polygon",
3411
+ "250": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-fantom",
3412
+ "42161": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-arbitrum"
3413
+ };
3414
+
3412
3415
  var SNAPSHOT_SUBGRAPH_URL = delegationSubgraphs;
3416
+ var PAGE_SIZE = 1000;
3417
+ function getDelegatesBySpace(network, space, snapshot, options) {
3418
+ if (snapshot === void 0) { snapshot = 'latest'; }
3419
+ if (options === void 0) { options = {}; }
3420
+ return __awaiter(this, void 0, void 0, function () {
3421
+ var subgraphUrl, pivot, result, spaceIn, newResults;
3422
+ return __generator(this, function (_a) {
3423
+ switch (_a.label) {
3424
+ case 0:
3425
+ subgraphUrl = options.subgraphUrl || SNAPSHOT_SUBGRAPH_URL[network];
3426
+ if (!subgraphUrl) {
3427
+ return [2 /*return*/, Promise.reject("Delegation subgraph not available for network " + network)];
3428
+ }
3429
+ pivot = 0;
3430
+ result = new Map();
3431
+ spaceIn = buildSpaceIn(space);
3432
+ _a.label = 1;
3433
+ case 1:
3434
+ return [4 /*yield*/, fetchData({
3435
+ url: subgraphUrl,
3436
+ spaces: spaceIn,
3437
+ pivot: pivot,
3438
+ snapshot: snapshot
3439
+ })];
3440
+ case 2:
3441
+ newResults = _a.sent();
3442
+ if (checkAllDuplicates(newResults)) {
3443
+ throw new Error('Unable to paginate delegation');
3444
+ }
3445
+ newResults.forEach(function (delegation) {
3446
+ concatUniqueDelegation(result, delegation);
3447
+ pivot = delegation.timestamp;
3448
+ });
3449
+ if (newResults.length < PAGE_SIZE)
3450
+ return [3 /*break*/, 3];
3451
+ return [3 /*break*/, 1];
3452
+ case 3: return [2 /*return*/, __spread(result.values())];
3453
+ }
3454
+ });
3455
+ });
3456
+ }
3457
+ function checkAllDuplicates(delegations) {
3458
+ return (delegations.length === PAGE_SIZE &&
3459
+ delegations[0].timestamp === delegations[delegations.length - 1].timestamp);
3460
+ }
3461
+ function delegationKey(delegation) {
3462
+ return delegation.delegator + "-" + delegation.delegate + "-" + delegation.space;
3463
+ }
3464
+ function concatUniqueDelegation(result, delegation) {
3465
+ var key = delegationKey(delegation);
3466
+ if (!result.has(key)) {
3467
+ result.set(key, delegation);
3468
+ }
3469
+ }
3470
+ function buildSpaceIn(space) {
3471
+ var spaces = ['', space];
3472
+ if (space.includes('.eth'))
3473
+ spaces.push(space.replace('.eth', ''));
3474
+ return spaces;
3475
+ }
3476
+ function fetchData(_a) {
3477
+ var url = _a.url, spaces = _a.spaces, pivot = _a.pivot, snapshot = _a.snapshot;
3478
+ return __awaiter(this, void 0, void 0, function () {
3479
+ var params;
3480
+ return __generator(this, function (_b) {
3481
+ switch (_b.label) {
3482
+ case 0:
3483
+ params = {
3484
+ delegations: {
3485
+ __args: {
3486
+ where: {
3487
+ space_in: spaces,
3488
+ timestamp_gte: pivot
3489
+ },
3490
+ first: PAGE_SIZE,
3491
+ skip: 0,
3492
+ orderBy: 'timestamp',
3493
+ orderDirection: 'asc'
3494
+ },
3495
+ delegator: true,
3496
+ space: true,
3497
+ delegate: true,
3498
+ timestamp: true
3499
+ }
3500
+ };
3501
+ if (snapshot !== 'latest') {
3502
+ params.delegations.__args.block = { number: snapshot };
3503
+ }
3504
+ return [4 /*yield*/, subgraphRequest(url, params)];
3505
+ case 1: return [2 /*return*/, (_b.sent()).delegations || []];
3506
+ }
3507
+ });
3508
+ });
3509
+ }
3510
+
3413
3511
  var ENS_RESOLVER_ABI = [
3414
3512
  'function text(bytes32 node, string calldata key) external view returns (string memory)'
3415
3513
  ];
@@ -3969,58 +4067,6 @@ function getSpaceController(id, network, options) {
3969
4067
  });
3970
4068
  });
3971
4069
  }
3972
- function getDelegatesBySpace(network, space, snapshot, options) {
3973
- if (snapshot === void 0) { snapshot = 'latest'; }
3974
- if (options === void 0) { options = {}; }
3975
- return __awaiter(this, void 0, void 0, function () {
3976
- var subgraphUrl, spaceIn, PAGE_SIZE, result, page, params, pageResult, pageDelegations;
3977
- return __generator(this, function (_a) {
3978
- switch (_a.label) {
3979
- case 0:
3980
- subgraphUrl = options.subgraphUrl || SNAPSHOT_SUBGRAPH_URL[network];
3981
- if (!subgraphUrl) {
3982
- return [2 /*return*/, Promise.reject("Delegation subgraph not available for network " + network)];
3983
- }
3984
- spaceIn = ['', space];
3985
- if (space.includes('.eth'))
3986
- spaceIn.push(space.replace('.eth', ''));
3987
- PAGE_SIZE = 1000;
3988
- result = [];
3989
- page = 0;
3990
- params = {
3991
- delegations: {
3992
- __args: {
3993
- where: {
3994
- space_in: spaceIn
3995
- },
3996
- first: PAGE_SIZE,
3997
- skip: 0
3998
- },
3999
- delegator: true,
4000
- space: true,
4001
- delegate: true
4002
- }
4003
- };
4004
- if (snapshot !== 'latest') {
4005
- params.delegations.__args.block = { number: snapshot };
4006
- }
4007
- _a.label = 1;
4008
- case 1:
4009
- params.delegations.__args.skip = page * PAGE_SIZE;
4010
- return [4 /*yield*/, subgraphRequest(subgraphUrl, params)];
4011
- case 2:
4012
- pageResult = _a.sent();
4013
- pageDelegations = pageResult.delegations || [];
4014
- result = result.concat(pageDelegations);
4015
- page++;
4016
- if (pageDelegations.length < PAGE_SIZE)
4017
- return [3 /*break*/, 3];
4018
- return [3 /*break*/, 1];
4019
- case 3: return [2 /*return*/, result];
4020
- }
4021
- });
4022
- });
4023
- }
4024
4070
  function clone(item) {
4025
4071
  return JSON.parse(JSON.stringify(item));
4026
4072
  }
@@ -1089,7 +1089,10 @@ var definitions$2 = {
1089
1089
  type: "string",
1090
1090
  title: "body",
1091
1091
  minLength: 0,
1092
- maxLength: 20000
1092
+ maxLengthWithSpaceType: {
1093
+ "default": 10000,
1094
+ turbo: 20000
1095
+ }
1093
1096
  },
1094
1097
  discussion: {
1095
1098
  type: "string",
@@ -2978,17 +2981,6 @@ var networks = {
2978
2981
  }
2979
2982
  };
2980
2983
 
2981
- var delegationSubgraphs = {
2982
- "1": "https://subgrapher.snapshot.org/gateway-arbitrum.network.thegraph.com/api/0f15b42bdeff7a063a4e1757d7e2f99e/subgraphs/id/4YgtogVaqoM8CErHWDK8mKQ825BcVdKB8vBYmb4avAQo",
2983
- "5": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-goerli",
2984
- "10": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-optimism",
2985
- "56": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-binance-smart-chain",
2986
- "100": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-gnosis-chain",
2987
- "137": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-polygon",
2988
- "250": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-fantom",
2989
- "42161": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-arbitrum"
2990
- };
2991
-
2992
2984
  var SingleChoiceVoting = /** @class */ (function () {
2993
2985
  function SingleChoiceVoting(proposal, votes, strategies, selected) {
2994
2986
  this.proposal = proposal;
@@ -3400,7 +3392,113 @@ var voting = {
3400
3392
  basic: SingleChoiceVoting
3401
3393
  };
3402
3394
 
3395
+ var delegationSubgraphs = {
3396
+ "1": "https://subgrapher.snapshot.org/gateway-arbitrum.network.thegraph.com/api/0f15b42bdeff7a063a4e1757d7e2f99e/subgraphs/id/4YgtogVaqoM8CErHWDK8mKQ825BcVdKB8vBYmb4avAQo",
3397
+ "5": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-goerli",
3398
+ "10": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-optimism",
3399
+ "56": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-binance-smart-chain",
3400
+ "100": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-gnosis-chain",
3401
+ "137": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-polygon",
3402
+ "250": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-fantom",
3403
+ "42161": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-arbitrum"
3404
+ };
3405
+
3403
3406
  var SNAPSHOT_SUBGRAPH_URL = delegationSubgraphs;
3407
+ var PAGE_SIZE = 1000;
3408
+ function getDelegatesBySpace(network, space, snapshot, options) {
3409
+ if (snapshot === void 0) { snapshot = 'latest'; }
3410
+ if (options === void 0) { options = {}; }
3411
+ return __awaiter(this, void 0, void 0, function () {
3412
+ var subgraphUrl, pivot, result, spaceIn, newResults;
3413
+ return __generator(this, function (_a) {
3414
+ switch (_a.label) {
3415
+ case 0:
3416
+ subgraphUrl = options.subgraphUrl || SNAPSHOT_SUBGRAPH_URL[network];
3417
+ if (!subgraphUrl) {
3418
+ return [2 /*return*/, Promise.reject("Delegation subgraph not available for network " + network)];
3419
+ }
3420
+ pivot = 0;
3421
+ result = new Map();
3422
+ spaceIn = buildSpaceIn(space);
3423
+ _a.label = 1;
3424
+ case 1:
3425
+ return [4 /*yield*/, fetchData({
3426
+ url: subgraphUrl,
3427
+ spaces: spaceIn,
3428
+ pivot: pivot,
3429
+ snapshot: snapshot
3430
+ })];
3431
+ case 2:
3432
+ newResults = _a.sent();
3433
+ if (checkAllDuplicates(newResults)) {
3434
+ throw new Error('Unable to paginate delegation');
3435
+ }
3436
+ newResults.forEach(function (delegation) {
3437
+ concatUniqueDelegation(result, delegation);
3438
+ pivot = delegation.timestamp;
3439
+ });
3440
+ if (newResults.length < PAGE_SIZE)
3441
+ return [3 /*break*/, 3];
3442
+ return [3 /*break*/, 1];
3443
+ case 3: return [2 /*return*/, __spread(result.values())];
3444
+ }
3445
+ });
3446
+ });
3447
+ }
3448
+ function checkAllDuplicates(delegations) {
3449
+ return (delegations.length === PAGE_SIZE &&
3450
+ delegations[0].timestamp === delegations[delegations.length - 1].timestamp);
3451
+ }
3452
+ function delegationKey(delegation) {
3453
+ return delegation.delegator + "-" + delegation.delegate + "-" + delegation.space;
3454
+ }
3455
+ function concatUniqueDelegation(result, delegation) {
3456
+ var key = delegationKey(delegation);
3457
+ if (!result.has(key)) {
3458
+ result.set(key, delegation);
3459
+ }
3460
+ }
3461
+ function buildSpaceIn(space) {
3462
+ var spaces = ['', space];
3463
+ if (space.includes('.eth'))
3464
+ spaces.push(space.replace('.eth', ''));
3465
+ return spaces;
3466
+ }
3467
+ function fetchData(_a) {
3468
+ var url = _a.url, spaces = _a.spaces, pivot = _a.pivot, snapshot = _a.snapshot;
3469
+ return __awaiter(this, void 0, void 0, function () {
3470
+ var params;
3471
+ return __generator(this, function (_b) {
3472
+ switch (_b.label) {
3473
+ case 0:
3474
+ params = {
3475
+ delegations: {
3476
+ __args: {
3477
+ where: {
3478
+ space_in: spaces,
3479
+ timestamp_gte: pivot
3480
+ },
3481
+ first: PAGE_SIZE,
3482
+ skip: 0,
3483
+ orderBy: 'timestamp',
3484
+ orderDirection: 'asc'
3485
+ },
3486
+ delegator: true,
3487
+ space: true,
3488
+ delegate: true,
3489
+ timestamp: true
3490
+ }
3491
+ };
3492
+ if (snapshot !== 'latest') {
3493
+ params.delegations.__args.block = { number: snapshot };
3494
+ }
3495
+ return [4 /*yield*/, subgraphRequest(url, params)];
3496
+ case 1: return [2 /*return*/, (_b.sent()).delegations || []];
3497
+ }
3498
+ });
3499
+ });
3500
+ }
3501
+
3404
3502
  var ENS_RESOLVER_ABI = [
3405
3503
  'function text(bytes32 node, string calldata key) external view returns (string memory)'
3406
3504
  ];
@@ -3960,58 +4058,6 @@ function getSpaceController(id, network, options) {
3960
4058
  });
3961
4059
  });
3962
4060
  }
3963
- function getDelegatesBySpace(network, space, snapshot, options) {
3964
- if (snapshot === void 0) { snapshot = 'latest'; }
3965
- if (options === void 0) { options = {}; }
3966
- return __awaiter(this, void 0, void 0, function () {
3967
- var subgraphUrl, spaceIn, PAGE_SIZE, result, page, params, pageResult, pageDelegations;
3968
- return __generator(this, function (_a) {
3969
- switch (_a.label) {
3970
- case 0:
3971
- subgraphUrl = options.subgraphUrl || SNAPSHOT_SUBGRAPH_URL[network];
3972
- if (!subgraphUrl) {
3973
- return [2 /*return*/, Promise.reject("Delegation subgraph not available for network " + network)];
3974
- }
3975
- spaceIn = ['', space];
3976
- if (space.includes('.eth'))
3977
- spaceIn.push(space.replace('.eth', ''));
3978
- PAGE_SIZE = 1000;
3979
- result = [];
3980
- page = 0;
3981
- params = {
3982
- delegations: {
3983
- __args: {
3984
- where: {
3985
- space_in: spaceIn
3986
- },
3987
- first: PAGE_SIZE,
3988
- skip: 0
3989
- },
3990
- delegator: true,
3991
- space: true,
3992
- delegate: true
3993
- }
3994
- };
3995
- if (snapshot !== 'latest') {
3996
- params.delegations.__args.block = { number: snapshot };
3997
- }
3998
- _a.label = 1;
3999
- case 1:
4000
- params.delegations.__args.skip = page * PAGE_SIZE;
4001
- return [4 /*yield*/, subgraphRequest(subgraphUrl, params)];
4002
- case 2:
4003
- pageResult = _a.sent();
4004
- pageDelegations = pageResult.delegations || [];
4005
- result = result.concat(pageDelegations);
4006
- page++;
4007
- if (pageDelegations.length < PAGE_SIZE)
4008
- return [3 /*break*/, 3];
4009
- return [3 /*break*/, 1];
4010
- case 3: return [2 /*return*/, result];
4011
- }
4012
- });
4013
- });
4014
- }
4015
4061
  function clone(item) {
4016
4062
  return JSON.parse(JSON.stringify(item));
4017
4063
  }