Skip to content

Commit

Permalink
feat: update createNewTokenBridge
Browse files Browse the repository at this point in the history
  • Loading branch information
antonio-altr committed Aug 1, 2024
1 parent 00e2bf2 commit 49aa9f8
Showing 1 changed file with 54 additions and 61 deletions.
115 changes: 54 additions & 61 deletions scripts/createTokenBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,60 @@ export const createNewTokenBridge = async (
console.log(`Retryable #2: ${retryables[1].transactionHash}`)
console.log(`Done!`)

// set weth gateway (only for eth-based chains)
if (nativeToken === constants.AddressZero) {
console.log(`Setting weth gateway...`)

const setWethGatewayTxRequest =
await createTokenBridgePrepareSetWethGatewayTransactionRequest({
rollup: rollupAddress as Address,
parentChainPublicClient,
orbitChainPublicClient,
account: deployer.address,
retryableGasOverrides: {
gasLimit: {
percentIncrease: 200n,
},
},
})

// sign and send the transaction
const setWethGatewayTxHash =
await parentChainPublicClient.sendRawTransaction({
serializedTransaction: await deployer.signTransaction(
setWethGatewayTxRequest
),
})

// get the transaction receipt after waiting for the transaction to complete
const setWethGatewayTxReceipt =
createTokenBridgePrepareSetWethGatewayTransactionReceipt(
await parentChainPublicClient.waitForTransactionReceipt({
hash: setWethGatewayTxHash,
})
)

console.log(
`Weth gateway set in tx ${setWethGatewayTxReceipt.transactionHash}`
)

// Wait for retryables to execute
console.log(`Waiting for retryables...`)
const orbitChainSetWethGatewayRetryableReceipt =
await setWethGatewayTxReceipt.waitForRetryables({
orbitPublicClient: orbitChainPublicClient,
})
console.log(
`Retryable #1: ${orbitChainSetWethGatewayRetryableReceipt[0].transactionHash}`
)
if (orbitChainSetWethGatewayRetryableReceipt[0].status !== 'success') {
console.error(
`Retryable status is not success: ${orbitChainSetWethGatewayRetryableReceipt[0].status}. The process will continue, but you'll have to register the Weth gateway later again.`
)
}
console.log(`Done!`)
}

const { parentChainContracts, orbitChainContracts } =
await txReceipt.getTokenBridgeContracts({
parentChainPublicClient,
Expand Down Expand Up @@ -277,67 +331,6 @@ export const createNewTokenBridge = async (
blockTime: arbitrumSdkConstants.ARB_MINIMUM_BLOCK_TIME_IN_SECONDS,
}

// set weth gateway (only for eth-based chains)
if (nativeToken === constants.AddressZero) {
console.log(`Setting weth gateway...`)

try {
// This might be necessary if we get ArbSdkError: Unrecognized network
addCustomNetwork({ customL2Network: l2Network });
} catch (error) {
console.log(error)
}

const setWethGatewayTxRequest =
await createTokenBridgePrepareSetWethGatewayTransactionRequest({
rollup: rollupAddress as Address,
parentChainPublicClient,
orbitChainPublicClient,
account: deployer.address,
retryableGasOverrides: {
gasLimit: {
percentIncrease: 200n,
},
},
})

// sign and send the transaction
const setWethGatewayTxHash =
await parentChainPublicClient.sendRawTransaction({
serializedTransaction: await deployer.signTransaction(
setWethGatewayTxRequest
),
})

// get the transaction receipt after waiting for the transaction to complete
const setWethGatewayTxReceipt =
createTokenBridgePrepareSetWethGatewayTransactionReceipt(
await parentChainPublicClient.waitForTransactionReceipt({
hash: setWethGatewayTxHash,
})
)

console.log(
`Weth gateway set in tx ${setWethGatewayTxReceipt.transactionHash}`
)

// Wait for retryables to execute
console.log(`Waiting for retryables...`)
const orbitChainSetWethGatewayRetryableReceipt =
await setWethGatewayTxReceipt.waitForRetryables({
orbitPublicClient: orbitChainPublicClient,
})
console.log(
`Retryable #1: ${orbitChainSetWethGatewayRetryableReceipt[0].transactionHash}`
)
if (orbitChainSetWethGatewayRetryableReceipt[0].status !== 'success') {
console.error(
`Retryable status is not success: ${orbitChainSetWethGatewayRetryableReceipt[0].status}. The process will continue, but you'll have to register the Weth gateway later again.`
)
}
console.log(`Done!`)
}

return {
l1Network,
l2Network,
Expand Down

0 comments on commit 49aa9f8

Please sign in to comment.