Skip to content

Commit

Permalink
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
Browse files Browse the repository at this point in the history
…e into eth-custom-dest-4
  • Loading branch information
brtkx committed Nov 6, 2024
2 parents 9735b22 + 48ec162 commit c11f665
Show file tree
Hide file tree
Showing 20 changed files with 248 additions and 62 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
secrets: inherit

test-e2e:
name: "${{ matrix.test.name }}${{ matrix.test.type == 'orbit-eth' && ' with L3' || matrix.test.type == 'orbit-custom' && ' with custom fee token' || ''}}"
name: "Test E2E - ${{ matrix.test.name }} ${{ matrix.test.typeName }}"
needs: [build, load-e2e-files]
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -100,16 +100,25 @@ jobs:
nitro-testnode-ref: badbcbea9b43d46e115da4d7c9f2f57c31af8431
l3-node: ${{ matrix.test.type != 'regular' }}
no-l3-token-bridge: ${{ matrix.test.type == 'regular' }}
args: ${{ matrix.test.type == 'orbit-custom' && '--l3-fee-token' || '' }}
args: >-
${{
(matrix.test.type == 'orbit-eth') && '--l3node --l3-token-bridge' ||
(matrix.test.type == 'orbit-custom-6dec' && '--l3-fee-token --l3-fee-token-decimals 6') ||
(matrix.test.type == 'orbit-custom-18dec' && '--l3-fee-token') ||
(matrix.test.type == 'orbit-custom-20dec' && '--l3-fee-token --l3-fee-token-decimals 20') ||
''
}}
- name: Run e2e tests via cypress-io/github-action
uses: cypress-io/github-action@0da3c06ed8217b912deea9d8ee69630baed1737e # [email protected]
with:
start: yarn start
command: >-
${{
${{
(matrix.test.type == 'orbit-eth') && 'yarn test:e2e:orbit --browser chrome' ||
(matrix.test.type == 'orbit-custom' && 'yarn test:e2e:orbit:custom-gas-token --browser chrome') ||
(matrix.test.type == 'orbit-custom-6dec' && 'yarn test:e2e:orbit:custom-gas-token --browser chrome') ||
(matrix.test.type == 'orbit-custom-18dec' && 'yarn test:e2e:orbit:custom-gas-token --browser chrome') ||
(matrix.test.type == 'orbit-custom-20dec' && 'yarn test:e2e:orbit:custom-gas-token --browser chrome') ||
(matrix.test.type == 'cctp' && 'yarn test:e2e:cctp --browser chrome') ||
'yarn test:e2e --browser chrome'
}}
Expand All @@ -134,7 +143,7 @@ jobs:
uses: actions/upload-artifact@v4
if: always()
with:
name: e2e-artifacts-${{ github.sha }}-${{ matrix.test.name }}-${{ (matrix.test.type == 'cctp' && 'cctp') || (matrix.test.type == 'orbit-eth' && 'l3') || (matrix.test.type == 'orbit-custom' && 'custom-fee-token') || 'regular'}}
name: e2e-artifacts-${{ github.sha }}-${{ matrix.test.name }}-${{ matrix.test.type }}
path: |
./packages/arb-token-bridge-ui/cypress/videos
./packages/arb-token-bridge-ui/cypress/screenshots
Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/formatSpecfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,27 @@ switch (testType) {
tests.push({
...spec,
type: "regular",
typeName: "",
});
tests.push({
...spec,
type: "orbit-eth",
typeName: "with L3 (ETH)",
});
tests.push({
...spec,
type: "orbit-custom",
type: "orbit-custom-6dec",
typeName: "with L3 (6 decimals custom)",
});
tests.push({
...spec,
type: "orbit-custom-18dec",
typeName: "with L3 (18 decimals custom)",
});
tests.push({
...spec,
type: "orbit-custom-20dec",
typeName: "with L3 (20 decimals custom)",
});
});
break;
Expand All @@ -27,6 +40,7 @@ switch (testType) {
// Running CCTP tests in parallel cause nonce issues, we're running the two tests sequentially
tests.push({
name: "cctp",
typeName: "",
file: "tests/e2e/specs/**/*Cctp.cy.{js,jsx,ts,tsx}",
recordVideo: false,
type: "cctp",
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-token-bridge-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"dependencies": {
"@apollo/client": "^3.7.11",
"@arbitrum/sdk": "^4.0.1",
"@arbitrum/sdk": "^4.0.2",
"@ethersproject/providers": "^5.7.0",
"@headlessui/react": "^1.7.8",
"@headlessui/tailwindcss": "^0.1.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/arb-token-bridge-ui/public/images/XaiLogo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { useNetworks } from '../../hooks/useNetworks'
import { useNetworksRelationship } from '../../hooks/useNetworksRelationship'
import { TokenLogoFallback } from './TokenInfo'
import { useBalanceOnSourceChain } from '../../hooks/useBalanceOnSourceChain'
import { useSourceChainNativeCurrencyDecimals } from '../../hooks/useSourceChainNativeCurrencyDecimals'

function tokenListIdsToNames(ids: number[]): string {
return ids
Expand Down Expand Up @@ -244,6 +245,8 @@ function TokenBalance({ token }: { token: ERC20BridgeToken | null }) {
} = useAppState()
const { isLoading: isLoadingAccountType } = useAccountType()
const { balance, symbol } = useTokenInfo(token)
const nativeCurrencyDecimalsOnSourceChain =
useSourceChainNativeCurrencyDecimals()

const isArbitrumNativeUSDC =
isTokenArbitrumOneNativeUSDC(token?.address) ||
Expand All @@ -266,6 +269,13 @@ function TokenBalance({ token }: { token: ERC20BridgeToken | null }) {
return typeof bridgeTokens[token.address] !== 'undefined'
}, [bridgeTokens, isArbitrumNativeUSDC, token])

const decimals = useMemo(() => {
if (token) {
return token.decimals
}
return nativeCurrencyDecimalsOnSourceChain
}, [nativeCurrencyDecimalsOnSourceChain, token])

if (!tokenIsAddedToTheBridge) {
return <span className="arb-hover text-sm">Import</span>
}
Expand All @@ -279,7 +289,7 @@ function TokenBalance({ token }: { token: ERC20BridgeToken | null }) {
<span className="flex items-center whitespace-nowrap text-sm text-white/70">
{balance ? (
formatAmount(balance, {
decimals: token?.decimals,
decimals,
symbol
})
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useLatest } from 'react-use'
import { useAccount, useNetwork, useSigner } from 'wagmi'
import { TransactionResponse } from '@ethersproject/providers'
import { twMerge } from 'tailwind-merge'
import { scaleFrom18DecimalsToNativeTokenDecimals } from '@arbitrum/sdk'

import { useAppState } from '../../state'
import { getNetworkName, isNetwork } from '../../util/networks'
Expand Down Expand Up @@ -80,6 +81,7 @@ import { useIsTransferAllowed } from './hooks/useIsTransferAllowed'
import { MoveFundsButton } from './MoveFundsButton'
import { ProjectsListing } from '../common/ProjectsListing'
import { useAmountBigNumber } from './hooks/useAmountBigNumber'
import { useSourceChainNativeCurrencyDecimals } from '../../hooks/useSourceChainNativeCurrencyDecimals'

const signerUndefinedError = 'Signer is undefined'
const transferNotAllowedError = 'Transfer not allowed'
Expand Down Expand Up @@ -134,6 +136,8 @@ export function TransferPanel() {
}
} = useLatest(useNetworksRelationship(latestNetworks.current))
const isBatchTransferSupported = useIsBatchTransferSupported()
const nativeCurrencyDecimalsOnSourceChain =
useSourceChainNativeCurrencyDecimals()

const nativeCurrency = useNativeCurrency({ provider: childChainProvider })

Expand Down Expand Up @@ -620,7 +624,7 @@ export function TransferPanel() {
amount: amountBigNumber,
options: {
approvalAmountIncrease: isCustomNativeTokenAmount2
? utils.parseUnits(amount2, nativeCurrency.decimals)
? utils.parseUnits(amount2, nativeCurrencyDecimalsOnSourceChain)
: undefined
}
})
Expand All @@ -635,7 +639,7 @@ export function TransferPanel() {
amount: amountBigNumber,
options: {
approvalAmountIncrease: isCustomNativeTokenAmount2
? utils.parseUnits(amount2, nativeCurrency.decimals)
? utils.parseUnits(amount2, nativeCurrencyDecimalsOnSourceChain)
: undefined
}
})
Expand Down Expand Up @@ -748,6 +752,7 @@ export function TransferPanel() {
}

overrides.maxSubmissionCost = utils
// we are not scaling these to native decimals because arbitrum-sdk does it for us
.parseEther(amount2)
.add(gasEstimates.estimatedChildChainSubmissionCost)
overrides.excessFeeRefundAddress = destinationAddress
Expand Down Expand Up @@ -802,6 +807,20 @@ export function TransferPanel() {

const timestampCreated = String(normalizeTimestamp(Date.now()))

const { isOrbitChain: isSourceOrbitChain } = isNetwork(
latestNetworks.current.sourceChain.id
)

// only scale for native tokens, and
// only scale if sent from Orbit, because it's always 18 decimals there but the UI needs scaled amount
const scaledAmount = scaleFrom18DecimalsToNativeTokenDecimals({
amount: amountBigNumber,
decimals: nativeCurrency.decimals
})

const isNativeTokenWithdrawalFromOrbit =
!selectedToken && isSourceOrbitChain

const txHistoryCompatibleObject = convertBridgeSdkToMergedTransaction({
bridgeTransfer,
parentChainId: parentChain.id,
Expand All @@ -810,7 +829,7 @@ export function TransferPanel() {
walletAddress,
destinationAddress,
nativeCurrency,
amount: amountBigNumber,
amount: isNativeTokenWithdrawalFromOrbit ? scaledAmount : amountBigNumber,
amount2: isBatchTransfer ? utils.parseEther(amount2) : undefined,
timestampCreated
})
Expand All @@ -829,7 +848,9 @@ export function TransferPanel() {
walletAddress,
destinationAddress,
nativeCurrency,
amount: amountBigNumber,
amount: isNativeTokenWithdrawalFromOrbit
? scaledAmount
: amountBigNumber,
amount2: isBatchTransfer ? utils.parseEther(amount2) : undefined,
timestampCreated
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { Button } from '../../common/Button'
import { useSelectedTokenDecimals } from '../../../hooks/TransferPanel/useSelectedTokenDecimals'
import { useNativeCurrencyBalances } from './useNativeCurrencyBalances'
import { useIsCctpTransfer } from '../hooks/useIsCctpTransfer'
import { useSourceChainNativeCurrencyDecimals } from '../../../hooks/useSourceChainNativeCurrencyDecimals'

function Amount2ToggleButton({
onClick
Expand Down Expand Up @@ -92,6 +93,8 @@ export function SourceNetworkBox() {
const decimals = useSelectedTokenDecimals()
const { errorMessages } = useTransferReadiness()
const nativeCurrencyBalances = useNativeCurrencyBalances()
const nativeCurrencyDecimalsOnSourceChain =
useSourceChainNativeCurrencyDecimals()

const isCctpTransfer = useIsCctpTransfer()

Expand Down Expand Up @@ -145,10 +148,19 @@ export function SourceNetworkBox() {
symbol: nativeCurrency.symbol,
disabled: true,
balance: nativeCurrencyBalances.sourceBalance
? Number(utils.formatEther(nativeCurrencyBalances.sourceBalance))
? Number(
utils.formatUnits(
nativeCurrencyBalances.sourceBalance,
nativeCurrencyDecimalsOnSourceChain
)
)
: undefined
}),
[nativeCurrencyBalances, nativeCurrency.symbol]
[
nativeCurrencyBalances,
nativeCurrency.symbol,
nativeCurrencyDecimalsOnSourceChain
]
)

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { useMemo } from 'react'
import { BigNumber } from 'ethers'

import { ERC20BridgeToken } from '../../../hooks/arbTokenBridge.types'
import { NativeCurrencyErc20 } from '../../../hooks/useNativeCurrency'
import {
NativeCurrencyErc20,
useNativeCurrency
} from '../../../hooks/useNativeCurrency'
import { Loader } from '../../common/atoms/Loader'
import { TokenSymbolWithExplorerLink } from '../../common/TokenSymbolWithExplorerLink'
import { formatAmount } from '../../../util/NumberUtils'

import { NetworkType } from './utils'
import { useNetworks } from '../../../hooks/useNetworks'
import { useNetworksRelationship } from '../../../hooks/useNetworksRelationship'

export function TokenBalance({
forToken,
Expand All @@ -22,6 +28,23 @@ export function TokenBalance({
tokenSymbolOverride?: string
}) {
const isParentChain = on === NetworkType.parentChain
const [networks] = useNetworks()
const { childChainProvider } = useNetworksRelationship(networks)
const nativeCurrency = useNativeCurrency({
provider: childChainProvider
})

const isCustomNativeCurrency =
nativeCurrency.isCustom &&
forToken?.address.toLowerCase() === nativeCurrency.address.toLowerCase()

const decimals = useMemo(() => {
if (!isParentChain && isCustomNativeCurrency) {
// Native currency on Orbit chain, always 18 decimals
return 18
}
return forToken?.decimals
}, [forToken?.decimals, isCustomNativeCurrency, isParentChain])

if (!forToken) {
return null
Expand All @@ -43,7 +66,7 @@ export function TokenBalance({
<span className="font-light">{prefix}</span>
<span aria-label={`${tokenSymbol} balance amount on ${on}`}>
{formatAmount(balance, {
decimals: forToken.decimals
decimals
})}
</span>{' '}
<TokenSymbolWithExplorerLink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { defaultErc20Decimals } from '../../../defaults'
import { useGasSummary } from '../../../hooks/TransferPanel/useGasSummary'
import { useNativeCurrency } from '../../../hooks/useNativeCurrency'
import { useNativeCurrencyBalances } from './useNativeCurrencyBalances'
import { useSourceChainNativeCurrencyDecimals } from '../../../hooks/useSourceChainNativeCurrencyDecimals'

export function useMaxAmount() {
const {
Expand All @@ -19,6 +20,8 @@ export function useMaxAmount() {
const { childChainProvider, isDepositMode } =
useNetworksRelationship(networks)
const nativeCurrency = useNativeCurrency({ provider: childChainProvider })
const nativeCurrencyDecimalsOnSourceChain =
useSourceChainNativeCurrencyDecimals()

const { estimatedParentChainGasFees, estimatedChildChainGasFees } =
useGasSummary()
Expand All @@ -36,14 +39,14 @@ export function useMaxAmount() {
if (nativeCurrency.isCustom && isDepositMode) {
return utils.formatUnits(
nativeCurrencySourceBalance,
nativeCurrency.decimals
nativeCurrencyDecimalsOnSourceChain
)
}

// ETH deposits and ETH/custom fee token withdrawals
const nativeCurrencyBalanceFormatted = utils.formatUnits(
nativeCurrencySourceBalance,
nativeCurrency.decimals
nativeCurrencyDecimalsOnSourceChain
)

if (
Expand All @@ -70,9 +73,9 @@ export function useMaxAmount() {
estimatedChildChainGasFees,
estimatedParentChainGasFees,
isDepositMode,
nativeCurrency.decimals,
nativeCurrency.isCustom,
nativeCurrencyBalances.sourceBalance
nativeCurrencyBalances.sourceBalance,
nativeCurrencyDecimalsOnSourceChain
])

const maxAmount = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Loader } from '../common/atoms/Loader'
import { sanitizeAmountQueryParam } from '../../hooks/useArbQueryParams'
import { truncateExtraDecimals } from '../../util/NumberUtils'
import { useNativeCurrencyBalances } from './TransferPanelMain/useNativeCurrencyBalances'
import { useSelectedTokenDecimals } from '../../hooks/TransferPanel/useSelectedTokenDecimals'

function MaxButton({
className = '',
Expand Down Expand Up @@ -86,6 +87,7 @@ function SourceChainTokenBalance({
const [networks] = useNetworks()
const { isDepositMode, childChainProvider } =
useNetworksRelationship(networks)
const selectedTokenDecimals = useSelectedTokenDecimals()

const nativeCurrencyBalances = useNativeCurrencyBalances()
const selectedTokenBalances = useSelectedTokenBalances()
Expand All @@ -103,7 +105,7 @@ function SourceChainTokenBalance({
const formattedBalance =
balance !== null
? formatAmount(balance, {
decimals: selectedToken?.decimals ?? nativeCurrency.decimals
decimals: selectedTokenDecimals
})
: null

Expand Down
Loading

0 comments on commit c11f665

Please sign in to comment.