Skip to content

Commit

Permalink
chore(namada): type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
egasimus committed Jun 26, 2024
1 parent fd0a3ea commit be4d5f2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 47 deletions.
4 changes: 2 additions & 2 deletions packages/namada/NamadaConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default class NamadaConsole extends Console {
.log(' Stake: ', bold(validator.stake))
.log(' Voting power: ', bold(validator.votingPower))
.log(' Priority: ', bold(validator.proposerPriority))
.log(' Commission: ', bold(validator.commission.commissionRate))
.log(' Max change: ', bold(validator.commission.maxCommissionChangePerEpoch), 'per epoch')
.log(' Commission: ', bold(validator.commission?.commissionRate))
.log(' Max change: ', bold(validator.commission?.maxCommissionChangePerEpoch), 'per epoch')
.log('Email: ', bold(validator.metadata?.email||''))
.log('Website: ', bold(validator.metadata?.website||''))
.log('Discord: ', bold(validator.metadata?.discordHandle||''))
Expand Down
20 changes: 19 additions & 1 deletion packages/namada/NamadaDecode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,25 @@ export interface NamadaDecoder {
gov_result (_: Uint8Array): Partial<Gov.ProposalResult>
pgf_parameters (_: Uint8Array): Partial<PGF.Parameters>
pos_validator_set (_: Uint8Array): { bondedStake: number|bigint }[]
pos_parameters (_: Uint8Array): Partial<PoS.Parameters>
pos_parameters (_: Uint8Array): Partial<{
maxProposalPeriod: bigint
maxValidatorSlots: bigint
pipelineLen: bigint
unbondingLen: bigint
tmVotesPerToken: bigint
blockProposerReward: bigint
blockVoteReward: bigint
maxInflationRate: bigint
targetStakedRatio: bigint
duplicateVoteMinSlashRate: bigint
lightClientAttackMinSlashRate: bigint
cubicSlashingWindowLength: bigint
validatorStakeThreshold: bigint
livenessWindowCheck: bigint
livenessThreshold: bigint
rewardsGainP: bigint
rewardsGainD: bigint
}>
pos_validator_state (_: Uint8Array): unknown
storage_keys ():
{ epochDuration: string
Expand Down
48 changes: 4 additions & 44 deletions packages/namada/NamadaPoS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,6 @@ import type {
Connection as NamadaConnection
} from './Namada'

class NamadaPoSParameters {
maxProposalPeriod!: bigint
maxValidatorSlots!: bigint
pipelineLen!: bigint
unbondingLen!: bigint
tmVotesPerToken!: bigint
blockProposerReward!: bigint
blockVoteReward!: bigint
maxInflationRate!: bigint
targetStakedRatio!: bigint
duplicateVoteMinSlashRate!: bigint
lightClientAttackMinSlashRate!: bigint
cubicSlashingWindowLength!: bigint
validatorStakeThreshold!: bigint
livenessWindowCheck!: bigint
livenessThreshold!: bigint
rewardsGainP!: bigint
rewardsGainD!: bigint
constructor (properties: Partial<NamadaPoSParameters> = {}) {
assign(this, properties, [
'maxProposalPeriod',
'maxValidatorSlots',
'pipelineLen',
'unbondingLen',
'tmVotesPerToken',
'blockProposerReward',
'blockVoteReward',
'maxInflationRate',
'targetStakedRatio',
'duplicateVoteMinSlashRate',
'lightClientAttackMinSlashRate',
'cubicSlashingWindowLength',
'validatorStakeThreshold',
'livenessWindowCheck',
'livenessThreshold',
'rewardsGainP',
'rewardsGainD',
])
}
}

class NamadaValidator extends Staking.Validator {
constructor (properties: Omit<ConstructorParameters<typeof Staking.Validator>[0], 'chain'> & {
chain: Namada, namadaAddress?: string,
Expand Down Expand Up @@ -78,9 +37,10 @@ class NamadaValidator extends Staking.Validator {
bondedStake?: number

async fetchDetails (options?: { parallel?: boolean }) {
return fetchValidatorDetails(this.chain.getConnection(), {
await fetchValidatorDetails(this.chain.getConnection(), {
...options, validator: this
})
return this
}
}

Expand All @@ -106,7 +66,7 @@ export async function fetchValidators (
parallelDetails?: boolean,
interval?: number,
} = {}
): Promise<Record<string, NamadaValidator>> {
): Promise<NamadaValidator[]> {
const connection =
chain.getConnection()
const validators: Record<string, NamadaValidator> =
Expand All @@ -129,7 +89,7 @@ export async function fetchValidators (
parallelDetails: options?.parallelDetails,
})
}
return validators
return Object.values(validators)
}

export async function fetchValidatorAddresses (connection: NamadaConnection): Promise<Address[]> {
Expand Down

0 comments on commit be4d5f2

Please sign in to comment.