Skip to content

Commit 279b114

Browse files
committed
feat: add fees helper
1 parent 98c372a commit 279b114

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/helpers/fees.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
}

0 commit comments

Comments
 (0)