-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adopt params endpoint * resolve comments * resolve comments * resolve comments
- Loading branch information
1 parent
643eece
commit 98859da
Showing
5 changed files
with
150 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { getPublicKeyNoCoord } from "@babylonlabs-io/btc-staking-ts"; | ||
import { AxiosResponse } from "axios"; | ||
|
||
import { Params } from "../types/params"; | ||
|
||
import { apiWrapper } from "./apiWrapper"; | ||
|
||
export interface ParamsDataResponse { | ||
data: ParamsAPI; | ||
} | ||
|
||
export interface ParamsAPI { | ||
bbn: BbnParams[]; | ||
} | ||
|
||
export interface BbnParams { | ||
version: number; | ||
covenant_pks: string[]; | ||
covenant_quorum: number; | ||
min_staking_value_sat: number; | ||
max_staking_value_sat: number; | ||
min_staking_time_blocks: number; | ||
max_staking_time_blocks: number; | ||
slashing_pk_script: string; | ||
min_slashing_tx_fee_sat: number; | ||
slashing_rate: string; | ||
min_unbonding_time_blocks: number; | ||
unbonding_fee_sat: number; | ||
min_commission_rate: string; | ||
max_active_finality_providers: number; | ||
delegation_creation_base_gas_fee: number; | ||
} | ||
|
||
export const getParams = async (): Promise<Params> => { | ||
const { data } = (await apiWrapper( | ||
"GET", | ||
"/v2/global-params", | ||
"Error getting params", | ||
)) as AxiosResponse<ParamsDataResponse>; | ||
|
||
const params = data.data; | ||
|
||
const versions = params.bbn | ||
.sort((a, b) => a.version - b.version) // Sort by version ascending | ||
.map((v) => ({ | ||
version: v.version, | ||
covenantNoCoordPks: v.covenant_pks.map((pk) => | ||
String(getPublicKeyNoCoord(pk)), | ||
), | ||
covenantQuorum: v.covenant_quorum, | ||
minStakingValueSat: v.min_staking_value_sat, | ||
maxStakingValueSat: v.max_staking_value_sat, | ||
minStakingTimeBlocks: v.min_staking_time_blocks, | ||
maxStakingTimeBlocks: v.max_staking_time_blocks, | ||
unbondingTime: v.min_unbonding_time_blocks, | ||
unbondingFeeSat: v.unbonding_fee_sat, | ||
minCommissionRate: v.min_commission_rate, | ||
maxActiveFinalityProviders: v.max_active_finality_providers, | ||
delegationCreationBaseGasFee: v.delegation_creation_base_gas_fee, | ||
slashing: { | ||
slashingPkScriptHex: v.slashing_pk_script, | ||
slashingRate: parseFloat(v.slashing_rate), | ||
minSlashingTxFeeSat: v.min_slashing_tx_fee_sat, | ||
}, | ||
maxStakingAmountSat: v.max_staking_value_sat, | ||
minStakingAmountSat: v.min_staking_value_sat, | ||
})); | ||
|
||
const latestVersion = versions.reduce((prev, current) => | ||
current.version > prev.version ? current : prev, | ||
); | ||
|
||
return { | ||
bbnStakingParams: { | ||
latestVersion, | ||
versions, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { getParams } from "@/app/api/getParams"; | ||
import { useAPIQuery } from "@/app/hooks/api/useApi"; | ||
import { Params } from "@/app/types/params"; | ||
|
||
export const PARAMS_KEY = "PARAMS"; | ||
|
||
export function useParams({ enabled = true }: { enabled?: boolean } = {}) { | ||
const data = useAPIQuery<Params>({ | ||
queryKey: [PARAMS_KEY], | ||
queryFn: getParams, | ||
enabled, | ||
}); | ||
|
||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { StakingParams } from "@babylonlabs-io/btc-staking-ts"; | ||
|
||
export interface BbnStakingParamsVersion extends StakingParams { | ||
version: number; | ||
minCommissionRate: string; | ||
maxActiveFinalityProviders: number; | ||
delegationCreationBaseGasFee: number; | ||
} | ||
|
||
export interface BbnStakingParams { | ||
latestVersion: BbnStakingParamsVersion; | ||
versions: BbnStakingParamsVersion[]; | ||
} | ||
|
||
export interface Params { | ||
bbnStakingParams: BbnStakingParams; | ||
} |