@substrate/api-sidecar 17.5.1 → 18.0.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.
Files changed (42) hide show
  1. package/build/package.json +14 -14
  2. package/build/src/chains-config/cache/lruCache.d.ts +2 -2
  3. package/build/src/chains-config/cache/lruCache.js +3 -6
  4. package/build/src/chains-config/cache/lruCache.js.map +1 -1
  5. package/build/src/controllers/accounts/AccountsStakingPayoutsController.js +54 -12
  6. package/build/src/controllers/accounts/AccountsStakingPayoutsController.js.map +1 -1
  7. package/build/src/services/accounts/AccountsStakingPayoutsService.d.ts +46 -18
  8. package/build/src/services/accounts/AccountsStakingPayoutsService.js +164 -49
  9. package/build/src/services/accounts/AccountsStakingPayoutsService.js.map +1 -1
  10. package/build/src/services/accounts/kusamaEarlyErasBlockInfo.json +2082 -0
  11. package/build/src/services/blocks/BlocksService.d.ts +2 -2
  12. package/build/src/services/blocks/BlocksService.js.map +1 -1
  13. package/build/src/services/blocks/BlocksService.spec.js +70 -3
  14. package/build/src/services/blocks/BlocksService.spec.js.map +1 -1
  15. package/build/src/services/blocks/XCMDecoder.d.ts +1 -1
  16. package/build/src/services/blocks/XCMDecoder.js +61 -46
  17. package/build/src/services/blocks/XCMDecoder.js.map +1 -1
  18. package/build/src/services/pallets/PalletsAssetConversionService.spec.js +1 -1
  19. package/build/src/services/pallets/PalletsAssetConversionService.spec.js.map +1 -1
  20. package/build/src/services/pallets/PalletsForeignAssetsService.js +2 -3
  21. package/build/src/services/pallets/PalletsForeignAssetsService.js.map +1 -1
  22. package/build/src/services/pallets/PalletsForeignAssetsService.spec.js +4 -4
  23. package/build/src/services/pallets/PalletsForeignAssetsService.spec.js.map +1 -1
  24. package/build/src/services/paras/ParasService.js +1 -1
  25. package/build/src/types/chains-config/ControllerConfig.d.ts +2 -2
  26. package/build/src/types/chains-config/ControllerConfig.js +1 -1
  27. package/build/src/types/responses/AccountStakingInfo.d.ts +3 -3
  28. package/build/src/types/responses/AccountStakingInfo.js +1 -1
  29. package/build/src/types/responses/BlockXCMMessages.d.ts +9 -4
  30. package/build/src/types/responses/BlockXCMMessages.js +1 -1
  31. package/build/src/types/responses/PalletAssetConversion.d.ts +3 -3
  32. package/build/src/types/responses/PalletAssetConversion.js +1 -1
  33. package/build/src/types/responses/SanitizedBackedCandidatesCommitments.d.ts +2 -1
  34. package/build/src/types/responses/SanitizedBackedCandidatesHorizontalMessage.d.ts +4 -0
  35. package/build/src/types/responses/SanitizedBackedCandidatesHorizontalMessage.js +18 -0
  36. package/build/src/types/responses/SanitizedBackedCandidatesHorizontalMessage.js.map +1 -0
  37. package/build/src/types/responses/SanitizedParachainInherentData.d.ts +3 -2
  38. package/build/src/types/responses/SanitizedParachainInherentData.js +1 -1
  39. package/build/src/types/responses/SanitizedParachainInherentDataHorizontalMessage.d.ts +4 -0
  40. package/build/src/types/responses/SanitizedParachainInherentDataHorizontalMessage.js +18 -0
  41. package/build/src/types/responses/SanitizedParachainInherentDataHorizontalMessage.js.map +1 -0
  42. package/package.json +14 -14
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "17.5.1",
2
+ "version": "18.0.0",
3
3
  "name": "@substrate/api-sidecar",
4
4
  "description": "REST service that makes it easy to interact with blockchain nodes built using Substrate's FRAME framework.",
5
5
  "homepage": "https://github.com/paritytech/substrate-api-sidecar#readme",
@@ -50,29 +50,29 @@
50
50
  "test:test-release": "yarn build:scripts && node scripts/build/runYarnPack.js"
51
51
  },
52
52
  "dependencies": {
53
- "@polkadot/api": "^10.11.2",
54
- "@polkadot/api-contract": "^10.11.2",
53
+ "@polkadot/api": "^10.12.4",
54
+ "@polkadot/api-contract": "^10.12.4",
55
55
  "@polkadot/util-crypto": "^12.6.2",
56
56
  "@substrate/calc": "^0.3.1",
57
57
  "argparse": "^2.0.1",
58
58
  "confmgr": "^1.0.10",
59
- "express": "^4.18.1",
59
+ "express": "^4.18.3",
60
60
  "express-winston": "^4.2.0",
61
61
  "http-errors": "^2.0.0",
62
- "lru-cache": "^7.13.1",
63
- "prom-client": "^14.2.0",
64
- "rxjs": "^7.5.6",
65
- "winston": "^3.8.1"
62
+ "lru-cache": "^10.2.0",
63
+ "prom-client": "^15.1.0",
64
+ "rxjs": "^7.8.1",
65
+ "winston": "^3.12.0"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@substrate/dev": "^0.7.1",
69
- "@types/argparse": "2.0.10",
70
- "@types/express": "^4.17.17",
71
- "@types/express-serve-static-core": "^4.17.36",
72
- "@types/http-errors": "1.8.2",
69
+ "@types/argparse": "2.0.15",
70
+ "@types/express": "^4.17.21",
71
+ "@types/express-serve-static-core": "^4.17.43",
72
+ "@types/http-errors": "2.0.4",
73
73
  "@types/lru-cache": "^7.10.10",
74
- "@types/morgan": "1.9.3",
75
- "@types/triple-beam": "^1.3.2",
74
+ "@types/morgan": "1.9.9",
75
+ "@types/triple-beam": "^1.3.5",
76
76
  "ts-node-dev": "^2.0.0"
77
77
  },
78
78
  "keywords": [
@@ -1,3 +1,3 @@
1
- import LRU from 'lru-cache';
1
+ import { LRUCache } from 'lru-cache';
2
2
  import { IBlock } from '../../types/responses';
3
- export declare const initLRUCache: () => LRU<string, IBlock>;
3
+ export declare const initLRUCache: () => LRUCache<string, IBlock>;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2017-2022 Parity Technologies (UK) Ltd.
2
+ // Copyright 2017-2024 Parity Technologies (UK) Ltd.
3
3
  // This file is part of Substrate API Sidecar.
4
4
  //
5
5
  // Substrate API Sidecar is free software: you can redistribute it and/or modify
@@ -14,16 +14,13 @@
14
14
  //
15
15
  // You should have received a copy of the GNU General Public License
16
16
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
17
  Object.defineProperty(exports, "__esModule", { value: true });
21
18
  exports.initLRUCache = void 0;
22
- const lru_cache_1 = __importDefault(require("lru-cache"));
19
+ const lru_cache_1 = require("lru-cache");
23
20
  const initLRUCache = () => {
24
21
  const config = { max: 2 };
25
22
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
26
- const cache = new lru_cache_1.default(config);
23
+ const cache = new lru_cache_1.LRUCache(config);
27
24
  return cache;
28
25
  };
29
26
  exports.initLRUCache = initLRUCache;
@@ -1 +1 @@
1
- {"version":3,"file":"lruCache.js","sourceRoot":"","sources":["../../../../src/chains-config/cache/lruCache.ts"],"names":[],"mappings":";AAAA,oDAAoD;AACpD,8CAA8C;AAC9C,EAAE;AACF,gFAAgF;AAChF,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,wEAAwE;;;;;;AAExE,0DAA4B;AAIrB,MAAM,YAAY,GAAG,GAAwB,EAAE;IACrD,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;IAC1B,4EAA4E;IAC5E,MAAM,KAAK,GAAG,IAAI,mBAAG,CAAC,MAAM,CAAwB,CAAC;IAErD,OAAO,KAAK,CAAC;AACd,CAAC,CAAC;AANW,QAAA,YAAY,gBAMvB"}
1
+ {"version":3,"file":"lruCache.js","sourceRoot":"","sources":["../../../../src/chains-config/cache/lruCache.ts"],"names":[],"mappings":";AAAA,oDAAoD;AACpD,8CAA8C;AAC9C,EAAE;AACF,gFAAgF;AAChF,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,wEAAwE;;;AAExE,yCAAqC;AAI9B,MAAM,YAAY,GAAG,GAA6B,EAAE;IAC1D,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;IAC1B,4EAA4E;IAC5E,MAAM,KAAK,GAAG,IAAI,oBAAQ,CAAC,MAAM,CAA6B,CAAC;IAE/D,OAAO,KAAK,CAAC;AACd,CAAC,CAAC;AANW,QAAA,YAAY,gBAMvB"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2017-2022 Parity Technologies (UK) Ltd.
2
+ // Copyright 2017-2024 Parity Technologies (UK) Ltd.
3
3
  // This file is part of Substrate API Sidecar.
4
4
  //
5
5
  // Substrate API Sidecar is free software: you can redistribute it and/or modify
@@ -23,6 +23,7 @@ const bn_js_1 = __importDefault(require("bn.js"));
23
23
  const http_errors_1 = require("http-errors");
24
24
  const middleware_1 = require("../../middleware");
25
25
  const services_1 = require("../../services");
26
+ const kusamaEarlyErasBlockInfo_json_1 = __importDefault(require("../../services/accounts/kusamaEarlyErasBlockInfo.json"));
26
27
  const AbstractController_1 = __importDefault(require("../AbstractController"));
27
28
  /**
28
29
  * GET payout information for a stash account.
@@ -85,11 +86,29 @@ class AccountsStakingPayoutsController extends AbstractController_1.default {
85
86
  * @param res Express Response
86
87
  */
87
88
  this.getStakingPayoutsByAccountId = async ({ params: { address }, query: { depth, era, unclaimedOnly, at } }, res) => {
88
- const hash = await this.getHashFromAt(at);
89
- const apiAt = await this.api.at(hash);
89
+ const earlyErasBlockInfo = kusamaEarlyErasBlockInfo_json_1.default;
90
+ let hash = await this.getHashFromAt(at);
91
+ let apiAt = await this.api.at(hash);
92
+ const runtimeInfo = await this.api.rpc.state.getRuntimeVersion(hash);
93
+ const isKusama = runtimeInfo.specName.toString().toLowerCase() === 'kusama';
90
94
  const { eraArg, currentEra } = await this.getEraAndHash(apiAt, this.verifyAndCastOr('era', era, undefined));
95
+ if (currentEra <= 519 && depth !== undefined && isKusama) {
96
+ throw new http_errors_1.InternalServerError('The `depth` query parameter is disabled for eras less than 518.');
97
+ }
98
+ else if (currentEra <= 519 && era !== undefined && isKusama) {
99
+ throw new http_errors_1.InternalServerError('The `era` query parameter is disabled for eras less than 518.');
100
+ }
101
+ let sanitizedDepth;
102
+ if (depth && isKusama) {
103
+ sanitizedDepth = Math.min(Number(depth), currentEra - 518).toString();
104
+ }
105
+ if (currentEra < 518 && isKusama) {
106
+ const eraStartBlock = earlyErasBlockInfo[currentEra].start;
107
+ hash = await this.getHashFromAt(eraStartBlock.toString());
108
+ apiAt = await this.api.at(hash);
109
+ }
91
110
  const unclaimedOnlyArg = unclaimedOnly === 'false' ? false : true;
92
- AccountsStakingPayoutsController.sanitizedSend(res, await this.service.fetchAccountStakingPayout(hash, address, this.verifyAndCastOr('depth', depth, 1), eraArg, unclaimedOnlyArg, currentEra, apiAt));
111
+ AccountsStakingPayoutsController.sanitizedSend(res, await this.service.fetchAccountStakingPayout(hash, address, this.verifyAndCastOr('depth', sanitizedDepth, 1), eraArg, unclaimedOnlyArg, currentEra, apiAt));
93
112
  };
94
113
  this.initRoutes();
95
114
  }
@@ -98,15 +117,8 @@ class AccountsStakingPayoutsController extends AbstractController_1.default {
98
117
  this.safeMountAsyncGetHandlers([['', this.getStakingPayoutsByAccountId]]);
99
118
  }
100
119
  async getEraAndHash(apiAt, era) {
101
- const [activeEraOption, currentEraMaybeOption] = await Promise.all([
102
- apiAt.query.staking.activeEra(),
103
- apiAt.query.staking.currentEra(),
104
- ]);
105
- if (activeEraOption.isNone) {
106
- throw new http_errors_1.InternalServerError('ActiveEra is None when Some was expected');
107
- }
108
- const activeEra = activeEraOption.unwrap().index.toNumber();
109
120
  let currentEra;
121
+ const currentEraMaybeOption = (await apiAt.query.staking.currentEra());
110
122
  if (currentEraMaybeOption instanceof types_1.Option) {
111
123
  if (currentEraMaybeOption.isNone) {
112
124
  throw new http_errors_1.InternalServerError('CurrentEra is None when Some was expected');
@@ -120,6 +132,36 @@ class AccountsStakingPayoutsController extends AbstractController_1.default {
120
132
  else {
121
133
  throw new http_errors_1.InternalServerError('Query for current_era returned a non-processable result.');
122
134
  }
135
+ let activeEra;
136
+ if (apiAt.query.staking.activeEra) {
137
+ const activeEraOption = await apiAt.query.staking.activeEra();
138
+ if (activeEraOption.isNone) {
139
+ const historicActiveEra = await apiAt.query.staking.currentEra();
140
+ if (historicActiveEra.isNone) {
141
+ throw new http_errors_1.InternalServerError('ActiveEra is None when Some was expected');
142
+ }
143
+ else {
144
+ activeEra = historicActiveEra.unwrap().toNumber();
145
+ }
146
+ }
147
+ else {
148
+ activeEra = activeEraOption.unwrap().index.toNumber();
149
+ }
150
+ }
151
+ else {
152
+ const sessionIndex = await apiAt.query.session.currentIndex();
153
+ const idx = sessionIndex.toNumber() % 6;
154
+ // https://substrate.stackexchange.com/a/2026/1786
155
+ if (currentEra < 518) {
156
+ activeEra = currentEra;
157
+ }
158
+ else if (idx > 0) {
159
+ activeEra = currentEra;
160
+ }
161
+ else {
162
+ activeEra = currentEra - 1;
163
+ }
164
+ }
123
165
  if (era !== undefined && era > activeEra - 1) {
124
166
  throw new http_errors_1.BadRequest(`The specified era (${era}) is too large. ` + `Largest era payout info is available for is ${activeEra - 1}`);
125
167
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AccountsStakingPayoutsController.js","sourceRoot":"","sources":["../../../../src/controllers/accounts/AccountsStakingPayoutsController.ts"],"names":[],"mappings":";AAAA,oDAAoD;AACpD,8CAA8C;AAC9C,EAAE;AACF,gFAAgF;AAChF,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,wEAAwE;;;;;AAIxE,2CAAyC;AACzC,kDAAuB;AAEvB,6CAA8D;AAE9D,iDAAoE;AACpE,6CAA+D;AAE/D,+EAAuD;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,MAAqB,gCAAiC,SAAQ,4BAAiD;IAC9G,YAAY,GAAe;QAC1B,KAAK,CAAC,GAAG,EAAE,oCAAoC,EAAE,IAAI,wCAA6B,CAAC,GAAG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AAC,CAAC;iBAC1E;qBAAM;oBACN,SAAS,GAAG,iBAAiB,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC;iBAClD;aACD;iBAAM;gBACN,SAAS,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;aACtD;SACD;aAAM;YACN,MAAM,YAAY,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;YAC9D,MAAM,GAAG,GAAG,YAAY,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;YACxC,kDAAkD;YAClD,IAAI,UAAU,GAAG,GAAG,EAAE;gBACrB,SAAS,GAAG,UAAU,CAAC;aACvB;iBAAM,IAAI,GAAG,GAAG,CAAC,EAAE;gBACnB,SAAS,GAAG,UAAU,CAAC;aACvB;iBAAM;gBACN,SAAS,GAAG,UAAU,GAAG,CAAC,CAAC;aAC3B;SACD;QAED,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,GAAG,SAAS,GAAG,CAAC,EAAE;YAC7C,MAAM,IAAI,wBAAU,CACnB,sBAAsB,GAAG,kBAAkB,GAAG,+CAA+C,SAAS,GAAG,CAAC,EAAE,CAC5G,CAAC;SACF;QAED,OAAO;YACN,MAAM,EAAE,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG;YAC/C,UAAU;SACV,CAAC;IACH,CAAC;CACD;AAhHD,mDAgHC"}
@@ -1,7 +1,7 @@
1
1
  import type { ApiDecoration } from '@polkadot/api/types';
2
2
  import type { DeriveEraExposure, DeriveEraExposureNominating } from '@polkadot/api-derive/staking/types';
3
- import type { Option } from '@polkadot/types';
4
- import type { BalanceOf, BlockHash, EraIndex, Perbill } from '@polkadot/types/interfaces';
3
+ import { Option } from '@polkadot/types';
4
+ import type { BalanceOf, BlockHash, EraIndex, EraPoints, Perbill } from '@polkadot/types/interfaces';
5
5
  import type { PalletStakingEraRewardPoints, PalletStakingStakingLedger } from '@polkadot/types/lookup';
6
6
  import type { IAccountStakingPayouts, IEraPayouts } from '../../types/responses';
7
7
  import { AbstractService } from '../AbstractService';
@@ -9,7 +9,20 @@ import { AbstractService } from '../AbstractService';
9
9
  * General information about an era, in tuple form because we initially get it
10
10
  * by destructuring a Promise.all(...)
11
11
  */
12
- type IErasGeneral = [DeriveEraExposure, PalletStakingEraRewardPoints, Option<BalanceOf>];
12
+ type IErasGeneral = [IAdjustedDeriveEraExposure, PalletStakingEraRewardPoints | EraPoints, Option<BalanceOf>];
13
+ /**
14
+ * Index of the validator for eras previous to 518 in Kusama chain.
15
+ */
16
+ interface ValidatorIndex {
17
+ [x: string]: number;
18
+ }
19
+ /**
20
+ * Adapted AdjustedDeriveEraExposure interface for compatibility with eras
21
+ * previous to 518 in Kusama chain.
22
+ */
23
+ interface IAdjustedDeriveEraExposure extends DeriveEraExposure {
24
+ validatorIndex?: ValidatorIndex;
25
+ }
13
26
  /**
14
27
  * Commission and staking ledger of a validator
15
28
  */
@@ -21,14 +34,28 @@ interface ICommissionAndLedger {
21
34
  * All the data we need to calculate payouts for an address at a given era.
22
35
  */
23
36
  interface IEraData {
24
- deriveEraExposure: DeriveEraExposure;
25
- eraRewardPoints: PalletStakingEraRewardPoints;
37
+ deriveEraExposure: IAdjustedDeriveEraExposure;
38
+ eraRewardPoints: PalletStakingEraRewardPoints | EraPoints;
26
39
  erasValidatorRewardOption: Option<BalanceOf>;
27
40
  exposuresWithCommission?: (ICommissionAndLedger & {
28
41
  validatorId: string;
29
42
  })[];
30
43
  eraIndex: EraIndex;
31
44
  }
45
+ /**
46
+ * Block information relevant for compatibility with eras previous
47
+ * to 518 in Kusama chain.
48
+ */
49
+ interface IBlockInfo {
50
+ height: string;
51
+ hash: BlockHash;
52
+ }
53
+ export interface IEarlyErasBlockInfo {
54
+ [era: string]: {
55
+ start: number;
56
+ end: number;
57
+ };
58
+ }
32
59
  export declare class AccountsStakingPayoutsService extends AbstractService {
33
60
  /**
34
61
  * Fetch and derive payouts for `address`.
@@ -45,22 +72,22 @@ export declare class AccountsStakingPayoutsService extends AbstractService {
45
72
  /**
46
73
  * Fetch general info about eras in the inclusive range `startEra` .. `era`.
47
74
  *
48
- * @param api `ApiPromise`
49
- * @param hash `BlockHash` to make call at
75
+ * @param historicApi Historic api for querying past blocks
50
76
  * @param startEra first era to get data for
51
77
  * @param era the last era to get data for
78
+ * @param blockNumber block information to ensure compatibility with older eras
52
79
  */
53
- fetchAllErasGeneral(historicApi: ApiDecoration<'promise'>, startEra: number, era: number): Promise<IErasGeneral[]>;
80
+ fetchAllErasGeneral(historicApi: ApiDecoration<'promise'>, startEra: number, era: number, blockNumber: IBlockInfo, isKusama: boolean): Promise<IErasGeneral[]>;
81
+ private fetchHistoricRewardPoints;
54
82
  /**
55
83
  * Fetch the commission & staking ledger for each `validatorId` in `deriveErasExposures`.
56
84
  *
57
- * @param api `ApiPromise`
58
- * @param hash `BlockHash` to make call at
85
+ * @param historicApi Historic api for querying past blocks
59
86
  * @param address address of the _Stash_ account to get the payouts of
60
87
  * @param startEra first era to get data for
61
88
  * @param deriveErasExposures exposures per era for `address`
62
89
  */
63
- fetchAllErasCommissions(historicApi: ApiDecoration<'promise'>, address: string, startEra: number, deriveErasExposures: DeriveEraExposure[]): Promise<ICommissionAndLedger[][]>;
90
+ fetchAllErasCommissions(historicApi: ApiDecoration<'promise'>, address: string, startEra: number, deriveErasExposures: IAdjustedDeriveEraExposure[], isKusama: boolean): Promise<ICommissionAndLedger[][]>;
64
91
  /**
65
92
  * Derive all the payouts for `address` at `era`.
66
93
  *
@@ -68,16 +95,15 @@ export declare class AccountsStakingPayoutsService extends AbstractService {
68
95
  * @param era the era to query
69
96
  * @param eraData data about the address and era we are calculating payouts for
70
97
  */
71
- deriveEraPayouts(address: string, unclaimedOnly: boolean, { deriveEraExposure, eraRewardPoints, erasValidatorRewardOption, exposuresWithCommission, eraIndex }: IEraData): IEraPayouts | {
98
+ deriveEraPayouts(address: string, unclaimedOnly: boolean, { deriveEraExposure, eraRewardPoints, erasValidatorRewardOption, exposuresWithCommission, eraIndex }: IEraData, isKusama: boolean): IEraPayouts | {
72
99
  message: string;
73
100
  };
74
101
  /**
75
102
  * Fetch the `commission` and `StakingLedger` of `validatorId`.
76
103
  *
77
- * @param api
104
+ * @param historicApi Historic api for querying past blocks
78
105
  * @param validatorId accountId of a validator's _Stash_ account
79
106
  * @param era the era to query
80
- * @param hash `BlockHash` to make call at
81
107
  * @param validatorLedgerCache object mapping validatorId => StakingLedger to limit redundant queries
82
108
  */
83
109
  private fetchCommissionAndLedger;
@@ -88,8 +114,8 @@ export declare class AccountsStakingPayoutsService extends AbstractService {
88
114
  * The original version uses the base ApiDerive implementation which does not include the ApiDecoration implementation.
89
115
  * It is required in this version to query older blocks for their historic data.
90
116
  *
91
- * @param historicApi
92
- * @param eraIndex
117
+ * @param historicApi Historic api for querying past blocks
118
+ * @param eraIndex index of the era to query
93
119
  */
94
120
  private deriveEraExposure;
95
121
  /**
@@ -97,6 +123,8 @@ export declare class AccountsStakingPayoutsService extends AbstractService {
97
123
  *
98
124
  * @param eraRewardPoints
99
125
  * @param validatorId accountId of a validator's _Stash_ account
126
+ * @param validatorIndex index of the validator in relation to the `EraPoints`
127
+ * array
100
128
  * */
101
129
  private extractTotalValidatorRewardPoints;
102
130
  /**
@@ -105,7 +133,7 @@ export declare class AccountsStakingPayoutsService extends AbstractService {
105
133
  *
106
134
  * @param address address of the _Stash_ account to get the exposure of behind `validatorId`
107
135
  * @param validatorId accountId of a validator's _Stash_ account
108
- * @param deriveEraExposure
136
+ * @param deriveEraExposure result of deriveEraExposure
109
137
  */
110
138
  private extractExposure;
111
139
  /**
@@ -115,6 +143,6 @@ export declare class AccountsStakingPayoutsService extends AbstractService {
115
143
  * @param address address of the _Stash_ account to get the payouts of
116
144
  * @param deriveEraExposure result of deriveEraExposure
117
145
  */
118
- deriveNominatedExposures(address: string, deriveEraExposure: DeriveEraExposure): DeriveEraExposureNominating[] | undefined;
146
+ deriveNominatedExposures(address: string, deriveEraExposure: IAdjustedDeriveEraExposure): DeriveEraExposureNominating[] | undefined;
119
147
  }
120
148
  export {};