@@ -141,6 +141,15 @@ const isMissingSelectorError = (err) =>
141141 err ?. data === "0x" ||
142142 err ?. info ?. error ?. data === "0x" ;
143143
144+ const isMissingSelectorOrBareRevertError = ( err ) =>
145+ isMissingSelectorError ( err ) ||
146+ ( err ?. name === "ProviderError" && err ?. message === "execution reverted" ) ;
147+
148+ const errorSummary = ( err ) =>
149+ [ err ?. name , err ?. code , err ?. message , err ?. data || err ?. info ?. error ?. data ]
150+ . filter ( Boolean )
151+ . join ( ": " ) ;
152+
144153const legacyArmContract = async ( arm , signerOrProvider ) =>
145154 new Contract (
146155 await arm . getAddress ( ) ,
@@ -414,17 +423,25 @@ const getArmBuffer = async (arm, blockTag) => {
414423
415424const getOutstandingWithdrawals = async ( arm , blockTag ) => {
416425 const opts = blockTag === undefined ? [ ] : [ { blockTag } ] ;
426+ let reservedWithdrawLiquidityError ;
427+ let currentAbiWithdrawalsError ;
417428 // Liquidity reserved for outstanding LP withdrawal requests (asset-denominated).
418429 // Newer ARMs track the asset-denominated amount directly in
419- // reservedWithdrawLiquidity(). Legacy ARMs expose
430+ // reservedWithdrawLiquidity(). Legacy Lido and EtherFi ARMs expose
420431 // withdrawsQueued()/withdrawsClaimed(); several new ABIs dropped these getters
421432 // even though the deployed legacy contracts still implement them on-chain, so
422433 // fall back to the legacy ABI.
423434 if ( arm . reservedWithdrawLiquidity ) {
424435 try {
425436 return await arm . reservedWithdrawLiquidity ( ...opts ) ;
426437 } catch ( err ) {
427- if ( ! isMissingSelectorError ( err ) ) throw err ;
438+ reservedWithdrawLiquidityError = err ;
439+ if ( ! isMissingSelectorOrBareRevertError ( err ) ) {
440+ throw new Error (
441+ `Failed to read outstanding withdrawals via reservedWithdrawLiquidity(): ${ errorSummary ( err ) } ` ,
442+ { cause : err } ,
443+ ) ;
444+ }
428445 }
429446 }
430447
@@ -435,7 +452,13 @@ const getOutstandingWithdrawals = async (arm, blockTag) => {
435452 ] ) ;
436453 return queued - claimed ;
437454 } catch ( err ) {
438- if ( ! isMissingSelectorError ( err ) ) throw err ;
455+ currentAbiWithdrawalsError = err ;
456+ if ( ! isMissingSelectorError ( err ) ) {
457+ throw new Error (
458+ `Failed to read outstanding withdrawals via withdrawsQueued()/withdrawsClaimed(): ${ errorSummary ( err ) } ` ,
459+ { cause : err } ,
460+ ) ;
461+ }
439462 }
440463 try {
441464 const legacyArm = await legacyArmContract ( arm ) ;
@@ -445,8 +468,27 @@ const getOutstandingWithdrawals = async (arm, blockTag) => {
445468 ] ) ;
446469 return queued - claimed ;
447470 } catch ( err ) {
448- if ( ! isMissingSelectorError ( err ) ) throw err ;
449- return arm . reservedWithdrawLiquidity ( ...opts ) ;
471+ if ( ! isMissingSelectorError ( err ) ) {
472+ throw new Error (
473+ `Failed to read outstanding withdrawals via legacy withdrawsQueued()/withdrawsClaimed(): ${ errorSummary ( err ) } ` ,
474+ { cause : err } ,
475+ ) ;
476+ }
477+
478+ const armAddress = await arm . getAddress ( ) ;
479+ const reservedResult = reservedWithdrawLiquidityError
480+ ? `failed (${ errorSummary ( reservedWithdrawLiquidityError ) } )`
481+ : "was not available in the current ABI" ;
482+ const currentAbiResult = currentAbiWithdrawalsError
483+ ? `failed (${ errorSummary ( currentAbiWithdrawalsError ) } )`
484+ : "was not attempted" ;
485+ throw new Error (
486+ `Unable to read outstanding withdrawals for ARM ${ armAddress } : ` +
487+ `reservedWithdrawLiquidity() ${ reservedResult } ; ` +
488+ `current ABI withdrawsQueued()/withdrawsClaimed() ${ currentAbiResult } ; ` +
489+ `legacy ABI withdrawsQueued()/withdrawsClaimed() failed (${ errorSummary ( err ) } )` ,
490+ { cause : err } ,
491+ ) ;
450492 }
451493} ;
452494
0 commit comments