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: properly check if native token is eth #541

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/lib/assetBridger/assetBridger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
/* eslint-env node */
'use strict'

import { constants } from 'ethers'

import { L1ContractTransaction } from '../message/L1Transaction'
import { L2ContractTransaction } from '../message/L2Transaction'

import {
L1Network,
L2Network,
getParentForNetwork,
isL2NetworkNativeTokenEther,
} from '../dataEntities/networks'
import {
SignerOrProvider,
Expand Down Expand Up @@ -73,7 +72,7 @@ export abstract class AssetBridger<DepositParams, WithdrawParams> {
* @returns {boolean}
*/
protected get nativeTokenIsEth() {
return !this.nativeToken || this.nativeToken === constants.AddressZero
return isL2NetworkNativeTokenEther(this.l2Network)
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/lib/dataEntities/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
/* eslint-env node */
'use strict'

import { constants } from 'ethers'

import { SignerOrProvider, SignerProviderUtils } from './signerOrProvider'
import { ArbSdkError } from '../dataEntities/errors'
import {
Expand Down Expand Up @@ -652,6 +654,13 @@ const createNetworkStateHandler = () => {
}
}

export function isL2NetworkNativeTokenEther(network: L2Network): boolean {
return (
typeof network.nativeToken === 'undefined' ||
network.nativeToken === constants.AddressZero
)
}

const { resetNetworksToDefault } = createNetworkStateHandler()

export { resetNetworksToDefault }
7 changes: 5 additions & 2 deletions src/lib/message/L1ToL2MessageCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
import { L1ContractTransaction, L1TransactionReceipt } from './L1Transaction'
import { Inbox__factory } from '../abi/factories/Inbox__factory'
import { ERC20Inbox__factory } from '../abi/factories/ERC20Inbox__factory'
import { getL2Network } from '../dataEntities/networks'
import {
getL2Network,
isL2NetworkNativeTokenEther,
} from '../dataEntities/networks'
import { PayableOverrides } from '@ethersproject/contracts'
import { SignerProviderUtils } from '../dataEntities/signerOrProvider'
import { MissingProviderArbSdkError } from '../dataEntities/errors'
Expand Down Expand Up @@ -147,7 +150,7 @@ export class L1ToL2MessageCreator {
)

const l2Network = await getL2Network(l2Provider)
const nativeTokenIsEth = typeof l2Network.nativeToken === 'undefined'
const nativeTokenIsEth = isL2NetworkNativeTokenEther(l2Network)

const data = L1ToL2MessageCreator.getTicketCreationRequestCallData(
params,
Expand Down
Loading