@snapshot-labs/snapshot.js 0.10.1 → 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.
@@ -2990,17 +2990,6 @@ var networks = {
2990
2990
  }
2991
2991
  };
2992
2992
 
2993
- var delegationSubgraphs = {
2994
- "1": "https://subgrapher.snapshot.org/gateway-arbitrum.network.thegraph.com/api/0f15b42bdeff7a063a4e1757d7e2f99e/subgraphs/id/4YgtogVaqoM8CErHWDK8mKQ825BcVdKB8vBYmb4avAQo",
2995
- "5": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-goerli",
2996
- "10": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-optimism",
2997
- "56": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-binance-smart-chain",
2998
- "100": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-gnosis-chain",
2999
- "137": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-polygon",
3000
- "250": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-fantom",
3001
- "42161": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-arbitrum"
3002
- };
3003
-
3004
2993
  var SingleChoiceVoting = /** @class */ (function () {
3005
2994
  function SingleChoiceVoting(proposal, votes, strategies, selected) {
3006
2995
  this.proposal = proposal;
@@ -3412,7 +3401,113 @@ var voting = {
3412
3401
  basic: SingleChoiceVoting
3413
3402
  };
3414
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
+
3415
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
+
3416
3511
  var ENS_RESOLVER_ABI = [
3417
3512
  'function text(bytes32 node, string calldata key) external view returns (string memory)'
3418
3513
  ];
@@ -3972,58 +4067,6 @@ function getSpaceController(id, network, options) {
3972
4067
  });
3973
4068
  });
3974
4069
  }
3975
- function getDelegatesBySpace(network, space, snapshot, options) {
3976
- if (snapshot === void 0) { snapshot = 'latest'; }
3977
- if (options === void 0) { options = {}; }
3978
- return __awaiter(this, void 0, void 0, function () {
3979
- var subgraphUrl, spaceIn, PAGE_SIZE, result, page, params, pageResult, pageDelegations;
3980
- return __generator(this, function (_a) {
3981
- switch (_a.label) {
3982
- case 0:
3983
- subgraphUrl = options.subgraphUrl || SNAPSHOT_SUBGRAPH_URL[network];
3984
- if (!subgraphUrl) {
3985
- return [2 /*return*/, Promise.reject("Delegation subgraph not available for network " + network)];
3986
- }
3987
- spaceIn = ['', space];
3988
- if (space.includes('.eth'))
3989
- spaceIn.push(space.replace('.eth', ''));
3990
- PAGE_SIZE = 1000;
3991
- result = [];
3992
- page = 0;
3993
- params = {
3994
- delegations: {
3995
- __args: {
3996
- where: {
3997
- space_in: spaceIn
3998
- },
3999
- first: PAGE_SIZE,
4000
- skip: 0
4001
- },
4002
- delegator: true,
4003
- space: true,
4004
- delegate: true
4005
- }
4006
- };
4007
- if (snapshot !== 'latest') {
4008
- params.delegations.__args.block = { number: snapshot };
4009
- }
4010
- _a.label = 1;
4011
- case 1:
4012
- params.delegations.__args.skip = page * PAGE_SIZE;
4013
- return [4 /*yield*/, subgraphRequest(subgraphUrl, params)];
4014
- case 2:
4015
- pageResult = _a.sent();
4016
- pageDelegations = pageResult.delegations || [];
4017
- result = result.concat(pageDelegations);
4018
- page++;
4019
- if (pageDelegations.length < PAGE_SIZE)
4020
- return [3 /*break*/, 3];
4021
- return [3 /*break*/, 1];
4022
- case 3: return [2 /*return*/, result];
4023
- }
4024
- });
4025
- });
4026
- }
4027
4070
  function clone(item) {
4028
4071
  return JSON.parse(JSON.stringify(item));
4029
4072
  }
@@ -2981,17 +2981,6 @@ var networks = {
2981
2981
  }
2982
2982
  };
2983
2983
 
2984
- var delegationSubgraphs = {
2985
- "1": "https://subgrapher.snapshot.org/gateway-arbitrum.network.thegraph.com/api/0f15b42bdeff7a063a4e1757d7e2f99e/subgraphs/id/4YgtogVaqoM8CErHWDK8mKQ825BcVdKB8vBYmb4avAQo",
2986
- "5": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-goerli",
2987
- "10": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-optimism",
2988
- "56": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-binance-smart-chain",
2989
- "100": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-gnosis-chain",
2990
- "137": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-polygon",
2991
- "250": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-fantom",
2992
- "42161": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-arbitrum"
2993
- };
2994
-
2995
2984
  var SingleChoiceVoting = /** @class */ (function () {
2996
2985
  function SingleChoiceVoting(proposal, votes, strategies, selected) {
2997
2986
  this.proposal = proposal;
@@ -3403,7 +3392,113 @@ var voting = {
3403
3392
  basic: SingleChoiceVoting
3404
3393
  };
3405
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
+
3406
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
+
3407
3502
  var ENS_RESOLVER_ABI = [
3408
3503
  'function text(bytes32 node, string calldata key) external view returns (string memory)'
3409
3504
  ];
@@ -3963,58 +4058,6 @@ function getSpaceController(id, network, options) {
3963
4058
  });
3964
4059
  });
3965
4060
  }
3966
- function getDelegatesBySpace(network, space, snapshot, options) {
3967
- if (snapshot === void 0) { snapshot = 'latest'; }
3968
- if (options === void 0) { options = {}; }
3969
- return __awaiter(this, void 0, void 0, function () {
3970
- var subgraphUrl, spaceIn, PAGE_SIZE, result, page, params, pageResult, pageDelegations;
3971
- return __generator(this, function (_a) {
3972
- switch (_a.label) {
3973
- case 0:
3974
- subgraphUrl = options.subgraphUrl || SNAPSHOT_SUBGRAPH_URL[network];
3975
- if (!subgraphUrl) {
3976
- return [2 /*return*/, Promise.reject("Delegation subgraph not available for network " + network)];
3977
- }
3978
- spaceIn = ['', space];
3979
- if (space.includes('.eth'))
3980
- spaceIn.push(space.replace('.eth', ''));
3981
- PAGE_SIZE = 1000;
3982
- result = [];
3983
- page = 0;
3984
- params = {
3985
- delegations: {
3986
- __args: {
3987
- where: {
3988
- space_in: spaceIn
3989
- },
3990
- first: PAGE_SIZE,
3991
- skip: 0
3992
- },
3993
- delegator: true,
3994
- space: true,
3995
- delegate: true
3996
- }
3997
- };
3998
- if (snapshot !== 'latest') {
3999
- params.delegations.__args.block = { number: snapshot };
4000
- }
4001
- _a.label = 1;
4002
- case 1:
4003
- params.delegations.__args.skip = page * PAGE_SIZE;
4004
- return [4 /*yield*/, subgraphRequest(subgraphUrl, params)];
4005
- case 2:
4006
- pageResult = _a.sent();
4007
- pageDelegations = pageResult.delegations || [];
4008
- result = result.concat(pageDelegations);
4009
- page++;
4010
- if (pageDelegations.length < PAGE_SIZE)
4011
- return [3 /*break*/, 3];
4012
- return [3 /*break*/, 1];
4013
- case 3: return [2 /*return*/, result];
4014
- }
4015
- });
4016
- });
4017
- }
4018
4061
  function clone(item) {
4019
4062
  return JSON.parse(JSON.stringify(item));
4020
4063
  }