Skip to content

Commit

Permalink
add kyc validity check
Browse files Browse the repository at this point in the history
  • Loading branch information
will pankiewicz authored and will pankiewicz committed Apr 15, 2024
1 parent 5a205c6 commit 58b993c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/common/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type ConfigSchema = {
minSelfStake: number;
commission: number;
unclaimedEraThreshold: number;
enableKYC: boolean;
};
cron: {
monitor: string;
Expand Down
12 changes: 11 additions & 1 deletion packages/common/src/constraints/CheckCandidates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
checkConnectionTime,
checkIdentity,
checkKusamaRank,
checkKYC,
checkLatestClientVersion,
checkOffline,
checkOnline,
Expand Down Expand Up @@ -129,6 +130,14 @@ export const checkCandidate = async (
logger.info(`${candidate.name} beefy keys not valid`, constraintsLabel);
}

const kycValid =
constraints.config?.constraints?.enableKYC == true
? await checkKYC(candidate)
: true;
if (!kycValid) {
logger.info(`${candidate.name} kyc not valid`, constraintsLabel);
}

valid =
onlineValid &&
validateValid &&
Expand All @@ -142,7 +151,8 @@ export const checkCandidate = async (
blockedValid &&
kusamaValid &&
providerValid &&
beefyValid;
beefyValid &&
kycValid;

await setValid(candidate, valid);

Expand Down
18 changes: 18 additions & 0 deletions packages/common/src/constraints/ValidityChecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
setConnectionTimeInvalidity,
setIdentityInvalidity,
setKusamaRankInvalidity,
setKYCInvalidity,
setLatestClientReleaseValidity,
setOfflineAccumulatedInvalidity,
setOnlineValidity,
Expand Down Expand Up @@ -434,3 +435,20 @@ export const checkBeefyKeys = async (
throw new Error("could not make validity check");
}
};

export const checkKYC = async (candidate: Candidate): Promise<boolean> => {
try {
const isKYC = await queries.isKYC(candidate.stash);
if (isKYC) {
const invalidityString = `${candidate.name} is not KYC`;
await setKYCInvalidity(candidate, false, invalidityString);
return false;
} else {
await setKYCInvalidity(candidate, true);
return true;
}
} catch (e) {
logger.warn(`Error trying to get kyc...`, constraintsLabel);
throw new Error("could not make validity check");
}
};
1 change: 1 addition & 0 deletions packages/common/src/db/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export enum InvalidityReasonType {
KUSAMA_RANK = "KUSAMA_RANK",
PROVIDER = "PROVIDER",
BEEFY = "BEEFY",
KYC = "KYC",
}

export interface InvalidityReason {
Expand Down
15 changes: 15 additions & 0 deletions packages/common/src/db/queries/Candidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,21 @@ export const setBeefyKeysInvalidity = async (
);
};

export const setKYCInvalidity = async (
candidate: Candidate,
isValid: boolean,
message?: string,
): Promise<void> => {
const invalidityMessage = message ? message : `${candidate.name} is not KYC`;
setCandidateInvalidity(
candidate,
InvalidityReasonType.KYC,
isValid,
invalidityMessage,
true,
);
};

// Sets valid boolean for node
export const setValid = async (
candidate: Candidate,
Expand Down

0 comments on commit 58b993c

Please sign in to comment.