Browse Source

CLI, api-scripts: Update after runtime StakingHandler bug fix

Leszek Wiesner 3 years ago
parent
commit
b47e5b62e3

+ 1 - 1
cli/src/base/AccountsCommandBase.ts

@@ -381,7 +381,7 @@ export default abstract class AccountsCommandBase extends ApiCommandBase {
     const requiredStakingAccountBalance = !stakingStatus
       ? requiredStake.add(candidateTxFee).add(STAKING_ACCOUNT_CANDIDATE_STAKE)
       : requiredStake
-    const missingStakingAccountBalance = requiredStakingAccountBalance.sub(balances.availableBalance)
+    const missingStakingAccountBalance = requiredStakingAccountBalance.sub(balances.freeBalance)
     if (missingStakingAccountBalance.gtn(0)) {
       this.warn(
         `Not enough available staking account balance! Missing: ${chalk.cyanBright(

+ 8 - 6
cli/src/commands/working-groups/createOpening.ts

@@ -104,12 +104,14 @@ export default class WorkingGroupsCreateOpening extends WorkingGroupsCommandBase
     return getInputJson<WorkingGroupOpeningInputParameters>(filePath, WorkingGroupOpeningInputSchema)
   }
 
-  async promptForStakeTopUp(stakingAccount: string, fundsSource?: string): Promise<void> {
-    const requiredStake = this.getOriginalApi().consts[apiModuleByGroup[this.group]].leaderOpeningStake
-    this.log(`You need to stake ${chalk.bold(formatBalance(requiredStake))} in order to create a new opening.`)
+  async promptForStakeTopUp({ stake, stakingAccount }: GroupMember, fundsSource?: string): Promise<void> {
+    const newStake = this.getOriginalApi().consts[apiModuleByGroup[this.group]].leaderOpeningStake.add(stake)
+    this.log(
+      `You need to increase your lead stake to ${chalk.bold(formatBalance(newStake))} in order to create a new opening.`
+    )
 
-    const [balances] = await this.getApi().getAccountsBalancesInfo([stakingAccount])
-    const missingBalance = requiredStake.sub(balances.availableBalance)
+    const [balances] = await this.getApi().getAccountsBalancesInfo([stakingAccount.toString()])
+    const missingBalance = newStake.sub(balances.freeBalance)
     if (missingBalance.gtn(0)) {
       await this.requireConfirmation(
         `Do you wish to transfer remaining ${chalk.bold(
@@ -250,7 +252,7 @@ export default class WorkingGroupsCreateOpening extends WorkingGroupsCommandBase
       rememberedInput = openingJson
 
       if (!upcoming) {
-        await this.promptForStakeTopUp(lead.stakingAccount.toString(), stakeTopUpSource)
+        await this.promptForStakeTopUp(lead, stakeTopUpSource)
       }
 
       const createUpcomingOpeningActionMeta = this.prepareCreateUpcomingOpeningMetadata(

+ 1 - 2
utils/api-scripts/src/initialize-lead.ts

@@ -22,7 +22,6 @@ const workingGroupModules = [
 type WorkingGroupModuleName = typeof workingGroupModules[number]
 
 const MIN_APPLICATION_STAKE = new BN(2000)
-const STAKING_ACCOUNT_CANDIDATE_STAKE = new BN(200)
 
 async function main() {
   // Init api
@@ -102,7 +101,7 @@ async function main() {
     // Set up stake account
     const addCandidateTx = api.tx.members.addStakingAccountCandidate(memberId)
     const addCandidateFee = (await addCandidateTx.paymentInfo(StakeKeyPair.address)).partialFee
-    const stakingAccountBalance = MIN_APPLICATION_STAKE.add(STAKING_ACCOUNT_CANDIDATE_STAKE).add(addCandidateFee)
+    const stakingAccountBalance = MIN_APPLICATION_STAKE.add(addCandidateFee)
     console.log('Setting up staking account...')
     await txHelper.sendAndCheck(
       LeadKeyPair,