Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): token payout ratios are not needed/used in the UI #153

Merged
merged 1 commit into from
May 17, 2024
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
48 changes: 7 additions & 41 deletions ui/src/api/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
RawConstraints,
RawNodePoolAssignmentConfig,
RawPoolsInfo,
RawPoolTokenPayoutRatios,
RawValidatorConfig,
RawValidatorState,
Validator,
Expand Down Expand Up @@ -85,28 +84,19 @@ export async function fetchValidator(
try {
const validatorClient = client || (await getSimulateValidatorClient())

const [config, state, validatorPoolData, poolTokenPayoutRatios, nodePoolAssignments] =
await Promise.all([
callGetValidatorConfig(Number(validatorId), validatorClient),
callGetValidatorState(Number(validatorId), validatorClient),
callGetPools(Number(validatorId), validatorClient),
callGetTokenPayoutRatio(Number(validatorId), validatorClient),
callGetNodePoolAssignments(Number(validatorId), validatorClient),
])
const [config, state, validatorPoolData, nodePoolAssignments] = await Promise.all([
callGetValidatorConfig(Number(validatorId), validatorClient),
callGetValidatorState(Number(validatorId), validatorClient),
callGetPools(Number(validatorId), validatorClient),
callGetNodePoolAssignments(Number(validatorId), validatorClient),
])

const rawConfig = config.returns?.[0] as RawValidatorConfig
const rawState = state.returns?.[0] as RawValidatorState
const rawPoolsInfo = validatorPoolData.returns?.[0] as RawPoolsInfo
const rawPoolTokenPayoutRatios = poolTokenPayoutRatios.returns?.[0] as RawPoolTokenPayoutRatios
const rawNodePoolAssignment = nodePoolAssignments.returns?.[0] as RawNodePoolAssignmentConfig

if (
!rawConfig ||
!rawState ||
!rawPoolsInfo ||
!rawPoolTokenPayoutRatios ||
!rawNodePoolAssignment
) {
if (!rawConfig || !rawState || !rawPoolsInfo || !rawNodePoolAssignment) {
throw new ValidatorNotFoundError(`Validator with id "${Number(validatorId)}" not found!`)
}

Expand All @@ -115,7 +105,6 @@ export async function fetchValidator(
rawConfig,
rawState,
rawPoolsInfo,
rawPoolTokenPayoutRatios,
rawNodePoolAssignment,
)

Expand Down Expand Up @@ -318,29 +307,6 @@ export async function fetchNodePoolAssignments(
}
}

export function callGetTokenPayoutRatio(
validatorId: number | bigint,
validatorClient: ValidatorRegistryClient,
) {
return validatorClient
.compose()
.getTokenPayoutRatio({ validatorId })
.simulate({ allowEmptySignatures: true, allowUnnamedResources: true })
}

export async function fetchTokenPayoutRatio(validatorId: string | number | bigint) {
try {
const validatorClient = await getSimulateValidatorClient()

const result = await callGetTokenPayoutRatio(Number(validatorId), validatorClient)

return result.returns![0]
} catch (error) {
console.error(error)
throw error
}
}

export function callGetMbrAmounts(validatorClient: ValidatorRegistryClient) {
return validatorClient
.compose()
Expand Down
8 changes: 0 additions & 8 deletions ui/src/interfaces/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ export interface PoolInfo {
algodVersion?: string
}

export type RawPoolTokenPayoutRatios = [[bigint, ...bigint[]], bigint]

export interface PoolTokenPayoutRatio {
poolPctOfWhole: number[]
updatedForPayout: number
}

export type NodeConfig = [bigint, ...bigint[]]
export type RawNodePoolAssignmentConfig = [[NodeConfig][]]
export type NodePoolAssignmentConfig = NodeConfig[]
Expand All @@ -90,7 +83,6 @@ export type Validator = {
config: Omit<ValidatorConfig, 'id'>
state: ValidatorState
pools: PoolInfo[]
tokenPayoutRatio: number[]
nodePoolAssignment: NodePoolAssignmentConfig
nfd?: Nfd
}
Expand Down
22 changes: 0 additions & 22 deletions ui/src/utils/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import {
NodeInfo,
NodePoolAssignmentConfig,
PoolInfo,
PoolTokenPayoutRatio,
RawNodePoolAssignmentConfig,
RawPoolsInfo,
RawPoolTokenPayoutRatios,
RawValidatorConfig,
RawValidatorState,
Validator,
Expand Down Expand Up @@ -90,50 +88,30 @@ export function transformNodePoolAssignment(
return rawConfig[0].flat()
}

/**
* Transform raw pool token payout ratio data (from `callGetTokenPayoutRatio`) into a flat array of payout ratios
* @param {RawPoolTokenPayoutRatios} rawData - Raw pool token payout ratio data
* @returns {number[]} Array of pool token payout ratios
*/
export function transformPoolTokenPayoutRatio(rawData: RawPoolTokenPayoutRatios): number[] {
const [poolPctOfWhole, updatedForPayout] = rawData

const poolTokenPayoutRatio: PoolTokenPayoutRatio = {
poolPctOfWhole: poolPctOfWhole.map((poolPct) => Number(poolPct)),
updatedForPayout: Number(updatedForPayout),
}

return poolTokenPayoutRatio.poolPctOfWhole
}

/**
* Transform raw validator data from multiple ABI method calls into a structured `Validator` object
* @param {RawValidatorConfig} rawConfig - Raw validator configuration data
* @param {RawValidatorState} rawState - Raw validator state data
* @param {RawPoolsInfo} rawPoolsInfo - Raw staking pool data
* @param {RawPoolTokenPayoutRatios} rawPoolTokenPayoutRatios - Raw pool token payout ratio data
* @param {RawNodePoolAssignmentConfig} rawNodePoolAssignment - Raw node pool assignment configuration data
* @returns {Validator} Structured validator object
*/
export function transformValidatorData(
rawConfig: RawValidatorConfig,
rawState: RawValidatorState,
rawPoolsInfo: RawPoolsInfo,
rawPoolTokenPayoutRatios: RawPoolTokenPayoutRatios,
rawNodePoolAssignment: RawNodePoolAssignmentConfig,
): Validator {
const { id, ...config } = transformValidatorConfig(rawConfig)
const state = transformValidatorState(rawState)
const pools = transformPoolsInfo(rawPoolsInfo)
const tokenPayoutRatio = transformPoolTokenPayoutRatio(rawPoolTokenPayoutRatios)
const nodePoolAssignment = transformNodePoolAssignment(rawNodePoolAssignment)

return {
id,
config,
state,
pools,
tokenPayoutRatio,
nodePoolAssignment,
}
}
Expand Down
4 changes: 0 additions & 4 deletions ui/src/utils/tests/fixtures/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,13 @@ export const MOCK_VALIDATOR_2_POOL_ASSIGNMENT: NodeConfig[] = createStaticArray<
8,
)

export const MOCK_TOKEN_PAYOUT_RATIO = new Array(24).fill(0)

const { id: validator1Id, ...validator1Config } = MOCK_VALIDATOR_1_CONFIG

export const MOCK_VALIDATOR_1: Validator = {
id: validator1Id,
config: validator1Config,
state: MOCK_VALIDATOR_1_STATE,
pools: MOCK_VALIDATOR_1_POOLS,
tokenPayoutRatio: MOCK_TOKEN_PAYOUT_RATIO,
nodePoolAssignment: MOCK_VALIDATOR_1_POOL_ASSIGNMENT,
}

Expand All @@ -134,7 +131,6 @@ export const MOCK_VALIDATOR_2: Validator = {
config: validator2Config,
state: MOCK_VALIDATOR_2_STATE,
pools: MOCK_VALIDATOR_2_POOLS,
tokenPayoutRatio: MOCK_TOKEN_PAYOUT_RATIO,
nodePoolAssignment: MOCK_VALIDATOR_2_POOL_ASSIGNMENT,
}

Expand Down
Loading