Skip to content

Commit

Permalink
fix(core): use EIP-1559 transactions if supported by the network
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Jan 6, 2023
1 parent 6c6e32e commit d6984ec
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 40 deletions.
7 changes: 7 additions & 0 deletions .changeset/selfish-badgers-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@chugsplash/core': patch
'@chugsplash/executor': patch
'@chugsplash/plugins': patch
---

Override transaction gas prices to use EIP-1559 if supported by the network
17 changes: 11 additions & 6 deletions packages/core/src/actions/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import {
ChugSplashBundleState,
ChugSplashBundleStatus,
} from './types'
import { getGasPriceOverrides } from '../utils'

export const executeTask = async (args: {
chugSplashManager: ethers.Contract
bundle: ChugSplashActionBundle
bundleState: ChugSplashBundleState
executor: ethers.Signer
executor: ethers.Wallet
projectName: string
logger: Logger
}) => {
Expand Down Expand Up @@ -52,9 +53,11 @@ export const executeTask = async (args: {
`[ChugSplash]: claiming the bundle for project: ${projectName}`
)
await (
await chugSplashManager.claimBundle({
value: EXECUTOR_BOND_AMOUNT,
})
await chugSplashManager.claimBundle(
await getGasPriceOverrides(executor.provider, {
value: EXECUTOR_BOND_AMOUNT,
})
)
).wait()
logger.info(`[ChugSplash]: claimed the bundle`)
} else if (bundleState.selectedExecutor !== executorAddress) {
Expand Down Expand Up @@ -183,7 +186,8 @@ export const executeTask = async (args: {
await chugSplashManager.executeMultipleActions(
batch.map((action) => action.action),
batch.map((action) => action.proof.actionIndex),
batch.map((action) => action.proof.siblings)
batch.map((action) => action.proof.siblings),
await getGasPriceOverrides(executor.provider)
)
).wait()

Expand Down Expand Up @@ -221,7 +225,8 @@ export const executeTask = async (args: {
await chugSplashManager.completeChugSplashBundle(
setImplActions.map((action) => action.action),
setImplActions.map((action) => action.proof.actionIndex),
setImplActions.map((action) => action.proof.siblings)
setImplActions.map((action) => action.proof.siblings),
await getGasPriceOverrides(executor.provider)
)
).wait()
logger.info(`[ChugSplash]: executed SetImplementation actions`)
Expand Down
25 changes: 16 additions & 9 deletions packages/core/src/languages/solidity/predeploys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
getProxyAdmin,
isContractDeployed,
getProxyImplementationAddress,
getGasPriceOverrides,
} from '../../utils'

export const initializeChugSplash = async (
Expand Down Expand Up @@ -88,7 +89,8 @@ export const initializeChugSplash = async (
EXECUTOR_PAYMENT_PERCENTAGE,
ChugSplashManager.address,
CHUGSPLASH_REGISTRY_PROXY_ADDRESS,
CHUGSPLASH_SALT
CHUGSPLASH_SALT,
await getGasPriceOverrides(provider)
)
).wait()
logger?.info('[ChugSplash]: ChugSplashBootLoader initialized')
Expand Down Expand Up @@ -153,7 +155,10 @@ export const initializeChugSplash = async (
// Initialize the ChugSplashRegistry's proxy. This sets the ChugSplashRegistry proxy's
// implementation and transfers ownership of the proxy to the multisig owner.
await (
await ProxyInitializer.initialize(CHUGSPLASH_REGISTRY_ADDRESS)
await ProxyInitializer.initialize(
CHUGSPLASH_REGISTRY_ADDRESS,
await getGasPriceOverrides(provider)
)
).wait()

// Make sure ownership of the ChugSplashRegistry's proxy has been transferred.
Expand Down Expand Up @@ -211,7 +216,8 @@ export const initializeChugSplash = async (
await (
await ChugSplashRegistry.addProxyType(
ethers.constants.HashZero,
DefaultAdapter.address
DefaultAdapter.address,
await getGasPriceOverrides(provider)
)
).wait()
logger?.info(
Expand Down Expand Up @@ -298,13 +304,14 @@ export const doDeterministicDeploy = async (
return new ethers.Contract(address, options.contract.abi, options.signer)
}

// Create a transaction request with gas price overrides.
const txnRequest = await getGasPriceOverrides(provider, {
to: deployer,
data: options.salt + ethers.utils.hexlify(deploymentTx.data).slice(2),
})

// Deploy the contract.
await (
await options.signer.sendTransaction({
to: deployer,
data: options.salt + ethers.utils.hexlify(deploymentTx.data).slice(2),
})
).wait()
await (await options.signer.sendTransaction(txnRequest)).wait()

if ((await isContractDeployed(address, provider)) === false) {
throw new Error(`failed to deploy contract at ${address}`)
Expand Down
56 changes: 52 additions & 4 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import * as path from 'path'
import * as fs from 'fs'

import { utils, constants, Signer, Contract, providers, ethers } from 'ethers'
import {
utils,
constants,
Signer,
Wallet,
Contract,
providers,
ethers,
PayableOverrides,
BigNumber,
} from 'ethers'
import {
ProxyArtifact,
ChugSplashRegistryABI,
Expand All @@ -10,6 +20,7 @@ import {
CHUGSPLASH_REGISTRY_PROXY_ADDRESS,
ProxyABI,
} from '@chugsplash/contracts'
import { TransactionRequest } from '@ethersproject/abstract-provider'

import { CanonicalChugSplashConfig, ParsedChugSplashConfig } from './config'
import { ChugSplashActionBundle, ChugSplashActionType } from './actions'
Expand Down Expand Up @@ -211,7 +222,13 @@ export const registerChugSplashProject = async (
if (
(await ChugSplashRegistry.projects(projectName)) === constants.AddressZero
) {
await (await ChugSplashRegistry.register(projectName, projectOwner)).wait()
await (
await ChugSplashRegistry.register(
projectName,
projectOwner,
await getGasPriceOverrides(provider)
)
).wait()
return true
} else {
const existingProjectOwner = await getProjectOwnerAddress(
Expand Down Expand Up @@ -315,12 +332,16 @@ export const displayDeploymentTable = (
}

export const claimExecutorPayment = async (
executor: Signer,
executor: Wallet,
ChugSplashManager: Contract
) => {
const executorDebt = await ChugSplashManager.debt(await executor.getAddress())
if (executorDebt.gt(0)) {
await (await ChugSplashManager.claimExecutorPayment()).wait()
await (
await ChugSplashManager.claimExecutorPayment(
await getGasPriceOverrides(executor.provider)
)
).wait()
}
}

Expand Down Expand Up @@ -416,3 +437,30 @@ export const getProxyImplementationAddress = async (
)
return decoded
}

/**
* Overrides an object's gas price settings to support EIP-1559 transactions if EIP-1559 is
* supported by the network. This only overrides the default behavior on Goerli, where transactions
* sent via Alchemy or Infura do not yet support EIP-1559 gas pricing, despite the fact that
* `maxFeePerGas` and `maxPriorityFeePerGas` are defined.
*
* @param provider Provider object.
* @param overridden The object whose gas price settings will be overridden.
* @returns The object whose gas price settings will be overridden.
*/
export const getGasPriceOverrides = async (
provider: ethers.providers.Provider,
overridden: PayableOverrides | TransactionRequest = {}
): Promise<PayableOverrides | TransactionRequest> => {
const { maxFeePerGas, maxPriorityFeePerGas } = await provider.getFeeData()

if (
BigNumber.isBigNumber(maxFeePerGas) &&
BigNumber.isBigNumber(maxPriorityFeePerGas)
) {
overridden.maxFeePerGas = maxFeePerGas
overridden.maxPriorityFeePerGas = maxPriorityFeePerGas
}

return overridden
}
4 changes: 3 additions & 1 deletion packages/plugins/src/hardhat/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
getAmountToDeposit,
isContractDeployed,
formatEther,
getGasPriceOverrides,
} from '@chugsplash/core'
import { getChainId } from '@eth-optimism/core-utils'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
Expand Down Expand Up @@ -429,7 +430,8 @@ reference name to something other than ${upgradeReferenceName}.`
await ChugSplashManager.proposeChugSplashBundle(
bundle.root,
bundle.actions.length,
configUri
configUri,
await getGasPriceOverrides(provider)
)
).wait()

Expand Down
23 changes: 18 additions & 5 deletions packages/plugins/src/hardhat/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getAmountToDeposit,
EXECUTION_BUFFER_MULTIPLIER,
formatEther,
getGasPriceOverrides,
} from '@chugsplash/core'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { ethers } from 'ethers'
Expand Down Expand Up @@ -159,7 +160,8 @@ export const postExecutionActions = async (
) => {
spinner.start(`Sending leftover funds to the project owner...`)

const signer = hre.ethers.provider.getSigner()
const provider = hre.ethers.provider
const signer = provider.getSigner()
const ChugSplashManager = getChugSplashManager(
signer,
parsedConfig.options.projectName
Expand All @@ -172,11 +174,15 @@ export const postExecutionActions = async (
if ((await signer.getAddress()) === currProjectOwner) {
// Withdraw any of the current project owner's funds in the ChugSplashManager.
const ownerBalance = await getOwnerWithdrawableAmount(
hre.ethers.provider,
provider,
parsedConfig.options.projectName
)
if (ownerBalance.gt(0)) {
await (await ChugSplashManager.withdrawOwnerETH()).wait()
await (
await ChugSplashManager.withdrawOwnerETH(
await getGasPriceOverrides(provider)
)
).wait()
spinner.succeed(
`Sent leftover funds to the project owner. Amount: ${formatEther(
ownerBalance,
Expand All @@ -194,10 +200,17 @@ export const postExecutionActions = async (
spinner.start(`Transferring project ownership to: ${newProjectOwner}`)
if (newProjectOwner === ethers.constants.AddressZero) {
// We must call a separate function if ownership is being transferred to address(0).
await (await ChugSplashManager.renounceOwnership()).wait()
await (
await ChugSplashManager.renounceOwnership(
await getGasPriceOverrides(provider)
)
).wait()
} else {
await (
await ChugSplashManager.transferOwnership(newProjectOwner)
await ChugSplashManager.transferOwnership(
newProjectOwner,
await getGasPriceOverrides(provider)
)
).wait()
}
spinner.succeed(`Transferred project ownership to: ${newProjectOwner}`)
Expand Down
Loading

0 comments on commit d6984ec

Please sign in to comment.