@@ -15,6 +15,7 @@ import {
1515 setSelfStakeInvalidity ,
1616 setUnclaimedInvalidity ,
1717 setValidateIntentionValidity ,
18+ setSanctionedGeoAreaValidity ,
1819} from "../db" ;
1920import { ChainData , Config , Constants , queries , Util } from "../index" ;
2021import axios from "axios" ;
@@ -434,3 +435,61 @@ export const checkBeefyKeys = async (
434435 throw new Error ( "could not make validity check" ) ;
435436 }
436437} ;
438+
439+ // Checks if the candidate is in a sanctioned location
440+ export const checkSanctionedGeoArea = async (
441+ config : Config . ConfigSchema ,
442+ candidate : Candidate ,
443+ ) : Promise < boolean > => {
444+ try {
445+ if (
446+ ! config . constraints ?. sanctionedGeoArea ?. sanctionedCountries ?. length &&
447+ ! config . constraints ?. sanctionedGeoArea ?. sanctionedRegions ?. length
448+ ) {
449+ await setSanctionedGeoAreaValidity ( candidate , true ) ;
450+ return true ;
451+ }
452+
453+ const location = await queries . getCandidateLocation ( candidate . slotId ) ;
454+ if ( ! location ?. region || ! location ?. country ) {
455+ await setSanctionedGeoAreaValidity ( candidate , true ) ;
456+ return true ;
457+ }
458+
459+ const sanctionedCountries = config . constraints ?. sanctionedGeoArea
460+ ?. sanctionedCountries
461+ ? config . constraints . sanctionedGeoArea . sanctionedCountries . map ( ( x ) =>
462+ x . trim ( ) . toLowerCase ( ) ,
463+ )
464+ : [ ] ;
465+ const sanctionedRegions = config . constraints ?. sanctionedGeoArea
466+ ?. sanctionedRegions
467+ ? config . constraints . sanctionedGeoArea . sanctionedRegions . map ( ( x ) =>
468+ x . trim ( ) . toLowerCase ( ) ,
469+ )
470+ : [ ] ;
471+
472+ if (
473+ sanctionedCountries . includes ( location . country . trim ( ) . toLowerCase ( ) ) ||
474+ sanctionedRegions . includes ( location . region . trim ( ) . toLowerCase ( ) )
475+ ) {
476+ logger . info (
477+ `${ candidate . name } is in a sanctioned location: Country: ${ location . country } , Region: ${ location . region } ` ,
478+ {
479+ label : "Constraints" ,
480+ } ,
481+ ) ;
482+ await setSanctionedGeoAreaValidity ( candidate , false ) ;
483+ return false ;
484+ }
485+
486+ await setSanctionedGeoAreaValidity ( candidate , true ) ;
487+ return true ;
488+ } catch ( e ) {
489+ logger . error (
490+ `Error checking location for sanctions: ${ e } ` ,
491+ constraintsLabel ,
492+ ) ;
493+ throw new Error ( "could not make validity check" ) ;
494+ }
495+ } ;
0 commit comments