Skip to content

Commit

Permalink
refactor: upgrade to @arbitrum/sdk v4 (#1640)
Browse files Browse the repository at this point in the history
Co-authored-by: spsjvc <[email protected]>
  • Loading branch information
brtkx and spsjvc authored Jul 16, 2024
1 parent 378e160 commit b70b2c6
Show file tree
Hide file tree
Showing 48 changed files with 717 additions and 809 deletions.
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": "^3.7.0",
"@arbitrum/sdk": "^4.0.0-alpha.9",
"@ethersproject/providers": "^5.7.0",
"@headlessui/react": "^1.7.8",
"@headlessui/tailwindcss": "^0.1.2",
Expand Down
17 changes: 8 additions & 9 deletions packages/arb-token-bridge-ui/scripts/generateDenylist.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import axios from 'axios'
import { TokenList } from '@uniswap/token-lists'
import { l2Networks } from '@arbitrum/sdk/dist/lib/dataEntities/networks'
import { getArbitrumNetworks } from '@arbitrum/sdk'

const tokenListsUrls = [
'https://tokenlist.arbitrum.io/ArbTokenLists/arbitrum_token_token_list.json',
Expand Down Expand Up @@ -123,21 +123,20 @@ async function main() {
...allTokenAddresses
]

Object.keys(l2Networks).map(chainId => {
const networkObject = l2Networks[chainId]

const { ethBridge, tokenBridge } = networkObject
getArbitrumNetworks().map(arbitrumNetwork => {
const { ethBridge, tokenBridge } = arbitrumNetwork
const { classicOutboxes } = ethBridge

if (classicOutboxes) {
denylistedAddresses.push(...Object.keys(classicOutboxes))
}

delete ethBridge.classicOutboxes
denylistedAddresses.push(
...Object.values(ethBridge),
...Object.values(tokenBridge)
)
denylistedAddresses.push(...Object.values(ethBridge))

if (tokenBridge) {
denylistedAddresses.push(...Object.values(tokenBridge))
}
})

const resultJson =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ import {
StaticJsonRpcProvider,
TransactionReceipt
} from '@ethersproject/providers'
import { L1ToL2MessageStatus } from '@arbitrum/sdk'
import {
EthDepositMessage,
EthDepositStatus,
L1ToL2MessageReader
} from '@arbitrum/sdk/dist/lib/message/L1ToL2Message'
EthDepositMessageStatus,
ParentToChildMessageStatus,
ParentToChildMessageReader
} from '@arbitrum/sdk'

import {
DepositStatus,
MergedTransaction,
WithdrawalStatus
} from '../../state/app/state'
import { ChainId, getBlockTime, isNetwork, rpcURLs } from '../../util/networks'
import {
ChainId,
getL1BlockTime,
isNetwork,
rpcURLs
} from '../../util/networks'
import { Deposit, Transfer } from '../../hooks/useTransactionHistory'
import { getWagmiChain } from '../../util/wagmi/getWagmiChain'
import {
Expand Down Expand Up @@ -286,7 +291,7 @@ export async function getUpdatedEthDeposit(
}

const status = await l1ToL2Msg?.status()
const isDeposited = status === EthDepositStatus.DEPOSITED
const isDeposited = status === EthDepositMessageStatus.DEPOSITED

const newDeposit: MergedTransaction = {
...tx,
Expand All @@ -295,12 +300,12 @@ export async function getUpdatedEthDeposit(
l1ToL2MsgData: {
fetchingUpdate: false,
status: isDeposited
? L1ToL2MessageStatus.FUNDS_DEPOSITED_ON_L2
: L1ToL2MessageStatus.NOT_YET_CREATED,
retryableCreationTxID: (l1ToL2Msg as EthDepositMessage).l2DepositTxHash,
? ParentToChildMessageStatus.FUNDS_DEPOSITED_ON_CHILD
: ParentToChildMessageStatus.NOT_YET_CREATED,
retryableCreationTxID: (l1ToL2Msg as EthDepositMessage).childTxHash,
// Only show `l2TxID` after the deposit is confirmed
l2TxID: isDeposited
? (l1ToL2Msg as EthDepositMessage).l2DepositTxHash
? (l1ToL2Msg as EthDepositMessage).childTxHash
: undefined
}
}
Expand Down Expand Up @@ -329,7 +334,7 @@ export async function getUpdatedTokenDeposit(
l1Provider: getProvider(tx.parentChainId),
l2Provider: getProvider(tx.childChainId)
})
const _l1ToL2Msg = l1ToL2Msg as L1ToL2MessageReader
const _l1ToL2Msg = l1ToL2Msg as ParentToChildMessageReader

if (!l1ToL2Msg) {
const receipt = await getTxReceipt(tx)
Expand All @@ -346,8 +351,8 @@ export async function getUpdatedTokenDeposit(
const res = await _l1ToL2Msg.getSuccessfulRedeem()

const l2TxID = (() => {
if (res.status === L1ToL2MessageStatus.REDEEMED) {
return res.l2TxReceipt.transactionHash
if (res.status === ParentToChildMessageStatus.REDEEMED) {
return res.childTxReceipt.transactionHash
} else {
return undefined
}
Expand All @@ -357,7 +362,9 @@ export async function getUpdatedTokenDeposit(
...tx,
status: _l1ToL2Msg.retryableCreationId ? 'success' : tx.status,
resolvedAt:
res.status === L1ToL2MessageStatus.REDEEMED ? dayjs().valueOf() : null,
res.status === ParentToChildMessageStatus.REDEEMED
? dayjs().valueOf()
: null,
l1ToL2MsgData: {
status: res.status,
l2TxID,
Expand Down Expand Up @@ -411,7 +418,7 @@ export async function getUpdatedCctpTransfer(
const requiredL1BlocksBeforeConfirmation = getBlockBeforeConfirmation(
tx.parentChainId
)
const blockTime = getBlockTime(tx.parentChainId)
const blockTime = getL1BlockTime(tx.parentChainId)

const txWithTxId: MergedTransaction = { ...tx, txId: receipt.transactionHash }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { useState } from 'react'
import { isAddress } from 'ethers/lib/utils.js'
import { Popover } from '@headlessui/react'
import {
addCustomNetwork,
constants as arbitrumSdkConstants
} from '@arbitrum/sdk'
import { registerCustomArbitrumNetwork } from '@arbitrum/sdk'
import { StaticJsonRpcProvider } from '@ethersproject/providers'
import { EllipsisHorizontalIcon, XMarkIcon } from '@heroicons/react/24/outline'
import { constants } from 'ethers'
Expand Down Expand Up @@ -181,7 +178,7 @@ async function mapOrbitConfigToOrbitChain(
const confirmPeriodBlocks =
(await rollup.confirmPeriodBlocks()).toNumber() ?? 150
return {
chainID: data.chainInfo.chainId,
chainId: data.chainInfo.chainId,
confirmPeriodBlocks,
ethBridge: {
bridge: data.coreContracts.bridge,
Expand All @@ -194,30 +191,24 @@ async function mapOrbitConfigToOrbitChain(
explorerUrl: data.chainInfo.explorerUrl,
isCustom: true,
name: data.chainInfo.chainName,
partnerChainID: data.chainInfo.parentChainId,
partnerChainIDs: [],
parentChainId: data.chainInfo.parentChainId,
retryableLifetimeSeconds: 604800,
nitroGenesisBlock: 0,
nitroGenesisL1Block: 0,
depositTimeout: 900000,
blockTime: arbitrumSdkConstants.ARB_MINIMUM_BLOCK_TIME_IN_SECONDS,
nativeToken: data.chainInfo.nativeToken,
isArbitrum: true,
tokenBridge: {
l1CustomGateway: data.tokenBridgeContracts.l2Contracts.customGateway,
l1ERC20Gateway: data.tokenBridgeContracts.l2Contracts.standardGateway,
l1GatewayRouter: data.tokenBridgeContracts.l2Contracts.router,
l1MultiCall: data.tokenBridgeContracts.l2Contracts.multicall,
l1ProxyAdmin: data.tokenBridgeContracts.l2Contracts.proxyAdmin,
l1Weth: data.tokenBridgeContracts.l2Contracts.weth,
l1WethGateway: data.tokenBridgeContracts.l2Contracts.wethGateway,
l2CustomGateway: data.tokenBridgeContracts.l3Contracts.customGateway,
l2ERC20Gateway: data.tokenBridgeContracts.l3Contracts.standardGateway,
l2GatewayRouter: data.tokenBridgeContracts.l3Contracts.router,
l2Multicall: data.tokenBridgeContracts.l3Contracts.multicall,
l2ProxyAdmin: data.tokenBridgeContracts.l3Contracts.proxyAdmin,
l2Weth: data.tokenBridgeContracts.l3Contracts.weth,
l2WethGateway: data.tokenBridgeContracts.l3Contracts.wethGateway
parentCustomGateway: data.tokenBridgeContracts.l2Contracts.customGateway,
parentErc20Gateway: data.tokenBridgeContracts.l2Contracts.standardGateway,
parentGatewayRouter: data.tokenBridgeContracts.l2Contracts.router,
parentMultiCall: data.tokenBridgeContracts.l2Contracts.multicall,
parentProxyAdmin: data.tokenBridgeContracts.l2Contracts.proxyAdmin,
parentWeth: data.tokenBridgeContracts.l2Contracts.weth,
parentWethGateway: data.tokenBridgeContracts.l2Contracts.wethGateway,
childCustomGateway: data.tokenBridgeContracts.l3Contracts.customGateway,
childErc20Gateway: data.tokenBridgeContracts.l3Contracts.standardGateway,
childGatewayRouter: data.tokenBridgeContracts.l3Contracts.router,
childMultiCall: data.tokenBridgeContracts.l3Contracts.multicall,
childProxyAdmin: data.tokenBridgeContracts.l3Contracts.proxyAdmin,
childWeth: data.tokenBridgeContracts.l3Contracts.weth,
childWethGateway: data.tokenBridgeContracts.l3Contracts.wethGateway
}
}
}
Expand Down Expand Up @@ -271,7 +262,7 @@ export const AddCustomChain = () => {
const nativeToken = await fetchNativeToken(data)
// Orbit config has been validated and will be added to the custom list after page refreshes
// let's still try to add it here to handle eventual errors
addCustomNetwork({ customL2Network: customChain })
registerCustomArbitrumNetwork(customChain)
saveCustomChainToLocalStorage({ ...customChain, ...nativeToken })
saveOrbitConfigToLocalStorage(data)
// reload to apply changes
Expand Down Expand Up @@ -333,20 +324,20 @@ export const AddCustomChain = () => {
<tbody>
{customChains.map(customChain => (
<tr
key={customChain.chainID}
key={customChain.chainId}
className="border-b border-gray-dark"
>
<th className="max-w-[100px] truncate py-3 text-sm font-normal">
{customChain.name}
</th>
<th className="py-3 text-sm font-normal">
{customChain.chainID}
{customChain.chainId}
</th>
<th className="py-3 text-sm font-normal">
{getNetworkName(customChain.partnerChainID)}
{getNetworkName(customChain.parentChainId)}
</th>
<th className="py-3 text-sm font-normal">
{customChain.partnerChainID}
{customChain.parentChainId}
</th>
<th className="py-3">
<Popover className="relative">
Expand All @@ -359,10 +350,10 @@ export const AddCustomChain = () => {
className="rounded-t p-4 text-left transition duration-300 hover:bg-[#333333]"
onClick={() => {
removeCustomChainFromLocalStorage(
customChain.chainID
customChain.chainId
)
removeOrbitConfigFromLocalStorage(
customChain.chainID
customChain.chainId
)
// reload to apply changes
location.reload()
Expand All @@ -375,7 +366,7 @@ export const AddCustomChain = () => {
href={`data:text/json;charset=utf-8,${encodeURIComponent(
JSON.stringify(
getOrbitConfigFromLocalStorageById(
customChain.chainID
customChain.chainId
)
)
)}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dayjs, { Dayjs } from 'dayjs'

import {
getBaseChainIdByChainId,
getBlockTime,
getL1BlockTime,
getConfirmPeriodBlocks
} from '../../util/networks'
import { MergedTransaction } from '../../state/app/state'
Expand All @@ -28,7 +28,8 @@ export function getTxConfirmationDate({
// the block time is always base chain's block time regardless of withdrawing from L3 to L2 or from L2 to L1
// and similarly, the confirm period blocks is always the number of blocks on the base chain
const confirmationSeconds =
getBlockTime(baseChainId) * getConfirmPeriodBlocks(withdrawalFromChainId) +
getL1BlockTime(baseChainId) *
getConfirmPeriodBlocks(withdrawalFromChainId) +
CONFIRMATION_BUFFER_MINUTES * SECONDS_IN_MIN
return createdAt.add(confirmationSeconds, 'second')
}
Expand Down
30 changes: 3 additions & 27 deletions packages/arb-token-bridge-ui/src/hooks/__tests__/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { constants } from '@arbitrum/sdk'

import { ChainWithRpcUrl } from '../../util/networks'

export function createMockOrbitChain({
Expand All @@ -10,7 +8,7 @@ export function createMockOrbitChain({
parentChainId: number
}): ChainWithRpcUrl {
return {
chainID: chainId,
chainId: chainId,
confirmPeriodBlocks: 45818,
ethBridge: {
bridge: '',
Expand All @@ -22,32 +20,10 @@ export function createMockOrbitChain({
nativeToken: '',
explorerUrl: '',
rpcUrl: '',
isArbitrum: true,
isCustom: true,
name: `Mocked Orbit Chain ${chainId}`,
slug: `mocked-orbit-chain-${chainId}`,
partnerChainID: parentChainId,
partnerChainIDs: [],
retryableLifetimeSeconds: 604800,
tokenBridge: {
l1CustomGateway: '',
l1ERC20Gateway: '',
l1GatewayRouter: '',
l1MultiCall: '',
l1ProxyAdmin: '',
l1Weth: '',
l1WethGateway: '',
l2CustomGateway: '',
l2ERC20Gateway: '',
l2GatewayRouter: '',
l2Multicall: '',
l2ProxyAdmin: '',
l2Weth: '',
l2WethGateway: ''
},
nitroGenesisBlock: 0,
nitroGenesisL1Block: 0,
depositTimeout: 1800000,
blockTime: constants.ARB_MINIMUM_BLOCK_TIME_IN_SECONDS
parentChainId,
retryableLifetimeSeconds: 604800
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
*/
import { addCustomNetwork } from '@arbitrum/sdk'
import { registerCustomArbitrumNetwork } from '@arbitrum/sdk'
import { ChainId, customChainLocalStorageKey } from '../../util/networks'
import { AmountQueryParam, ChainParam } from '../useArbQueryParams'
import { createMockOrbitChain } from './helpers'
Expand Down Expand Up @@ -224,7 +224,7 @@ describe('ChainParam custom encoder and decoder', () => {
chainId: 222222,
parentChainId: 1
})
addCustomNetwork({ customL2Network: customChain })
registerCustomArbitrumNetwork(customChain)
expect(ChainParam.decode('222222')).toEqual(222222)
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
*/
import { addCustomNetwork } from '@arbitrum/sdk'
import { registerCustomArbitrumNetwork } from '@arbitrum/sdk'
import { ChainId, customChainLocalStorageKey } from '../../util/networks'
import { sanitizeQueryParams } from '../useNetworks'
import { createMockOrbitChain } from './helpers'
Expand Down Expand Up @@ -35,9 +35,9 @@ describe('sanitizeQueryParams', () => {
return null
}
)
addCustomNetwork({ customL2Network: mockedOrbitChain_1 })
addCustomNetwork({ customL2Network: mockedOrbitChain_2 })
addCustomNetwork({ customL2Network: mockedOrbitChain_3 })
registerCustomArbitrumNetwork(mockedOrbitChain_1)
registerCustomArbitrumNetwork(mockedOrbitChain_2)
registerCustomArbitrumNetwork(mockedOrbitChain_3)
})

afterAll(() => {
Expand Down
Loading

0 comments on commit b70b2c6

Please sign in to comment.