@snapshot-labs/snapshot.js 0.10.1 → 0.11.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/dist/index.d.ts CHANGED
@@ -283,10 +283,18 @@ declare const _default: {
283
283
  delay: {
284
284
  type: string;
285
285
  minimum: number;
286
+ maximum: number;
287
+ errorMessage: {
288
+ maximum: string;
289
+ };
286
290
  };
287
291
  period: {
288
292
  type: string;
289
293
  minimum: number;
294
+ maximum: number;
295
+ errorMessage: {
296
+ maximum: string;
297
+ };
290
298
  };
291
299
  type: {
292
300
  type: string;
@@ -279,10 +279,18 @@ declare const _default: {
279
279
  delay: {
280
280
  type: string;
281
281
  minimum: number;
282
+ maximum: number;
283
+ errorMessage: {
284
+ maximum: string;
285
+ };
282
286
  };
283
287
  period: {
284
288
  type: string;
285
289
  minimum: number;
290
+ maximum: number;
291
+ errorMessage: {
292
+ maximum: string;
293
+ };
286
294
  };
287
295
  type: {
288
296
  type: string;
@@ -9,6 +9,7 @@ var hash = require('@ethersproject/hash');
9
9
  var jsonToGraphqlQuery = require('json-to-graphql-query');
10
10
  var Ajv = require('ajv');
11
11
  var addFormats = require('ajv-formats');
12
+ var addErrors = require('ajv-errors');
12
13
  var set = require('lodash.set');
13
14
  var providers$1 = require('@ethersproject/providers');
14
15
  var bytes = require('@ethersproject/bytes');
@@ -19,6 +20,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
19
20
  var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
20
21
  var Ajv__default = /*#__PURE__*/_interopDefaultLegacy(Ajv);
21
22
  var addFormats__default = /*#__PURE__*/_interopDefaultLegacy(addFormats);
23
+ var addErrors__default = /*#__PURE__*/_interopDefaultLegacy(addErrors);
22
24
  var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
23
25
 
24
26
  /*! *****************************************************************************
@@ -870,11 +872,19 @@ var definitions = {
870
872
  properties: {
871
873
  delay: {
872
874
  type: "integer",
873
- minimum: 0
875
+ minimum: 0,
876
+ maximum: 2592000,
877
+ errorMessage: {
878
+ maximum: "Delay must be less than 30 days"
879
+ }
874
880
  },
875
881
  period: {
876
882
  type: "integer",
877
- minimum: 0
883
+ minimum: 0,
884
+ maximum: 15552000,
885
+ errorMessage: {
886
+ maximum: "Delay must be less than 180 days"
887
+ }
878
888
  },
879
889
  type: {
880
890
  type: "string",
@@ -2990,17 +3000,6 @@ var networks = {
2990
3000
  }
2991
3001
  };
2992
3002
 
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
3003
  var SingleChoiceVoting = /** @class */ (function () {
3005
3004
  function SingleChoiceVoting(proposal, votes, strategies, selected) {
3006
3005
  this.proposal = proposal;
@@ -3412,7 +3411,113 @@ var voting = {
3412
3411
  basic: SingleChoiceVoting
3413
3412
  };
3414
3413
 
3414
+ var delegationSubgraphs = {
3415
+ "1": "https://subgrapher.snapshot.org/gateway-arbitrum.network.thegraph.com/api/0f15b42bdeff7a063a4e1757d7e2f99e/subgraphs/id/4YgtogVaqoM8CErHWDK8mKQ825BcVdKB8vBYmb4avAQo",
3416
+ "5": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-goerli",
3417
+ "10": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-optimism",
3418
+ "56": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-binance-smart-chain",
3419
+ "100": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-gnosis-chain",
3420
+ "137": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-polygon",
3421
+ "250": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-fantom",
3422
+ "42161": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-arbitrum"
3423
+ };
3424
+
3415
3425
  var SNAPSHOT_SUBGRAPH_URL = delegationSubgraphs;
3426
+ var PAGE_SIZE = 1000;
3427
+ function getDelegatesBySpace(network, space, snapshot, options) {
3428
+ if (snapshot === void 0) { snapshot = 'latest'; }
3429
+ if (options === void 0) { options = {}; }
3430
+ return __awaiter(this, void 0, void 0, function () {
3431
+ var subgraphUrl, pivot, result, spaceIn, newResults;
3432
+ return __generator(this, function (_a) {
3433
+ switch (_a.label) {
3434
+ case 0:
3435
+ subgraphUrl = options.subgraphUrl || SNAPSHOT_SUBGRAPH_URL[network];
3436
+ if (!subgraphUrl) {
3437
+ return [2 /*return*/, Promise.reject("Delegation subgraph not available for network " + network)];
3438
+ }
3439
+ pivot = 0;
3440
+ result = new Map();
3441
+ spaceIn = buildSpaceIn(space);
3442
+ _a.label = 1;
3443
+ case 1:
3444
+ return [4 /*yield*/, fetchData({
3445
+ url: subgraphUrl,
3446
+ spaces: spaceIn,
3447
+ pivot: pivot,
3448
+ snapshot: snapshot
3449
+ })];
3450
+ case 2:
3451
+ newResults = _a.sent();
3452
+ if (checkAllDuplicates(newResults)) {
3453
+ throw new Error('Unable to paginate delegation');
3454
+ }
3455
+ newResults.forEach(function (delegation) {
3456
+ concatUniqueDelegation(result, delegation);
3457
+ pivot = delegation.timestamp;
3458
+ });
3459
+ if (newResults.length < PAGE_SIZE)
3460
+ return [3 /*break*/, 3];
3461
+ return [3 /*break*/, 1];
3462
+ case 3: return [2 /*return*/, __spread(result.values())];
3463
+ }
3464
+ });
3465
+ });
3466
+ }
3467
+ function checkAllDuplicates(delegations) {
3468
+ return (delegations.length === PAGE_SIZE &&
3469
+ delegations[0].timestamp === delegations[delegations.length - 1].timestamp);
3470
+ }
3471
+ function delegationKey(delegation) {
3472
+ return delegation.delegator + "-" + delegation.delegate + "-" + delegation.space;
3473
+ }
3474
+ function concatUniqueDelegation(result, delegation) {
3475
+ var key = delegationKey(delegation);
3476
+ if (!result.has(key)) {
3477
+ result.set(key, delegation);
3478
+ }
3479
+ }
3480
+ function buildSpaceIn(space) {
3481
+ var spaces = ['', space];
3482
+ if (space.includes('.eth'))
3483
+ spaces.push(space.replace('.eth', ''));
3484
+ return spaces;
3485
+ }
3486
+ function fetchData(_a) {
3487
+ var url = _a.url, spaces = _a.spaces, pivot = _a.pivot, snapshot = _a.snapshot;
3488
+ return __awaiter(this, void 0, void 0, function () {
3489
+ var params;
3490
+ return __generator(this, function (_b) {
3491
+ switch (_b.label) {
3492
+ case 0:
3493
+ params = {
3494
+ delegations: {
3495
+ __args: {
3496
+ where: {
3497
+ space_in: spaces,
3498
+ timestamp_gte: pivot
3499
+ },
3500
+ first: PAGE_SIZE,
3501
+ skip: 0,
3502
+ orderBy: 'timestamp',
3503
+ orderDirection: 'asc'
3504
+ },
3505
+ delegator: true,
3506
+ space: true,
3507
+ delegate: true,
3508
+ timestamp: true
3509
+ }
3510
+ };
3511
+ if (snapshot !== 'latest') {
3512
+ params.delegations.__args.block = { number: snapshot };
3513
+ }
3514
+ return [4 /*yield*/, subgraphRequest(url, params)];
3515
+ case 1: return [2 /*return*/, (_b.sent()).delegations || []];
3516
+ }
3517
+ });
3518
+ });
3519
+ }
3520
+
3416
3521
  var ENS_RESOLVER_ABI = [
3417
3522
  'function text(bytes32 node, string calldata key) external view returns (string memory)'
3418
3523
  ];
@@ -3429,6 +3534,7 @@ var ajv = new Ajv__default['default']({
3429
3534
  });
3430
3535
  // @ts-ignore
3431
3536
  addFormats__default['default'](ajv);
3537
+ addErrors__default['default'](ajv);
3432
3538
  ajv.addFormat('address', {
3433
3539
  validate: function (value) {
3434
3540
  try {
@@ -3972,58 +4078,6 @@ function getSpaceController(id, network, options) {
3972
4078
  });
3973
4079
  });
3974
4080
  }
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
4081
  function clone(item) {
4028
4082
  return JSON.parse(JSON.stringify(item));
4029
4083
  }
@@ -7,6 +7,7 @@ import { _TypedDataEncoder, namehash, ensNormalize } from '@ethersproject/hash';
7
7
  import { jsonToGraphQLQuery } from 'json-to-graphql-query';
8
8
  import Ajv from 'ajv';
9
9
  import addFormats from 'ajv-formats';
10
+ import addErrors from 'ajv-errors';
10
11
  import set from 'lodash.set';
11
12
  import { StaticJsonRpcProvider } from '@ethersproject/providers';
12
13
  import { hexlify, arrayify } from '@ethersproject/bytes';
@@ -861,11 +862,19 @@ var definitions = {
861
862
  properties: {
862
863
  delay: {
863
864
  type: "integer",
864
- minimum: 0
865
+ minimum: 0,
866
+ maximum: 2592000,
867
+ errorMessage: {
868
+ maximum: "Delay must be less than 30 days"
869
+ }
865
870
  },
866
871
  period: {
867
872
  type: "integer",
868
- minimum: 0
873
+ minimum: 0,
874
+ maximum: 15552000,
875
+ errorMessage: {
876
+ maximum: "Delay must be less than 180 days"
877
+ }
869
878
  },
870
879
  type: {
871
880
  type: "string",
@@ -2981,17 +2990,6 @@ var networks = {
2981
2990
  }
2982
2991
  };
2983
2992
 
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
2993
  var SingleChoiceVoting = /** @class */ (function () {
2996
2994
  function SingleChoiceVoting(proposal, votes, strategies, selected) {
2997
2995
  this.proposal = proposal;
@@ -3403,7 +3401,113 @@ var voting = {
3403
3401
  basic: SingleChoiceVoting
3404
3402
  };
3405
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
+
3406
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
+
3407
3511
  var ENS_RESOLVER_ABI = [
3408
3512
  'function text(bytes32 node, string calldata key) external view returns (string memory)'
3409
3513
  ];
@@ -3420,6 +3524,7 @@ var ajv = new Ajv({
3420
3524
  });
3421
3525
  // @ts-ignore
3422
3526
  addFormats(ajv);
3527
+ addErrors(ajv);
3423
3528
  ajv.addFormat('address', {
3424
3529
  validate: function (value) {
3425
3530
  try {
@@ -3963,58 +4068,6 @@ function getSpaceController(id, network, options) {
3963
4068
  });
3964
4069
  });
3965
4070
  }
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
4071
  function clone(item) {
4019
4072
  return JSON.parse(JSON.stringify(item));
4020
4073
  }