Skip to content

Commit

Permalink
Add gasPrice too high error
Browse files Browse the repository at this point in the history
  • Loading branch information
ScreamingHawk committed May 29, 2024
1 parent a37f6ca commit 10276ea
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
35 changes: 26 additions & 9 deletions src/deployers/SingletonDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const EOA_SINGLETONDEPLOYER_ADDRESS =
const SINGLETONDEPLOYER_TX =
'0xf9016c8085174876e8008303c4d88080b90154608060405234801561001057600080fd5b50610134806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80634af63f0214602d575b600080fd5b60cf60048036036040811015604157600080fd5b810190602081018135640100000000811115605b57600080fd5b820183602082011115606c57600080fd5b80359060200191846001830284011164010000000083111715608d57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550509135925060eb915050565b604080516001600160a01b039092168252519081900360200190f35b6000818351602085016000f5939250505056fea26469706673582212206b44f8a82cb6b156bfcc3dc6aadd6df4eefd204bc928a4397fd15dacf6d5320564736f6c634300060200331b83247000822470'

const DEPLOYER_MAX_GAS = ethers.utils.parseUnits("100", 'gwei')

export class SingletonDeployer implements Deployer {
private readonly provider: providers.Provider
singletonFactory: SingletonFactoryContract
Expand Down Expand Up @@ -79,17 +81,32 @@ export class SingletonDeployer implements Deployer {

// Deploy singleton deployer
this.logger?.log('Deploying singleton deployer contract')
const gasPrice = BigNumber.from(txParams.gasPrice ?? await this.provider.getGasPrice())
const gasTooHigh = gasPrice.gt(DEPLOYER_MAX_GAS)
if (gasTooHigh) {
// Warn user that gas price is too high. Try anyway
this.logger?.error('Gas price too high for singleton deployer. Trying anyway...')
}

const tx = await this.provider.sendTransaction(SINGLETONDEPLOYER_TX)
const receipt = await tx.wait()
try {
const receipt = await tx.wait()

// Confirm deployment
if (
receipt.status !== 1 ||
(await this.provider.getCode(SINGLETONFACTORY_ADDR)).length <= 2
) {
const errMsg = `Failed to deploy singleton deployer at ${SINGLETONFACTORY_ADDR}`
this.logger?.error(errMsg)
throw new Error(errMsg)
// Confirm deployment
if (
receipt.status !== 1 ||
(await this.provider.getCode(SINGLETONFACTORY_ADDR)).length <= 2
) {
const errMsg = `Failed to deploy singleton deployer at ${SINGLETONFACTORY_ADDR}`
this.logger?.error(errMsg)
throw new Error(errMsg)
}

} catch (err) {
if (gasTooHigh) {
this.logger?.error('Gas price too high for singleton deployer. This is likely why the transaction failed!')
}
throw err
}
}

Expand Down
37 changes: 27 additions & 10 deletions src/deployers/UniversalDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const UNIVERSALDEPLOYER_FUNDING = BigNumber.from(300).mul(
const UNIVERSALDEPLOYER_TX =
'0xf9010880852416b84e01830222e08080b8b66080604052348015600f57600080fd5b50609980601d6000396000f3fe60a06020601f369081018290049091028201604052608081815260009260609284918190838280828437600092018290525084519495509392505060208401905034f5604080516001600160a01b0383168152905191935081900360200190a0505000fea26469706673582212205a310755225e3c740b2f013fb6343f4c205e7141fcdf15947f5f0e0e818727fb64736f6c634300060a00331ca01820182018201820182018201820182018201820182018201820182018201820a01820182018201820182018201820182018201820182018201820182018201820'

const DEPLOYER_MAX_GAS = ethers.utils.parseUnits("100", 'gwei')

export class UniversalDeployer implements Deployer {
private readonly provider: providers.Provider
universalFactory: UniversalDeployer2Contract
Expand Down Expand Up @@ -84,17 +86,32 @@ export class UniversalDeployer implements Deployer {

// Deploy universal deployer v1
this.logger?.log('Deploying universal deployer contract')
const gasPrice = BigNumber.from(txParams.gasPrice ?? await this.provider.getGasPrice())
const gasTooHigh = gasPrice.gt(DEPLOYER_MAX_GAS)
if (gasTooHigh) {
// Warn user that gas price is too high. Try anyway
this.logger?.error('Gas price too high for universal deployer. Trying anyway...')
}

const tx = await this.provider.sendTransaction(UNIVERSALDEPLOYER_TX)
const receipt = await tx.wait()

// Confirm deployment
if (
receipt.status !== 1 ||
(await this.provider.getCode(UNIVERSALDEPLOYER_ADDRESS)).length <= 2
) {
const errMsg = `Failed to deploy universal deployer at ${UNIVERSALDEPLOYER_ADDRESS}`
this.logger?.error(errMsg)
throw new Error(errMsg)
try {
const receipt = await tx.wait()

// Confirm deployment
if (
receipt.status !== 1 ||
(await this.provider.getCode(UNIVERSALDEPLOYER_ADDRESS)).length <= 2
) {
const errMsg = `Failed to deploy universal deployer at ${UNIVERSALDEPLOYER_ADDRESS}`
this.logger?.error(errMsg)
throw new Error(errMsg)
}

} catch (err) {
if (gasTooHigh) {
this.logger?.error('Gas price too high for universal deployer. This is likely why the transaction failed!')
}
throw err
}
}

Expand Down

0 comments on commit 10276ea

Please sign in to comment.