Skip to content

Commit

Permalink
Merge branch 'dl/fs-905' of github.com:OffchainLabs/arbitrum-token-br…
Browse files Browse the repository at this point in the history
…idge into dl/fs-905
  • Loading branch information
douglance committed Oct 18, 2024
2 parents b9a81eb + eda964b commit 87353c4
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/add-orbit-chain-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ body:
- "421614"
- "11155111"
- "17000"
- "8453"
- "84532"
validations:
required: true

Expand Down
10 changes: 9 additions & 1 deletion audit-ci.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"$schema": "https://github.com/IBM/audit-ci/raw/main/docs/schema.json",
"low": true,
"allowlist": []
"allowlist": [
// https://github.com/advisories/GHSA-fc9h-whq2-v747
// Valid ECDSA signatures erroneously rejected in Elliptic
// Legitimate transactions or communications may be incorrectly flagged as invalid.
// No patched version available yet
// from: arb-token-bridge-ui>@unstoppabledomains/resolution>elliptic
// from: arb-token-bridge-ui>ethers>@ethersproject/signing-key>elliptic
"GHSA-fc9h-whq2-v747"
]
}
24 changes: 9 additions & 15 deletions packages/arb-token-bridge-ui/src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { BalanceUpdater } from '../syncers/BalanceUpdater'
import { TokenListSyncer } from '../syncers/TokenListSyncer'
import { Header } from '../common/Header'
import { HeaderAccountPopover } from '../common/HeaderAccountPopover'
import { getNetworkName, isNetwork } from '../../util/networks'
import { getNetworkName } from '../../util/networks'
import {
ArbQueryParamProvider,
useArbQueryParams
Expand All @@ -41,6 +41,7 @@ import { HeaderConnectWalletButton } from '../common/HeaderConnectWalletButton'
import { onDisconnectHandler } from '../../util/walletConnectUtils'
import { addressIsSmartContract } from '../../util/AddressUtils'
import { useSyncConnectedChainToAnalytics } from './useSyncConnectedChainToAnalytics'
import { isDepositMode } from '../../util/isDepositMode'

declare global {
interface Window {
Expand Down Expand Up @@ -98,30 +99,23 @@ const ArbTokenBridgeStoreSyncWrapper = (): JSX.Element | null => {
// Any time one of those changes
setTokenBridgeParams(null)
actions.app.setConnectionState(ConnectionState.LOADING)

const {
isArbitrum: isConnectedToArbitrum,
isOrbitChain: isConnectedToOrbitChain
} = isNetwork(networks.sourceChain.id)
const isParentChainEthereum = isNetwork(
parentChain.id
).isEthereumMainnetOrTestnet

actions.app.reset(networks.sourceChain.id)
actions.app.setChainIds({
l1NetworkChainId: parentChain.id,
l2NetworkChainId: childChain.id
})

if (
(isParentChainEthereum && isConnectedToArbitrum) ||
isConnectedToOrbitChain
isDepositMode({
sourceChainId: networks.sourceChain.id,
destinationChainId: networks.destinationChain.id
})
) {
console.info('Withdrawal mode detected:')
actions.app.setConnectionState(ConnectionState.L2_CONNECTED)
} else {
console.info('Deposit mode detected:')
actions.app.setConnectionState(ConnectionState.L1_CONNECTED)
} else {
console.info('Withdrawal mode detected:')
actions.app.setConnectionState(ConnectionState.L2_CONNECTED)
}

setTokenBridgeParams({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ describe('sanitizeQueryParams', () => {
})
})
})
describe('when `destinationChainId` is valid but has no paired source chains and `sourceChainId` is undefined', () => {
it('should set `sourceChainId` to Ethereum and `destinationChainId` to Arbitrum One', () => {
const result = sanitizeQueryParams({
sourceChainId: undefined,
destinationChainId: ChainId.Holesky
})
expect(result).toEqual({
sourceChainId: ChainId.Ethereum,
destinationChainId: ChainId.ArbitrumOne
})
})
})

describe('when `destinationChainId` is invalid and `sourceChainId` is valid', () => {
it('should set `destinationChainId` based on `sourceChainId`', () => {
Expand Down Expand Up @@ -207,4 +219,16 @@ describe('sanitizeQueryParams', () => {
})
})
})
describe('when `destinationChainId` is undefined and `sourceChainId` is valid but has no paired destination chains', () => {
it('should set `sourceChainId` to Ethereum and `destinationChainId` to Arbitrum One', () => {
const result = sanitizeQueryParams({
sourceChainId: ChainId.Holesky,
destinationChainId: undefined
})
expect(result).toEqual({
sourceChainId: ChainId.Ethereum,
destinationChainId: ChainId.ArbitrumOne
})
})
})
})
20 changes: 18 additions & 2 deletions packages/arb-token-bridge-ui/src/hooks/useNetworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ export function sanitizeQueryParams({
isSupportedChainId(destinationChainId)
) {
const [defaultSourceChainId] = getDestinationChainIds(destinationChainId)
return { sourceChainId: defaultSourceChainId!, destinationChainId }

if (typeof defaultSourceChainId === 'undefined') {
return {
sourceChainId: ChainId.Ethereum,
destinationChainId: ChainId.ArbitrumOne
}
}

return { sourceChainId: defaultSourceChainId, destinationChainId }
}

// sourceChainId is valid and destinationChainId is undefined
Expand All @@ -83,9 +91,17 @@ export function sanitizeQueryParams({
!isSupportedChainId(destinationChainId)
) {
const [defaultDestinationChainId] = getDestinationChainIds(sourceChainId)

if (typeof defaultDestinationChainId === 'undefined') {
return {
sourceChainId: ChainId.Ethereum,
destinationChainId: ChainId.ArbitrumOne
}
}

return {
sourceChainId: sourceChainId,
destinationChainId: defaultDestinationChainId!
destinationChainId: defaultDestinationChainId
}
}

Expand Down
7 changes: 7 additions & 0 deletions packages/arb-token-bridge-ui/src/types/ChainQueryParam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { chainToWagmiChain } from '../util/wagmi/wagmiAdditionalNetworks'
const chainQueryParams = [
'ethereum',
'sepolia',
'holesky',
'arbitrum-one',
'arbitrum-nova',
'arbitrum-sepolia',
Expand Down Expand Up @@ -50,6 +51,9 @@ export function getChainQueryParamForChain(chainId: ChainId): ChainQueryParam {
case ChainId.ArbitrumNova:
return 'arbitrum-nova'

case ChainId.Holesky:
return 'holesky'

case ChainId.Sepolia:
return 'sepolia'

Expand Down Expand Up @@ -94,6 +98,9 @@ export function getChainForChainKeyQueryParam(
case 'sepolia':
return chains.sepolia

case 'holesky':
return customChains.holesky

case 'arbitrum-one':
return chains.arbitrum

Expand Down
16 changes: 15 additions & 1 deletion packages/scripts/src/addOrbitChain/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from "zod";
import { constants, ethers } from "ethers";
import { getOctokit } from "@actions/github";

export const TESTNET_PARENT_CHAIN_IDS = [11155111, 421614, 17000];
export const TESTNET_PARENT_CHAIN_IDS = [11155111, 421614, 17000, 84532];
const ZERO_ADDRESS = constants.AddressZero;

export const isValidAddress = (address: string): boolean => {
Expand Down Expand Up @@ -128,6 +128,20 @@ export const chainSchema = z
chainId: 17000,
name: "Holesky",
};
case 8453: // Base
return {
rpcUrl: "https://mainnet.base.org",
blockExplorer: "https://basescan.io",
chainId: 8453,
name: "Base",
};
case 84532: // Base Sepolia
return {
rpcUrl: "https://sepolia.base.org",
blockExplorer: "https://sepolia.basescan.io",
chainId: 84532,
name: "Base Sepolia",
};
default:
throw new Error(`Unsupported parent chain ID: ${parentChainId}`);
}
Expand Down

0 comments on commit 87353c4

Please sign in to comment.