Skip to content

Commit

Permalink
Merge pull request #2057 from w3f/will-nominator-stake-era
Browse files Browse the repository at this point in the history
bump version to v2.6.95
  • Loading branch information
wpank authored Oct 24, 2022
2 parents 1a46905 + 5a2357d commit 1ff144c
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 12 deletions.
2 changes: 1 addition & 1 deletion charts/otv-backend/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
description: 1K Validators Backend
name: otv-backend
version: v2.6.94
version: v2.6.95
apiVersion: v2
2 changes: 1 addition & 1 deletion charts/otv-backend/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ resources:

image:
repo: web3f/otv-backend
tag: 2.6.94
tag: 2.6.95

certificate:
enabled: true
Expand Down
4 changes: 2 additions & 2 deletions helmfile.d/10-otv-backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ releases:
namespace: kusama
{{ if eq .Environment.Name "production" }}
chart: w3f/otv-backend
version: v2.6.94
version: v2.6.95
{{ else }}
chart: ../charts/otv-backend
{{ end }}
Expand All @@ -30,7 +30,7 @@ releases:
namespace: polkadot
{{ if eq .Environment.Name "production" }}
chart: w3f/otv-backend
version: v2.6.94
version: v2.6.95
{{ else }}
chart: ../charts/otv-backend
{{ end }}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/constraints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ export const getCouncilStakeValues = (
validCandidates: Types.CandidateData[]
) => {
const councilStakeValues = validCandidates.map((candidate) => {
return candidate.councilStake ? candidate.councilStake : 0;
return candidate.councilStake ? Number(candidate.councilStake) : 0;
});
const councilStakeStats = getStats(councilStakeValues);
return { councilStakeValues, councilStakeStats };
Expand Down
16 changes: 16 additions & 0 deletions packages/common/src/db/queries/NominatorStake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,19 @@ export const getLatestNominatorStake = async (
await NominatorStakeModel.find({ validator }).sort("-era").limit(1)
)[0];
};

export const getEraNominatorStake = async (
validator: string,
era: number
): Promise<any> => {
return (await NominatorStakeModel.find({ validator, era }))[0];
};

export const getNominatorStake = async (
validator: string,
limit?: number
): Promise<any> => {
await NominatorStakeModel.find({ validator })
.sort("-era")
.limit(limit ? limit : 100)[0];
};
4 changes: 2 additions & 2 deletions packages/common/src/score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export const asc = (arr) => arr.sort((a, b) => a - b);
// Gets the absolute min of an array of values
export const absMin = (arr) => {
const sorted = asc(arr);
return sorted[0];
return Number(sorted[0]);
};

// Gets the absolute max of an array of values
export const absMax = (arr) => {
const sorted = asc(arr);
return sorted[sorted.length - 1];
return Number(sorted[sorted.length - 1]);
};

// Gets the total sum of an array of values
Expand Down
28 changes: 26 additions & 2 deletions packages/gateway/src/controllers/Candidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,33 @@ export default class CandidateController {
response(context, 200, await CandidateService.getNodes());
}

public static async getNominatorStake(context: any): Promise<void> {
public static async getLatestNominatorStake(context: any): Promise<void> {
const address = context.params.address;

response(context, 200, await CandidateService.getNominatorStake(address));
response(
context,
200,
await CandidateService.getLatestNominatorStake(address)
);
}

public static async getEraNominatorStake(context: any): Promise<void> {
const { address, era } = context.params;

response(
context,
200,
await CandidateService.getEraNominatorStake(address, era)
);
}

public static async getLastNominatorStake(context: any): Promise<void> {
const { address, limit } = context.params;

response(
context,
200,
await CandidateService.getNominatorStake(address, limit)
);
}
}
8 changes: 6 additions & 2 deletions packages/gateway/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ const API = {
LastReferendums: "/lastreferendums",
ReferendumIndexVotes: "/referendumvotes/index/:index",
ReferendumAccountVotes: "/referendumvotes/account/:address",
NominatorStake: "/nominatorstake/:address",
LastNominatorStake: "/nominatorstake/:address/last/:limit",
LatestNominatorStake: "/nominatorstake/:address",
EraNominatorStake: "/nominatorstake/:address/:era",
Delegations: "/delegations/:address",
AllDelegations: "/delegations",
};
Expand All @@ -57,7 +59,9 @@ router.get(API.Accounting, Accounting.getAccounting);
router.get(API.Candidate, Candidate.getCandidate);
router.get(API.GetCandidates, Candidate.getCandidates);
router.get(API.GetNodes, Candidate.getNodes);
router.get(API.NominatorStake, Candidate.getNominatorStake);
router.get(API.LatestNominatorStake, Candidate.getLatestNominatorStake);
router.get(API.EraNominatorStake, Candidate.getEraNominatorStake);
router.get(API.LastNominatorStake, Candidate.getLastNominatorStake);

router.get(API.GetNominators, Nominator.getNominators);
router.get(API.GetNominator, Nominator.getNominator);
Expand Down
12 changes: 11 additions & 1 deletion packages/gateway/src/services/Candidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,17 @@ export const getNodes = async (): Promise<any> => {
return allNodes;
};

export const getNominatorStake = async (address): Promise<any> => {
export const getLatestNominatorStake = async (address): Promise<any> => {
const stake = await queries.getLatestNominatorStake(address);
return stake;
};

export const getEraNominatorStake = async (address, era): Promise<any> => {
const stake = await queries.getEraNominatorStake(address, era);
return stake;
};

export const getNominatorStake = async (address, limit): Promise<any> => {
const stake = await queries.getNominatorStake(address, limit);
return stake;
};

0 comments on commit 1ff144c

Please sign in to comment.