Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
400d81fb
Unverified
Commit
400d81fb
authored
Dec 08, 2022
by
mergify[bot]
Committed by
GitHub
Dec 08, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4304 from ethereum-optimism/sc/ctb-clean-advanced-contract
maint(ctb): clean up getAdvancedContract
parents
80107e98
e72b44d2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
32 deletions
+20
-32
deploy-utils.ts
packages/contracts-bedrock/src/deploy-utils.ts
+20
-32
No files found.
packages/contracts-bedrock/src/deploy-utils.ts
View file @
400d81fb
...
...
@@ -59,8 +59,8 @@ export const deploy = async ({
await
hre
.
ethers
.
provider
.
waitForTransaction
(
result
.
transactionHash
)
// Create the contract object to return.
const
created
=
get
AdvancedContract
({
hre
,
const
created
=
as
AdvancedContract
({
confirmations
:
hre
.
deployConfig
.
numDeployConfirmations
,
contract
:
new
Contract
(
result
.
address
,
iface
!==
undefined
...
...
@@ -81,18 +81,19 @@ export const deploy = async ({
}
/**
* Returns a version of the contract object which modifies all of the input contract's methods to
:
*
1. Waits for a confirmed receipt with more than numDeployConfirmations confirmations.
*
2. Include simple resubmission logic, ONLY for Kovan, which appears to drop transactions
.
* Returns a version of the contract object which modifies all of the input contract's methods to
*
automatically await transaction receipts and confirmations. Will also throw if we timeout while
*
waiting for a transaction to be included in a block
.
*
* @param opts Options for the contract.
* @param opts.hre HardhatRuntimeEnvironment.
* @param opts.contract Contract to wrap.
* @returns Wrapped contract object.
*/
export
const
getAdvancedContract
=
(
opts
:
{
hre
:
HardhatRuntimeEnvironment
export
const
asAdvancedContract
=
(
opts
:
{
contract
:
Contract
confirmations
?:
number
gasPrice
?:
number
}):
Contract
=>
{
// Temporarily override Object.defineProperty to bypass ether's object protection.
const
def
=
Object
.
defineProperty
...
...
@@ -114,32 +115,25 @@ export const getAdvancedContract = (opts: {
for
(
const
fnName
of
Object
.
keys
(
contract
.
functions
))
{
const
fn
=
contract
[
fnName
].
bind
(
contract
)
;(
contract
as
any
)[
fnName
]
=
async
(...
args
:
any
)
=>
{
// We want to use the gas price that has been configured at the beginning of the deployment.
// However, if the function being triggered is a "constant" (static) function, then we don't
// want to provide a gas price because we're prone to getting insufficient balance errors.
let
gasPrice
:
number
|
undefined
try
{
gasPrice
=
opts
.
hre
.
deployConfig
.
gasPrice
}
catch
(
err
)
{
// Fine, no gas price
}
// We want to use the configured gas price but we need to set the gas price to zero if we're
// triggering a static function.
let
gasPrice
=
opts
.
gasPrice
if
(
contract
.
interface
.
getFunction
(
fnName
).
constant
)
{
gasPrice
=
0
}
// Now actually trigger the transaction (or call).
const
tx
=
await
fn
(...
args
,
{
gasPrice
,
})
// Meant for static calls, we don't need to wait for anything, we get the result right away.
if
(
typeof
tx
!==
'
object
'
||
typeof
tx
.
wait
!==
'
function
'
)
{
return
tx
}
// Special logic for:
// (1) handling confirmations
// (2) handling an issue on Kovan specifically where transactions get dropped for no
// apparent reason.
// Wait for the transaction to be included in a block and wait for the specified number of
// deployment confirmations.
const
maxTimeout
=
120
let
timeout
=
0
while
(
true
)
{
...
...
@@ -147,16 +141,10 @@ export const getAdvancedContract = (opts: {
const
receipt
=
await
contract
.
provider
.
getTransactionReceipt
(
tx
.
hash
)
if
(
receipt
===
null
)
{
timeout
++
if
(
timeout
>
maxTimeout
&&
opts
.
hre
.
network
.
name
===
'
kovan
'
)
{
// Special resubmission logic ONLY required on Kovan.
console
.
log
(
`WARNING: Exceeded max timeout on transaction. Attempting to submit transaction again...`
)
return
contract
[
fnName
](...
args
)
if
(
timeout
>
maxTimeout
)
{
throw
new
Error
(
'
timeout exceeded waiting for txn to be mined
'
)
}
}
else
if
(
receipt
.
confirmations
>=
opts
.
hre
.
deployConfig
.
numDeployConfirmations
)
{
}
else
if
(
receipt
.
confirmations
>=
(
opts
.
confirmations
||
0
))
{
return
tx
}
}
...
...
@@ -204,8 +192,8 @@ export const getContractFromArtifact = async (
}
}
return
get
AdvancedContract
({
hre
,
return
as
AdvancedContract
({
confirmations
:
hre
.
deployConfig
.
numDeployConfirmations
,
contract
:
new
hre
.
ethers
.
Contract
(
artifact
.
address
,
iface
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment