1- import { Aftermath } from 'aftermath-ts-sdk' ;
1+ import { Aftermath , Pool } from 'aftermath-ts-sdk' ;
22import { PoolInfo } from '../../@types/interface' ;
33import { handleError } from '../../utils' ;
44
55// Initialize Aftermath SDK for mainnet
66const af = new Aftermath ( 'MAINNET' ) ;
77const pools = af . Pools ( ) ;
88
9- // Type definitions for pool operations
10- type RankingMetric = 'apr' | 'tvl' | 'fees' | 'volume' ;
11- type SortOrder = 'asc' | 'desc' ;
12-
139/**
1410 * Processes raw pool data into standardized format
1511 * @param pool - Raw pool data from Aftermath
1612 * @param poolId - Unique identifier for the pool
1713 * @returns Standardized pool information
1814 */
19- async function processPool ( pool : any , poolId : string ) : Promise < PoolInfo > {
15+ async function processPool ( pool : Pool , poolId : string ) : Promise < PoolInfo > {
2016 try {
2117 const metrics = await pools . getPoolsStats ( { poolIds : [ poolId ] } ) ;
2218 const poolMetrics = metrics [ 0 ] ;
@@ -54,7 +50,10 @@ async function processPool(pool: any, poolId: string): Promise<PoolInfo> {
5450 * @param poolId - Unique identifier for the pool
5551 * @returns JSON string containing pool details or error information
5652 */
57- export async function getPool ( poolId : string ) : Promise < string > {
53+ export async function getPool (
54+ ...args : ( string | number | bigint | boolean ) [ ]
55+ ) : Promise < string > {
56+ const poolId = args [ 0 ] as string ;
5857 try {
5958 const pool = await pools . getPool ( { objectId : poolId } ) ;
6059 if ( ! pool ) {
@@ -132,10 +131,9 @@ export async function getAllPools(): Promise<string> {
132131 * @returns JSON string containing event information
133132 */
134133export async function getPoolEvents (
135- poolId : string ,
136- eventType : 'deposit' | 'withdraw' ,
137- limit = 10 ,
134+ ...args : ( string | number | bigint | boolean ) [ ]
138135) : Promise < string > {
136+ const [ poolId , eventType , limit ] = args as [ string , string , number ] ;
139137 try {
140138 const pool = await pools . getPool ( { objectId : poolId } ) ;
141139 if ( ! pool ) {
@@ -171,29 +169,6 @@ export async function getPoolEvents(
171169 }
172170}
173171
174- /**
175- * Calculates pool APR based on volume and TVL
176- * @param pool - Pool data containing volume and TVL information
177- * @returns Calculated APR as a percentage
178- */
179- export function calculatePoolApr ( pool : any ) : number {
180- try {
181- // Convert values from base units
182- const volume24h = Number ( pool . pool . volume24h || 0 ) / 1e9 ;
183- const tvl = Number ( pool . pool . lpCoinSupply || 0 ) / 1e9 ;
184- if ( tvl === 0 ) return 0 ;
185-
186- // Calculate annual revenue and APR
187- const feeRate = Number ( pool . pool . flatness || 0 ) / 1e9 ;
188- const feeRevenue24h = volume24h * feeRate ;
189- const annualRevenue = feeRevenue24h * 365 ;
190- return ( annualRevenue / tvl ) * 100 ;
191- } catch ( error ) {
192- console . error ( 'Error calculating pool APR:' , error ) ;
193- return 0 ;
194- }
195- }
196-
197172/**
198173 * Gets ranked pools by specified metric
199174 * @param metric - Metric to rank by (apr, tvl, fees, volume)
@@ -202,10 +177,9 @@ export function calculatePoolApr(pool: any): number {
202177 * @returns JSON string containing ranked pool information
203178 */
204179export async function getRankedPools (
205- metric : RankingMetric = 'tvl' ,
206- limit = 10 ,
207- order : SortOrder = 'desc' ,
180+ ...args : ( string | number | bigint | boolean ) [ ]
208181) : Promise < string > {
182+ const [ metric , limit , order ] = args as [ string , number , string ] ;
209183 try {
210184 // Fetch and process all pools
211185 const allPools = await pools . getAllPools ( ) ;
@@ -299,10 +273,9 @@ export async function getRankedPools(
299273 * @returns JSON string containing filtered pool information
300274 */
301275export async function getFilteredPools (
302- minTvl ?: number ,
303- minApr ?: number ,
304- tokens ?: string [ ] ,
276+ ...args : ( string | number | bigint | boolean ) [ ]
305277) : Promise < string > {
278+ const [ minTvl , minApr , tokens ] = args as [ number , number , string [ ] ] ;
306279 try {
307280 // Fetch and process all pools
308281 const allPools = await pools . getAllPools ( ) ;
0 commit comments