Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bridge-ui): return true if the token address is found on dest chain to send correct gas limit #14446

Merged
merged 13 commits into from
Aug 12, 2023
55 changes: 32 additions & 23 deletions packages/bridge-ui/src/utils/checkIfTokenIsDeployedCrossChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,47 @@ export const checkIfTokenIsDeployedCrossChain = async (

const tokenAddressOnDestChain = token.addresses[destChain.id];

if (tokenAddressOnDestChain === '0x00') {
// Check if token is already deployed as BridgedERC20 on destination chain
const tokenAddressOnSourceChain = token.addresses[srcChain.id];

log(
'Checking if token',
token,
'is deployed as BridgedERC20 on destination chain',
destChain,
if (tokenAddressOnDestChain !== '0x00') {
return true;
}

// Check if token is already deployed as BridgedERC20 on destination chain
const tokenAddressOnSourceChain = token.addresses[srcChain.id];

log(
'Checking if token',
token,
'is deployed as BridgedERC20 on destination chain',
destChain,
);

try {
const isBridgedToken = await destTokenVaultContract.isBridgedToken(
tokenAddressOnSourceChain,
);

try {
if (isBridgedToken) {
return await destTokenVaultContract.bridgedToCanonical(
srcChain.id,
tokenAddressOnSourceChain,
);
} else {
const bridgedTokenAddress =
await destTokenVaultContract.canonicalToBridged(
srcChain.id,
tokenAddressOnSourceChain,
);

log(`Address of bridged token: ${bridgedTokenAddress}`);

if (bridgedTokenAddress !== ethers.constants.AddressZero) {
return true;
}
} catch (error) {
console.error(error);
throw new Error(
'encountered an issue when checking if token is deployed cross-chain',
{
cause: error,
},
);
return bridgedTokenAddress !== ethers.constants.AddressZero;
}
} catch (error) {
console.error(error);
throw new Error(
'encountered an issue when checking if token is deployed cross-chain',
{
cause: error,
},
);
}
}
return false;
Expand Down