@@ -8,18 +8,24 @@ import {
88 BridgeStrategyDataParams ,
99} from "../_bridges/types" ;
1010
11+ const ACROSS_THRESHOLD = 10_000 ; // 10K USD
12+ const LARGE_DEPOSIT_THRESHOLD = 1_000_000 ; // 1M USD
13+
1114export function isFullyUtilized ( limits : LimitsResponse ) : boolean {
1215 // Check if utilization is high (>80%)
1316 const { liquidReserves, utilizedReserves } = limits . reserves ;
1417 const _liquidReserves = BigNumber . from ( liquidReserves ) ;
1518 const _utilizedReserves = BigNumber . from ( utilizedReserves ) ;
19+ const flooredUtilizedReserves = _utilizedReserves . gt ( 0 )
20+ ? _utilizedReserves
21+ : BigNumber . from ( 0 ) ;
1622
1723 const utilizationThreshold = sdk . utils . fixedPointAdjustment . mul ( 80 ) . div ( 100 ) ; // 80%
1824
1925 // Calculate current utilization percentage
20- const currentUtilization = _utilizedReserves
26+ const currentUtilization = flooredUtilizedReserves
2127 . mul ( sdk . utils . fixedPointAdjustment )
22- . div ( _liquidReserves . add ( _utilizedReserves ) ) ;
28+ . div ( _liquidReserves . add ( flooredUtilizedReserves ) ) ;
2329
2430 return currentUtilization . gt ( utilizationThreshold ) ;
2531}
@@ -69,15 +75,14 @@ export async function getBridgeStrategyData({
6975 const depositAmountUsd = parseFloat (
7076 ethers . utils . formatUnits ( amountInInputTokenDecimals , inputToken . decimals )
7177 ) ;
72- const isInThreshold = depositAmountUsd <= 10_000 ; // 10K USD
73- const isLargeDeposit = depositAmountUsd > 1_000_000 ; // 1M USD
78+ const isInThreshold = depositAmountUsd <= ACROSS_THRESHOLD ;
79+ const isLargeDeposit = depositAmountUsd > LARGE_DEPOSIT_THRESHOLD ;
7480
7581 // Check if eligible for Fast CCTP (Polygon, BSC, Solana) and deposit > 10K USD
7682 const fastCctpChains = [ CHAIN_IDs . POLYGON , CHAIN_IDs . BSC , CHAIN_IDs . SOLANA ] ;
77- const isFastCctpChain =
78- fastCctpChains . includes ( inputToken . chainId ) ||
79- fastCctpChains . includes ( outputToken . chainId ) ;
80- const isFastCctpEligible = isFastCctpChain && depositAmountUsd > 10_000 ; // 10K USD
83+ const isFastCctpChain = fastCctpChains . includes ( inputToken . chainId ) ;
84+ const isFastCctpEligible =
85+ isFastCctpChain && depositAmountUsd > ACROSS_THRESHOLD ;
8186
8287 // Check if Linea is the source chain
8388 const isLineaSource = inputToken . chainId === CHAIN_IDs . LINEA ;
@@ -92,11 +97,13 @@ export async function getBridgeStrategyData({
9297 isLineaSource,
9398 } ;
9499 } catch ( error ) {
95- logger . warn ( {
96- at : "getBridgeStrategyData" ,
97- message : "Failed to fetch bridge strategy data, using defaults" ,
98- error : error instanceof Error ? error . message : String ( error ) ,
99- } ) ;
100+ if ( logger ) {
101+ logger . warn ( {
102+ at : "getBridgeStrategyData" ,
103+ message : "Failed to fetch bridge strategy data, using defaults" ,
104+ error : error instanceof Error ? error . message : String ( error ) ,
105+ } ) ;
106+ }
100107
101108 // Safely return undefined if we can't fetch bridge strategy data
102109 return undefined ;
0 commit comments