File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ import { FeeTier , TICK_SPACING_BY_FEE } from "@/types/utils/getPool" ;
2+
3+ /**
4+ * Gets the appropriate tick spacing for a given fee tier.
5+ * @param fee The fee tier
6+ * @returns The corresponding tick spacing
7+ * @throws Error if fee tier is not supported
8+ */
9+ export function getTickSpacingForFee ( fee : number ) : number {
10+ if ( ! Object . values ( FeeTier ) . includes ( fee ) ) {
11+ throw new Error (
12+ `Unsupported fee tier: ${ fee } . Supported tiers: ${ Object . values ( FeeTier ) . join ( ", " ) } ` ,
13+ ) ;
14+ }
15+ return TICK_SPACING_BY_FEE [ fee as FeeTier ] ;
16+ }
17+
18+ /**
19+ * Validates if a fee tier is supported.
20+ * @param fee The fee tier to validate
21+ * @returns True if the fee tier is supported
22+ */
23+ export function isValidFeeTier ( fee : number ) : boolean {
24+ return Object . values ( FeeTier ) . includes ( fee ) ;
25+ }
26+
27+ /**
28+ * Gets the percentage representation of a fee tier.
29+ * @param fee The fee tier
30+ * @returns The fee as a percentage string
31+ * @throws Error if fee tier is not supported
32+ */
33+ export function getFeePercentage ( fee : number ) : string {
34+ if ( ! isValidFeeTier ( fee ) ) {
35+ throw new Error ( `Unsupported fee tier: ${ fee } ` ) ;
36+ }
37+ return `${ ( fee / 10000 ) . toFixed ( 2 ) } %` ;
38+ }
You can’t perform that action at this time.
0 commit comments