Commit 77511b68 authored by Kevin Ho's avatar Kevin Ho

add hardhat task for withdrawing ETH fees to L1

parent 2f4c4846
---
'@eth-optimism/contracts': patch
---
Add a hardhat task to withdraw ETH fees from L2 to L1
......@@ -160,5 +160,23 @@ If you are using a network which Etherscan supports you can verify your contract
npx hardhat etherscan-verify --api-key ... --network ...
```
### Other hardhat tasks
To whitelist deployers on Mainnet you must have the whitelist Owner wallet connected, then run:
```bash
npx hardhat whitelist \
--use-ledger true \
--contracts-rpc-url https://mainnet.optimism.io \
--address ... \ # address to whitelist
```
To withdraw ETH fees to L1 on Mainnet, run:
```bash
npx hardhat withdraw-fees \
--use-ledger \ # The ledger to withdraw fees with. Ensure this wallet has ETH on L2 to pay the tx fee.
--contracts-rpc-url https://mainnet.optimism.io \
```
## Security
Please refer to our [Security Policy](https://github.com/ethereum-optimism/.github/security/policy) for information about how to disclose security issues with this code.
......@@ -17,6 +17,7 @@ import './tasks/deploy'
import './tasks/l2-gasprice'
import './tasks/set-owner'
import './tasks/whitelist'
import './tasks/withdraw-fees'
import 'hardhat-gas-reporter'
// Load environment variables from .env
......
......@@ -63,10 +63,9 @@ task('set-owner')
console.log(`Owner is currently ${owner.toString()}`)
console.log(`Setting owner to ${args.owner}`)
const tx = await Ownable.connect(signer).transferOwnership(
args.owner,
{ gasPrice: args.transactionGasPrice }
)
const tx = await Ownable.connect(signer).transferOwnership(args.owner, {
gasPrice: args.transactionGasPrice,
})
const receipt = await tx.wait()
console.log(`Success - ${receipt.transactionHash}`)
......
'use strict'
import { ethers } from 'ethers'
import { task } from 'hardhat/config'
import * as types from 'hardhat/internal/core/params/argumentTypes'
import { LedgerSigner } from '@ethersproject/hardware-wallets'
import { getContractFactory } from '../src/contract-defs'
import { predeploys } from '../src/predeploys'
// Withdraw fees from the FeeVault to L1
// npx hardhat withdraw-fees --dry-run
task('withdraw-fees')
.addOptionalParam('dryRun', 'simulate withdrawing fees', false, types.boolean)
.addOptionalParam(
'useLedger',
'use a ledger for signing',
false,
types.boolean
)
.addOptionalParam(
'ledgerPath',
'ledger key derivation path',
ethers.utils.defaultPath,
types.string
)
.addOptionalParam(
'contractsRpcUrl',
'Sequencer HTTP Endpoint',
process.env.CONTRACTS_RPC_URL,
types.string
)
.addOptionalParam(
'privateKey',
'Private Key',
process.env.CONTRACTS_DEPLOYER_KEY,
types.string
)
.setAction(async (args, hre: any) => {
const provider = new ethers.providers.JsonRpcProvider(args.contractsRpcUrl)
let signer: ethers.Signer
if (!args.useLedger) {
if (!args.contractsDeployerKey) {
throw new Error('Must pass --contracts-deployer-key')
}
signer = new ethers.Wallet(args.contractsDeployerKey).connect(provider)
} else {
signer = new LedgerSigner(provider, 'default', args.ledgerPath)
}
if (args.dryRun) {
console.log('Performing dry run of fee withdrawal...')
}
const l2FeeVault = getContractFactory('OVM_SequencerFeeVault')
.connect(signer)
.attach(predeploys.OVM_SequencerFeeVault)
const signerAddress = await signer.getAddress()
const signerBalance = await provider.getBalance(signerAddress)
const signerBalanceInETH = ethers.utils.formatEther(signerBalance)
console.log(
`Using L2 signer ${signerAddress} with a balance of ${signerBalanceInETH} ETH`
)
const l1FeeWallet = await l2FeeVault.l1FeeWallet()
const amount = await provider.getBalance(l2FeeVault.address)
const amountInETH = ethers.utils.formatEther(amount)
console.log(
`${
args.dryRun ? '[DRY RUN] ' : ''
}Withdrawing ${amountInETH} ETH to the L1 address: ${l1FeeWallet}`
)
if (args.dryRun) {
await l2FeeVault.estimateGas.withdraw()
return
} else {
const withdrawTx = await l2FeeVault.withdraw()
console.log(
`Withdrawal complete: https://optimistic.etherscan.io/tx/${withdrawTx.hash}`
)
console.log(
`Complete withdrawal in 1 week here: https://optimistic.etherscan.io/address/${predeploys.OVM_SequencerFeeVault}#withdrawaltxs`
)
}
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment