Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/command/grantee/create.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs'
import { Argument, LeafCommand, Option } from 'furious-commander'
import { GranteeCommand } from './grantee-command'
import { stampProperties } from '../../utils/option'
import { createKeyValue } from '../../utils/text'
import fs from 'fs'
import { GranteeCommand } from './grantee-command'

export class Create extends GranteeCommand implements LeafCommand {
public readonly name = 'create'
Expand All @@ -25,7 +25,7 @@ export class Create extends GranteeCommand implements LeafCommand {
public stamp!: string

public async run(): Promise<void> {
await super.init()
super.init()
this.actReqHeaders = {
'Swarm-Act': 'true',
}
Expand Down
4 changes: 2 additions & 2 deletions src/command/grantee/get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Argument, LeafCommand } from 'furious-commander'
import { GranteeCommand } from './grantee-command'
import { createKeyValue } from '../../utils/text'
import { GranteeCommand } from './grantee-command'

export class Get extends GranteeCommand implements LeafCommand {
public readonly name = 'get'
Expand All @@ -15,7 +15,7 @@ export class Get extends GranteeCommand implements LeafCommand {
public reference!: string

public async run(): Promise<void> {
await super.init()
super.init()
const response = await this.bee.getGrantees(this.reference)
this.console.log(
createKeyValue('Grantee public keys', response.grantees.map(grantee => grantee.toCompressedHex()).join('\n')),
Expand Down
6 changes: 3 additions & 3 deletions src/command/grantee/patch.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs'
import { Argument, LeafCommand, Option } from 'furious-commander'
import { GranteeCommand } from './grantee-command'
import { stampProperties } from '../../utils/option'
import { createKeyValue } from '../../utils/text'
import fs from 'fs'
import { GranteeCommand } from './grantee-command'

export class Patch extends GranteeCommand implements LeafCommand {
public readonly name = 'patch'
Expand Down Expand Up @@ -43,7 +43,7 @@ export class Patch extends GranteeCommand implements LeafCommand {
public history!: string

public async run(): Promise<void> {
await super.init()
super.init()
this.actReqHeaders = {
'Swarm-Act': 'true',
'Swarm-Act-Timestamp': Date.now().toString(),
Expand Down
2 changes: 1 addition & 1 deletion src/command/pinning/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class List extends PinningCommand implements LeafCommand {
public readonly description = 'List pinned root hashes'

public async run(): Promise<void> {
await super.init()
super.init()
this.console.info('Getting pinned root hashes...')

const pins = await this.bee.getAllPins()
Expand Down
2 changes: 1 addition & 1 deletion src/command/pinning/unpin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class Unpin extends PinningCommand implements LeafCommand {
public address!: string

public async run(): Promise<void> {
await super.init()
super.init()

try {
await this.bee.unpin(this.address)
Expand Down
2 changes: 1 addition & 1 deletion src/command/pss/receive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Receive extends PssCommand implements LeafCommand {
public receivedMessage?: string

public async run(): Promise<void> {
await super.init()
super.init()

this.console.log('Waiting for one PSS message on topic ' + this.topic)

Expand Down
2 changes: 1 addition & 1 deletion src/command/pss/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class Send extends PssCommand implements LeafCommand {
sendable?: string | Uint8Array

public async run(): Promise<void> {
await super.init()
super.init()

if (this.path) {
if (!fileExists(this.path)) {
Expand Down
4 changes: 2 additions & 2 deletions src/command/pss/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class Subscribe extends PssCommand implements LeafCommand {
})
public outFile!: string

public async run(): Promise<void> {
await super.init()
public run(): void {
super.init()

this.console.log('Subscribing for PSS messages on topic ' + this.topic)

Expand Down
31 changes: 14 additions & 17 deletions src/command/stake.ts → src/command/stake/deposit.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import { BZZ } from '@ethersphere/bee-js'
import { LeafCommand, Option } from 'furious-commander'
import { createSpinner } from '../utils/spinner'
import { createKeyValue } from '../utils/text'
import { RootCommand } from './root-command'
import { VerbosityLevel } from './root-command/command-log'
import { createSpinner } from '../../utils/spinner'
import { RootCommand } from '../root-command'
import { VerbosityLevel } from '../root-command/command-log'

const MIN_DEPOSIT = BZZ.fromDecimalString('10')

export class Stake extends RootCommand implements LeafCommand {
public readonly name = 'stake'
export class Deposit extends RootCommand implements LeafCommand {
public readonly name = 'deposit'

public readonly description = `Manages nodes stake`
public readonly description = 'Stake xBZZ for the storage incentives'

@Option({
key: 'deposit',
key: 'plur',
description: "Amount of PLUR to add to the node's stake",
type: 'bigint',
minimum: BigInt(1),
conflicts: 'bzz',
})
public amountPlur!: bigint | undefined

@Option({
key: 'deposit-bzz',
key: 'bzz',
description: "Amount of BZZ to add to the node's stake",
type: 'string',
conflicts: 'plur',
})
public amountBzz!: string | undefined

Expand All @@ -36,10 +37,10 @@ export class Stake extends RootCommand implements LeafCommand {
await this.deposit(BZZ.fromDecimalString(this.amountBzz))
}

const stake = await this.bee.getStake()

this.console.log(createKeyValue('Staked xBZZ', stake.toDecimalString()))
this.console.quiet(stake.toDecimalString())
this.console.log('Stake deposited successfully!')
this.console.log('Run `swarm-cli stake status` to check your stake status.')
this.console.log('')
this.console.log('Do note it may take a few minutes for the stake to be reflected in the node status.')
}

private async deposit(amount: BZZ): Promise<void> {
Expand Down Expand Up @@ -86,10 +87,6 @@ export class Stake extends RootCommand implements LeafCommand {
try {
await this.bee.depositStake(amount)
spinner.stop()

this.console.log(
'Successfully staked! It may take a few minutes for the stake to be reflected in the node status.',
)
} catch (e) {
spinner.stop()
throw e
Expand Down
13 changes: 13 additions & 0 deletions src/command/stake/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { GroupCommand } from 'furious-commander'
import { Deposit } from './deposit'
import { Recover } from './recover'
import { Status } from './status'
import { Withdraw } from './withdraw'

export class Stake implements GroupCommand {
public readonly name = 'stake'

public readonly description = 'Manages node stake'

public subCommandClasses = [Status, Deposit, Withdraw, Recover]
}
70 changes: 70 additions & 0 deletions src/command/stake/recover.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Contract } from 'ethers'
import { Argument, LeafCommand, Option } from 'furious-commander'
import { makeReadySigner } from '../../utils/rpc'
import { RootCommand } from '../root-command'
import { createWallet } from '../utility'

export class Recover extends RootCommand implements LeafCommand {
public readonly name = 'recover'

public readonly description = 'Recovers xBZZ from paused staking contracts'

@Argument({
key: 'wallet-source',
description: 'Wallet source (path or private key string)',
required: true,
autocompletePath: true,
})
public walletSource!: string

@Option({
key: 'json-rpc-url',
type: 'string',
description: 'Gnosis JSON-RPC URL',
default: 'https://xdai.fairdatasociety.org',
})
public jsonRpcUrl!: string

public async run(): Promise<void> {
super.init()

const address = '0x445B848e16730988F871c4a09aB74526d27c2Ce8'
const abi = [
{
inputs: [],
name: 'migrateStake',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [],
name: 'paused',
outputs: [
{
internalType: 'bool',
name: '',
type: 'bool',
},
],
stateMutability: 'view',
type: 'function',
},
]

const wallet = await createWallet(this.walletSource, this.console)
const signer = await makeReadySigner(wallet.getPrivateKeyString(), this.jsonRpcUrl)
const contract = new Contract(address, abi, signer)

const isPaused = await contract.paused()

if (!isPaused) {
this.console.error('The contract is not paused. No need to recover xBZZ.')

return
}

this.console.log('Recovering xBZZ from paused staking contract...')
await contract.migrateStake()
}
}
20 changes: 20 additions & 0 deletions src/command/stake/status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { LeafCommand } from 'furious-commander'
import { createKeyValue } from '../../utils/text'
import { RootCommand } from '../root-command'

export class Status extends RootCommand implements LeafCommand {
public readonly name = 'status'

public readonly description = `Prints staked and withdrawable stake`

public async run(): Promise<void> {
super.init()

const stake = await this.bee.getStake()
const surplusStake = await this.bee.getWithdrawableStake()

this.console.log(createKeyValue('Staked xBZZ', stake.toDecimalString()))
this.console.log(createKeyValue('Withdrawable staked xBZZ', surplusStake.toDecimalString()))
this.console.quiet(stake.toDecimalString())
}
}
50 changes: 50 additions & 0 deletions src/command/stake/withdraw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { BZZ } from '@ethersphere/bee-js'
import { LeafCommand } from 'furious-commander'
import { createSpinner } from '../../utils/spinner'
import { RootCommand } from '../root-command'
import { VerbosityLevel } from '../root-command/command-log'

export class Withdraw extends RootCommand implements LeafCommand {
public readonly name = 'withdraw'

public readonly description = `Withdraw surplus stake to the node's balance`

public async run(): Promise<void> {
super.init()

const surplusStake = await this.bee.getWithdrawableStake()

if (surplusStake.eq(BZZ.fromDecimalString('0'))) {
this.console.log('There is no surplus stake to withdraw.')

return
}

if (!this.quiet && !this.yes) {
this.yes = await this.console.confirm(
`You are about to withdraw a surplus stake of ${surplusStake.toDecimalString()} xBZZ, are you sure you wish to proceed?`,
)
}

if (!this.yes && !this.quiet) {
return
}

const spinner = createSpinner('Withdrawing surplus stake')

if (this.verbosity !== VerbosityLevel.Quiet && !this.curl) {
spinner.start()
}
try {
await this.bee.withdrawSurplusStake()
spinner.stop()

this.console.log(
'Successfully withdrawn surplus stake! It may take a few minutes for the withdrawal to be reflected in the node status.',
)
} catch (e) {
spinner.stop()
throw e
}
}
}
2 changes: 1 addition & 1 deletion src/command/stamp/dilute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Dilute extends StampCommand implements LeafCommand {
public stamp!: string

public async run(): Promise<void> {
await super.init()
super.init()

if (!this.stamp) {
this.stamp = await pickStamp(this.bee, this.console)
Expand Down
2 changes: 1 addition & 1 deletion src/command/stamp/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class List extends StampCommand implements LeafCommand {
public minUsage!: number

public async run(): Promise<void> {
await super.init()
super.init()
this.console.verbose(`Listing postage stamps...`)

const stamps = (await this.bee.getAllPostageBatch()) || []
Expand Down
2 changes: 1 addition & 1 deletion src/command/stamp/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class Show extends StampCommand implements LeafCommand {
public stamp!: string

public async run(): Promise<void> {
await super.init()
super.init()

if (!this.stamp) {
this.stamp = await pickStamp(this.bee, this.console)
Expand Down
2 changes: 1 addition & 1 deletion src/command/stamp/topup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Topup extends StampCommand implements LeafCommand {
public stamp!: string

public async run(): Promise<void> {
await super.init()
super.init()

if (!this.stamp) {
this.stamp = await pickStamp(this.bee, this.console)
Expand Down
6 changes: 3 additions & 3 deletions src/command/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ export class Status extends RootCommand implements LeafCommand {
this.console.all(createKeyValue('Total xBZZ', totalBalance.toDecimalString()))
}

if (nodeInfo.beeMode !== BeeModes.ULTRA_LIGHT && nodeInfo.beeMode !== BeeModes.DEV) {
if (nodeInfo.beeMode === BeeModes.FULL) {
this.console.all('')
this.console.all(chalk.bold('Staking'))
const stake = await this.bee.getStake()
const surplusStake = await this.bee.getWithdrawableStake()
this.console.all(createKeyValue('Staked xBZZ', stake.toDecimalString()))
}
this.console.all(createKeyValue('Withdrawable staked xBZZ', surplusStake.toDecimalString()))

if (nodeInfo.beeMode === BeeModes.FULL) {
const reserveStatus = await this.bee.getStatus()
this.console.all('')
this.console.all(chalk.bold('Reserve'))
Expand Down
2 changes: 1 addition & 1 deletion src/command/utility/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class Lock extends RootCommand implements LeafCommand {
public walletSource!: string

public async run(): Promise<void> {
await super.init()
super.init()
const wallet = await createWallet(this.walletSource, this.console)
const password = await this.console.askForPasswordWithConfirmation(
'Enter a new password to encrypt key file',
Expand Down
2 changes: 1 addition & 1 deletion src/command/utility/unlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class Unlock extends RootCommand implements LeafCommand {
public walletSource!: string

public async run(): Promise<void> {
await super.init()
super.init()
const wallet = await createWallet(this.walletSource, this.console)

if (!this.yes) {
Expand Down
Loading
Loading