@@ -9505,6 +9505,20 @@ async function discoverSeedCandidatesFromProtocolMeta(protocol) {
95059505}
95069506
95079507async function scorePoolCandidates ( candidates , protocol ) {
9508+ const callWithTimeout = async (
9509+ promiseFactory ,
9510+ timeoutMs = 3500 ,
9511+ fallback = null ,
9512+ ) => {
9513+ const timeout = new Promise ( ( resolve ) => {
9514+ setTimeout ( ( ) => resolve ( fallback ) , timeoutMs ) ;
9515+ } ) ;
9516+ try {
9517+ return await Promise . race ( [ promiseFactory ( ) , timeout ] ) ;
9518+ } catch {
9519+ return fallback ;
9520+ }
9521+ } ;
95089522 const provider = new JsonRpcProvider ( BSC_RPC_URL , {
95099523 name : "bsc" ,
95109524 chainId : BSC_CHAIN_ID ,
@@ -9573,9 +9587,20 @@ async function scorePoolCandidates(candidates, protocol) {
95739587 const rows = [ ] ;
95749588 for ( const pool of candidates ) {
95759589 const [ usdcRaw , usdtRaw , listaProbe ] = await Promise . all ( [
9576- readWithFallback ( ( ) => readBalanceRaw ( BSC_USDC , pool ) , "0" ) ,
9577- readWithFallback ( ( ) => readBalanceRaw ( BSC_USDT , pool ) , "0" ) ,
9578- probeListaCompatibility ( pool ) ,
9590+ callWithTimeout (
9591+ ( ) => readWithFallback ( ( ) => readBalanceRaw ( BSC_USDC , pool ) , "0" ) ,
9592+ 3000 ,
9593+ "0" ,
9594+ ) ,
9595+ callWithTimeout (
9596+ ( ) => readWithFallback ( ( ) => readBalanceRaw ( BSC_USDT , pool ) , "0" ) ,
9597+ 3000 ,
9598+ "0" ,
9599+ ) ,
9600+ callWithTimeout ( ( ) => probeListaCompatibility ( pool ) , 3500 , {
9601+ compatible : false ,
9602+ reason : "probe_timeout" ,
9603+ } ) ,
95799604 ] ) ;
95809605 const usdcUi = Number ( rawToUi ( usdcRaw , BSC_USDC_DECIMALS ) ) ;
95819606 const usdtUi = Number ( rawToUi ( usdtRaw , BSC_USDT_DECIMALS ) ) ;
0 commit comments