@@ -15,6 +15,7 @@ import { BalancerChartDataItem, PoolData } from './balancerTypes';
1515import { CoingeckoSnapshotPriceData } from './useTokens' ;
1616import { DateTime } from 'luxon' ;
1717import { CG_KEY } from "./constants" ;
18+ import { sanitizeChartData , sanitizeScalarValue } from '../../utils/dataValidation' ;
1819
1920function getPoolValues (
2021 poolId : string ,
@@ -131,6 +132,21 @@ export function useBalancerPools(first = 250, startunixTime = startTimestamp, en
131132
132133 //TODO: token price information is not stored in PoolData Object model anymore -> remove
133134
135+ // Sanitize pool metrics (hack data corruption fix)
136+ const sanitizedTvl = sanitizeScalarValue ( poolData . tvl , 0 , 'tvl' ) ;
137+ const sanitizedTvl24 = sanitizeScalarValue ( poolData24 . tvl , 0 , 'tvl' ) ;
138+ const sanitizedVolume = sanitizeScalarValue ( poolData . volume , 0 , 'volume' ) ;
139+ const sanitizedVolume24 = sanitizeScalarValue ( poolData24 . volume , 0 , 'volume' ) ;
140+ const sanitizedFees = sanitizeScalarValue ( poolData . fees , 0 , 'fees' ) ;
141+ const sanitizedFees24 = sanitizeScalarValue ( poolData24 . fees , 0 , 'fees' ) ;
142+ const sanitizedFeesEpoch = sanitizeScalarValue ( poolData . feesEpoch , 0 , 'fees' ) ;
143+ const sanitizedProtocolFeesEpoch = sanitizeScalarValue ( poolData . protcolFeesEpoch , 0 , 'protocolFees' ) ;
144+
145+ const volumeDelta = sanitizedVolume - sanitizedVolume24 ;
146+ const feesDelta = sanitizedFees - sanitizedFees24 ;
147+ const tvlChange = sanitizedTvl24 !== 0 ? ( sanitizedTvl - sanitizedTvl24 ) / sanitizedTvl24 : 0 ;
148+ const volumeChange = sanitizedVolume24 !== 0 ? volumeDelta / sanitizedVolume24 : 0 ;
149+
134150 return {
135151 ...pool ,
136152 name : pool . name || '' ,
@@ -152,18 +168,17 @@ export function useBalancerPools(first = 250, startunixTime = startTimestamp, en
152168 balance,
153169 } ;
154170 } ) ,
155- liquidity : poolData . tvl ,
171+ liquidity : sanitizedTvl ,
156172 sqrtPrice : 0 ,
157173 tick : 0 ,
158- volumeUSD : poolData . volume - poolData24 . volume ,
159- volumeUSDChange :
160- ( poolData . volume - poolData24 . volume ) / poolData24 . volume ,
174+ volumeUSD : sanitizeScalarValue ( volumeDelta , 0 ) ,
175+ volumeUSDChange : sanitizeScalarValue ( volumeChange , 0 ) ,
161176 //volumeUSDChange: 100 / poolData24.volume * poolData.volume,
162- feesUSD : poolData . fees - poolData24 . fees ,
163- feesEpochUSD : poolData . feesEpoch ,
164- protocolFeesEpocUSD : poolData . protcolFeesEpoch ,
165- tvlUSD : poolData . tvl ,
166- tvlUSDChange : ( poolData . tvl - poolData24 . tvl ) / poolData24 . tvl ,
177+ feesUSD : sanitizeScalarValue ( feesDelta , 0 ) ,
178+ feesEpochUSD : sanitizedFeesEpoch ,
179+ protocolFeesEpocUSD : sanitizedProtocolFeesEpoch ,
180+ tvlUSD : sanitizedTvl ,
181+ tvlUSDChange : sanitizeScalarValue ( tvlChange , 0 ) ,
167182 //tvlUSDChange: 100 / poolData24.tvl * poolData.tvl,
168183 poolType : poolData . poolType + "" ,
169184 amp : pool . amp ? pool . amp : '0' ,
@@ -243,6 +258,19 @@ export function useBalancerPoolSingleData(poolId: string): PoolData | null {
243258 }
244259
245260
261+ // Sanitize pool metrics (hack data corruption fix)
262+ const sanitizedTvl = sanitizeScalarValue ( parseFloat ( pool . totalLiquidity ) , 0 , 'tvl' ) ;
263+ const sanitizedTvl24 = sanitizeScalarValue ( parseFloat ( pool24 . totalLiquidity ) , 0 , 'tvl' ) ;
264+ const sanitizedVolume = sanitizeScalarValue ( parseFloat ( pool . totalSwapVolume ) , 0 , 'volume' ) ;
265+ const sanitizedVolume24 = sanitizeScalarValue ( parseFloat ( pool24 . totalSwapVolume ) , 0 , 'volume' ) ;
266+ const sanitizedFees = sanitizeScalarValue ( parseFloat ( pool . totalSwapFee ) , 0 , 'fees' ) ;
267+ const sanitizedFees24 = sanitizeScalarValue ( parseFloat ( pool24 . totalSwapFee ) , 0 , 'fees' ) ;
268+
269+ const volumeDelta = sanitizedVolume - sanitizedVolume24 ;
270+ const feesDelta = sanitizedFees - sanitizedFees24 ;
271+ const tvlChange = sanitizedTvl24 !== 0 ? ( sanitizedTvl - sanitizedTvl24 ) / sanitizedTvl24 : 0 ;
272+ const volumeChange = sanitizedVolume24 !== 0 ? volumeDelta / sanitizedVolume24 : 0 ;
273+
246274 return {
247275 ...pool ,
248276 name : pool . name || '' ,
@@ -264,18 +292,17 @@ export function useBalancerPoolSingleData(poolId: string): PoolData | null {
264292 balance,
265293 } ;
266294 } ) ,
267- liquidity : parseFloat ( pool . totalLiquidity ) ,
295+ liquidity : sanitizedTvl ,
268296 sqrtPrice : 0 ,
269297 tick : 0 ,
270- volumeUSD : parseFloat ( pool . totalSwapVolume ) - parseFloat ( pool24 . totalSwapVolume ) ,
271- volumeUSDChange :
272- ( parseFloat ( pool . totalSwapVolume ) - parseFloat ( pool24 . totalSwapVolume ) ) / parseFloat ( pool24 . totalSwapVolume ) ,
298+ volumeUSD : sanitizeScalarValue ( volumeDelta , 0 ) ,
299+ volumeUSDChange : sanitizeScalarValue ( volumeChange , 0 ) ,
273300 //volumeUSDChange: 100 / poolData24.volume * poolData.volume,
274- feesUSD : parseFloat ( pool . totalSwapFee ) - parseFloat ( pool24 . totalSwapFee ) ,
301+ feesUSD : sanitizeScalarValue ( feesDelta , 0 ) ,
275302 feesEpochUSD : 0 ,
276303 protocolFeesEpocUSD : 0 ,
277- tvlUSD : parseFloat ( pool . totalLiquidity ) ,
278- tvlUSDChange : ( parseFloat ( pool . totalLiquidity ) - parseFloat ( pool24 . totalLiquidity ) ) / parseFloat ( pool24 . totalLiquidity ) ,
304+ tvlUSD : sanitizedTvl ,
305+ tvlUSDChange : sanitizeScalarValue ( tvlChange , 0 ) ,
279306 //tvlUSDChange: 100 / poolData24.tvl * poolData.tvl,
280307 poolType : pool . poolType + "" ,
281308 amp : pool . amp ? pool . amp : '0' ,
@@ -428,11 +455,12 @@ export function useBalancerPoolPageData(poolId: string): {
428455
429456 const tokenDatas = coingeckoSnapshotData ;
430457
458+ // Sanitize chart data (hack data corruption fix)
431459 return {
432- tvlData,
433- volumeData,
434- feesData,
435- protocolFeesData,
460+ tvlData : sanitizeChartData ( tvlData , 'tvl' ) ,
461+ volumeData : sanitizeChartData ( volumeData , 'volume' ) ,
462+ feesData : sanitizeChartData ( feesData , 'fees' ) ,
463+ protocolFeesData : sanitizeChartData ( protocolFeesData , 'protocolFees' ) ,
436464 tokenDatas,
437465 } ;
438466}
0 commit comments