Commit bcdf5749 authored by Kelvin Fichter's avatar Kelvin Fichter

fix(sdk): bug in supportsTokenPair

Fixes a bug in the supportsTokenPair where unsupported token interfaces
would cause the SDK to error out. Happens because the adapters check for
things that are only present in certain types of tokens. Adds a new
error handling check that wraps all sub-calls to supportsTokenPair in
each of the adapters so that the adapters don't need to worry about
this.
parent 111f3f3a
...@@ -156,7 +156,6 @@ export class StandardBridgeAdapter implements IBridgeAdapter { ...@@ -156,7 +156,6 @@ export class StandardBridgeAdapter implements IBridgeAdapter {
l1Token: AddressLike, l1Token: AddressLike,
l2Token: AddressLike l2Token: AddressLike
): Promise<boolean> { ): Promise<boolean> {
try {
const contract = new Contract( const contract = new Contract(
toAddress(l2Token), toAddress(l2Token),
optimismMintableERC20.abi, optimismMintableERC20.abi,
...@@ -184,18 +183,6 @@ export class StandardBridgeAdapter implements IBridgeAdapter { ...@@ -184,18 +183,6 @@ export class StandardBridgeAdapter implements IBridgeAdapter {
} }
return true return true
} catch (err) {
// If the L2 token is not an L2StandardERC20, it may throw an error. If there's a call
// exception then we assume that the token is not supported. Other errors are thrown. Since
// the JSON-RPC API is not well-specified, we need to handle multiple possible error codes.
if (
!err?.message?.toString().includes('CALL_EXCEPTION') &&
!err?.stack?.toString().includes('execution reverted')
) {
console.error('Unexpected error when checking bridge', err)
}
return false
}
} }
public async approval( public async approval(
......
...@@ -490,9 +490,18 @@ export class CrossChainMessenger { ...@@ -490,9 +490,18 @@ export class CrossChainMessenger {
): Promise<IBridgeAdapter> { ): Promise<IBridgeAdapter> {
const bridges: IBridgeAdapter[] = [] const bridges: IBridgeAdapter[] = []
for (const bridge of Object.values(this.bridges)) { for (const bridge of Object.values(this.bridges)) {
try {
if (await bridge.supportsTokenPair(l1Token, l2Token)) { if (await bridge.supportsTokenPair(l1Token, l2Token)) {
bridges.push(bridge) bridges.push(bridge)
} }
} catch (err) {
if (
!err?.message?.toString().includes('CALL_EXCEPTION') &&
!err?.stack?.toString().includes('execution reverted')
) {
console.error('Unexpected error when checking bridge', err)
}
}
} }
if (bridges.length === 0) { if (bridges.length === 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment