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

merge sepolia into mainnet #1139

Merged
merged 4 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scroll.io",
"version": "5.0.108",
"version": "5.0.109",
"private": false,
"license": "MIT",
"scripts": {
Expand Down
38 changes: 16 additions & 22 deletions src/hooks/useSendTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isError } from "ethers"
import { useMemo, useState } from "react"

import { CHAIN_ID, NETWORKS, TX_STATUS } from "@/constants"
import { BATCH_BRIDGE_GATEWAY_PROXY_ADDR, CHAIN_ID, NETWORKS, SCROLL_MESSENGER_ADDR, TX_STATUS } from "@/constants"
import { useBridgeContext } from "@/contexts/BridgeContextProvider"
import { usePriceFeeContext } from "@/contexts/PriceFeeProvider"
import { useRainbowContext } from "@/contexts/RainbowProvider"
Expand All @@ -24,7 +24,7 @@ const LOWER_BOUND = 1e5

export function useSendTransaction(props) {
const { amount: fromTokenAmount, selectedToken, receiver, needApproval } = props
const { walletCurrentAddress } = useRainbowContext()
const { walletCurrentAddress, provider } = useRainbowContext()
const { networksAndSigners, blockNumbers } = useBridgeContext()
const { enlargedGasLimit: txGasLimit, maxFeePerGas, maxPriorityFeePerGas, gasLimitBatch } = useGasFee(selectedToken, needApproval)
const { addTransaction, addEstimatedTimeMap, removeFrontTransactions, updateTransaction } = useTxStore()
Expand All @@ -41,37 +41,27 @@ export function useSendTransaction(props) {
return amountToBN(fromTokenAmount, selectedToken.decimals)
}, [fromTokenAmount, selectedToken?.decimals])

const checkIsContract = async contractAddress => {
if (!provider) throw new Error("provider is not defined")
const code = await provider.getCode(contractAddress)
if (code === "0x") throw new Error("You are connected to the wrong network. Please switch to the correct network and refresh.")
}

const send = async () => {
setIsLoading(true)
let tx, chainId
let tx
const isBatchMode = bridgeSummaryType === BridgeSummaryType.Selector && depositBatchMode === DepositBatchMode.Economy
// let currentBlockNumber
try {
if (isBatchMode) {
// currentBlockNumber = await networksAndSigners[CHAIN_ID.L1].provider.getBlockNumber()
chainId = await networksAndSigners[CHAIN_ID.L1].provider.getNetwork().then(network => Number(network.chainId))
console.log("chainId", chainId)
if (chainId === CHAIN_ID.L1) {
tx = await batchSendL1ToL2()
} else {
throw new Error("Invalid chainId for transaction.")
}
tx = await batchSendL1ToL2()
} else if (fromNetwork.isL1) {
// currentBlockNumber = await networksAndSigners[CHAIN_ID.L1].provider.getBlockNumber()
chainId = await networksAndSigners[CHAIN_ID.L1].provider.getNetwork().then(network => Number(network.chainId))
if (chainId === CHAIN_ID.L1) {
tx = await sendl1ToL2()
} else {
throw new Error("Invalid chainId for transaction.")
}
tx = await sendl1ToL2()
} else if (!fromNetwork.isL1 && toNetwork.isL1) {
// currentBlockNumber = await networksAndSigners[CHAIN_ID.L2].provider.getBlockNumber()
chainId = await networksAndSigners[CHAIN_ID.L2].provider.getNetwork().then(network => Number(network.chainId))
if (chainId === CHAIN_ID.L2) {
tx = await sendl2ToL1()
} else {
throw new Error("Invalid chainId for transaction.")
}
tx = await sendl2ToL1()
}

// start to check tx replacement from current block number
Expand Down Expand Up @@ -217,6 +207,8 @@ export function useSendTransaction(props) {
}

const withdrawETH = async () => {
await checkIsContract(SCROLL_MESSENGER_ADDR[CHAIN_ID.L2])

return networksAndSigners[CHAIN_ID.L2].scrollMessenger["sendMessage(address,uint256,bytes,uint256)"](
receiver || walletCurrentAddress,
parsedAmount,
Expand Down Expand Up @@ -247,6 +239,8 @@ export function useSendTransaction(props) {
}

const batchDepositETH = async () => {
await checkIsContract(BATCH_BRIDGE_GATEWAY_PROXY_ADDR[CHAIN_ID.L1])

const options: TxOptions = {
value: parsedAmount + batchDepositConfig.feeAmountPerTx,
gasLimit: Math.max(Number(gasLimitBatch), LOWER_BOUND),
Expand Down