@@ -36,6 +36,7 @@ export interface NominatorStatus {
3636 rewardDestination ?: string ;
3737 stale ?: boolean ;
3838 dryRun ?: boolean ;
39+ shouldNominate ?: boolean ;
3940}
4041
4142export default class Nominator extends EventEmitter {
@@ -61,6 +62,8 @@ export default class Nominator extends EventEmitter {
6162 reason : "" ,
6263 } ;
6364
65+ public _shouldNominate = false ;
66+
6467 private _status : NominatorStatus = {
6568 status : "Init" ,
6669 bondedAddress : "" ,
@@ -130,12 +133,25 @@ export default class Nominator extends EventEmitter {
130133 this . _status = { ...this . _status , ...newStatus } ;
131134 } ;
132135
136+ public async shouldNominate ( ) : Promise < boolean > {
137+ const stash = await this . stash ( ) ;
138+ const isBonded = await this . chaindata . isBonded ( stash ) ;
139+ const [ bonded , err ] = await this . chaindata . getDenomBondedAmount ( stash ) ;
140+
141+ const currentEra = ( await this . chaindata . getCurrentEra ( ) ) || 0 ;
142+ const lastNominationEra =
143+ ( await this . chaindata . getNominatorLastNominationEra ( stash ) ) || 0 ;
144+ this . _shouldNominate = isBonded && currentEra - lastNominationEra >= 1 ;
145+ return this . _shouldNominate ;
146+ }
147+
133148 public async init ( ) : Promise < NominatorStatus > {
134149 try {
135150 const stash = await this . stash ( ) ;
136151 const isBonded = await this . chaindata . isBonded ( stash ) ;
137152 const [ bonded , err ] = await this . chaindata . getDenomBondedAmount ( stash ) ;
138153
154+ const currentEra = ( await this . chaindata . getCurrentEra ( ) ) || 0 ;
139155 const lastNominationEra =
140156 ( await this . chaindata . getNominatorLastNominationEra ( stash ) ) || 0 ;
141157 const currentTargets =
@@ -163,11 +179,14 @@ export default class Nominator extends EventEmitter {
163179 this . signer . address ,
164180 ) ;
165181
182+ this . _shouldNominate =
183+ bonded > 50 && isBonded && currentEra - lastNominationEra >= 1 ;
184+
166185 const rewardDestination = await this . payee ( ) ;
167- const currentEra = ( await this . chaindata . getCurrentEra ( ) ) || 0 ;
186+
168187 const stale = isBonded && currentEra - lastNominationEra > 8 ;
169188 const status : NominatorStatus = {
170- status : "Init ",
189+ status : this . _shouldNominate ? "Initialized" : "Existing Nomination ",
171190 bondedAddress : this . bondedAddress ,
172191 stashAddress : await this . stash ( ) ,
173192 bondedAmount : Number ( bonded ) ,
@@ -182,6 +201,7 @@ export default class Nominator extends EventEmitter {
182201 stale : stale ,
183202 dryRun : this . _dryRun ,
184203 updated : Date . now ( ) ,
204+ shouldNominate : this . _shouldNominate ,
185205 } ;
186206 this . updateNominatorStatus ( status ) ;
187207 this . _canNominate = {
0 commit comments