@@ -10,6 +10,7 @@ import {
1010 ERC4626__factory ,
1111 GasRouter__factory ,
1212 HypERC20 ,
13+ HypERC20Collateral__factory ,
1314 HypERC20__factory ,
1415 HypERC4626 ,
1516 HypERC4626Collateral ,
@@ -73,7 +74,7 @@ import {
7374// An estimate of the gas amount for a typical EVM token router transferRemote transaction
7475// Computed by estimating on a few different chains, taking the max, and then adding ~50% padding
7576export const EVM_TRANSFER_REMOTE_GAS_ESTIMATE = 450_000n ;
76- const QUOTE_TRANSFER_REMOTE_CONTRACT_VERSION = '10.0.0' ;
77+ const TOKEN_FEE_CONTRACT_VERSION = '10.0.0' ;
7778
7879// Interacts with native currencies
7980export class EvmNativeTokenAdapter
@@ -275,18 +276,26 @@ export class EvmHypSyntheticAdapter
275276 return this . getTotalSupply ( ) ;
276277 }
277278
279+ async getContractPackageVersion ( ) {
280+ try {
281+ return await this . contract . PACKAGE_VERSION ( ) ;
282+ } catch ( err ) {
283+ // PACKAGE_VERSION was introduced in v5.4.0
284+ this . logger . error ( `Error when fetching package version ${ err } ` ) ;
285+ return '5.3.9' ;
286+ }
287+ }
288+
278289 async quoteTransferRemoteGas ( {
279290 destination,
280291 recipient,
281292 amount,
282293 } : QuoteTransferRemoteParams ) : Promise < InterchainGasQuote > {
283- const contractVersion = await this . contract . PACKAGE_VERSION ( ) ;
284-
294+ const contractVersion = await this . getContractPackageVersion ( ) ;
285295 const hasQuoteTransferRemote = isValidContractVersion (
286296 contractVersion ,
287- QUOTE_TRANSFER_REMOTE_CONTRACT_VERSION ,
297+ TOKEN_FEE_CONTRACT_VERSION ,
288298 ) ;
289-
290299 // Version does not support quoteTransferRemote defaulting to quoteGasPayment
291300 if ( ! hasQuoteTransferRemote ) {
292301 const gasPayment = await this . contract . quoteGasPayment ( destination ) ;
@@ -387,9 +396,22 @@ export class EvmHypCollateralAdapter
387396 }
388397
389398 async getWrappedTokenAddress ( ) : Promise < Address > {
390- if ( ! this . wrappedTokenAddress ) {
391- this . wrappedTokenAddress = await this . collateralContract . token ( ) ;
392- }
399+ if ( this . wrappedTokenAddress ) return this . wrappedTokenAddress ;
400+
401+ const contractVersion = await this . getContractPackageVersion ( ) ;
402+ const hasTokenFeeInterface = isValidContractVersion (
403+ contractVersion ,
404+ TOKEN_FEE_CONTRACT_VERSION ,
405+ ) ;
406+
407+ if ( ! hasTokenFeeInterface ) {
408+ const erc20CollateralContract = HypERC20Collateral__factory . connect (
409+ this . addresses . token ,
410+ this . getProvider ( ) ,
411+ ) ;
412+ this . wrappedTokenAddress = await erc20CollateralContract . wrappedToken ( ) ;
413+ } else this . wrappedTokenAddress = await this . collateralContract . token ( ) ;
414+
393415 return this . wrappedTokenAddress ! ;
394416 }
395417
0 commit comments