Skip to content

Commit

Permalink
Merge branch 'main' into feat-native-token
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc committed Oct 31, 2024
2 parents a99cd6a + f7d4c50 commit 72bde4f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/lib/assetBridger/assetBridger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
/* eslint-env node */
'use strict'

import { constants } from 'ethers'

import { ParentContractTransaction } from '../message/ParentTransaction'
import { ChildContractTransaction } from '../message/ChildTransaction'

import { ArbitrumNetwork } from '../dataEntities/networks'
import {
ArbitrumNetwork,
isArbitrumNetworkNativeTokenEther,
} from '../dataEntities/networks'
import {
SignerOrProvider,
SignerProviderUtils,
Expand Down Expand Up @@ -69,7 +70,7 @@ export abstract class AssetBridger<DepositParams, WithdrawParams> {
* @returns {boolean}
*/
protected get nativeTokenIsEth() {
return !this.nativeToken || this.nativeToken === constants.AddressZero
return isArbitrumNetworkNativeTokenEther(this.childNetwork)
}

/**
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 @@ -565,6 +565,15 @@ export function assertArbitrumNetworkHasTokenBridge<T extends ArbitrumNetwork>(
}
}

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

const { resetNetworksToDefault } = createNetworkStateHandler()

export { resetNetworksToDefault }
7 changes: 5 additions & 2 deletions src/lib/message/ParentToChildMessageCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
ParentTransactionReceipt,
} from './ParentTransaction'
import { Inbox__factory } from '../abi/factories/Inbox__factory'
import { getArbitrumNetwork } from '../dataEntities/networks'
import {
getArbitrumNetwork,
isArbitrumNetworkNativeTokenEther,
} from '../dataEntities/networks'
import { ERC20Inbox__factory } from '../abi/factories/ERC20Inbox__factory'
import { PayableOverrides } from '@ethersproject/contracts'
import { SignerProviderUtils } from '../dataEntities/signerOrProvider'
Expand Down Expand Up @@ -156,7 +159,7 @@ export class ParentToChildMessageCreator {
)

const childChain = await getArbitrumNetwork(childProvider)
const nativeTokenIsEth = typeof childChain.nativeToken === 'undefined'
const nativeTokenIsEth = isArbitrumNetworkNativeTokenEther(childChain)

const data = ParentToChildMessageCreator.getTicketCreationRequestCallData(
params,
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import {
getChildrenForNetwork,
isParentNetwork,
getMulticallAddress,
isArbitrumNetworkNativeTokenEther,
ArbitrumNetwork,
} from '../../src/lib/dataEntities/networks'
import { SignerOrProvider } from '../../src/lib/dataEntities/signerOrProvider'
import { constants } from 'ethers'

const ethereumMainnetChainId = 1
const arbitrumOneChainId = 42161
Expand Down Expand Up @@ -220,4 +223,30 @@ describe('Networks', async () => {
expect(network.chainId).to.equal(arbitrumOneChainId)
})
})

describe('isArbitrumNetworkNativeTokenEther', () => {
it('returns `true` when `nativeToken` is undefined', () => {
expect(
isArbitrumNetworkNativeTokenEther({
nativeToken: undefined,
} as ArbitrumNetwork)
).to.equal(true)
})

it('returns `true` when `nativeToken` is zero address', () => {
expect(
isArbitrumNetworkNativeTokenEther({
nativeToken: constants.AddressZero,
} as ArbitrumNetwork)
).to.equal(true)
})

it('returns `false` when `nativeToken` is a valid address', () => {
expect(
isArbitrumNetworkNativeTokenEther({
nativeToken: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
} as ArbitrumNetwork)
).to.equal(false)
})
})
})

0 comments on commit 72bde4f

Please sign in to comment.