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
91e9a748
Unverified
Commit
91e9a748
authored
Oct 25, 2021
by
kf
Committed by
Kelvin Fichter
Nov 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: bugs in forked network setup script
parent
70ff6476
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
31 deletions
+128
-31
0000-hardhat-setup.ts
packages/contracts/deploy/0000-hardhat-setup.ts
+47
-30
hardhat-deploy-ethers.ts
packages/contracts/src/hardhat-deploy-ethers.ts
+81
-1
No files found.
packages/contracts/deploy/0000-hardhat-setup.ts
View file @
91e9a748
/* eslint @typescript-eslint/no-var-requires: "off" */
/* eslint @typescript-eslint/no-var-requires: "off" */
import
{
ethers
}
from
'
ethers
'
import
{
DeployFunction
}
from
'
hardhat-deploy/dist/types
'
import
{
DeployFunction
}
from
'
hardhat-deploy/dist/types
'
import
{
import
{
getAdvancedContract
,
getContractFromArtifact
,
fundAccount
,
sendImpersonatedTx
,
waitUntilTrue
,
waitUntilTrue
,
BIG_BALANCE
,
}
from
'
../src/hardhat-deploy-ethers
'
}
from
'
../src/hardhat-deploy-ethers
'
const
deployFn
:
DeployFunction
=
async
(
hre
)
=>
{
const
deployFn
:
DeployFunction
=
async
(
hre
)
=>
{
const
{
deployer
}
=
await
hre
.
getNamedAccounts
()
if
((
hre
as
any
).
deployConfig
.
forked
!==
'
true
'
)
{
if
((
hre
as
any
).
deployConfig
.
forked
!==
'
true
'
)
{
return
return
}
}
console
.
log
(
`Running custom setup for forked experimental networks`
)
console
.
log
(
`Running custom setup for forked experimental networks`
)
const
{
deployer
}
=
await
hre
.
getNamedAccounts
()
// Fund the deployer account
// Fund the deployer account
so it can be used for the rest of this deployment.
console
.
log
(
`Funding deployer account...`
)
console
.
log
(
`Funding deployer account...`
)
const
amount
=
`0xFFFFFFFFFFFFFFFFFF`
await
fundAccount
(
hre
,
deployer
,
BIG_BALANCE
)
await
hre
.
ethers
.
provider
.
send
(
'
hardhat_setBalance
'
,
[
deployer
,
amount
])
console
.
log
(
`Waiting for balance to reflect...`
)
await
waitUntilTrue
(
async
()
=>
{
const
balance
=
await
hre
.
ethers
.
provider
.
getBalance
(
deployer
)
return
balance
.
gte
(
hre
.
ethers
.
BigNumber
.
from
(
amount
))
})
// Get a reference to the AddressManager contract.
// Get a reference to the AddressManager contract.
const
artifact
=
await
hre
.
deployments
.
get
(
'
Lib_AddressManager
'
)
const
Lib_AddressManager
=
await
getContractFromArtifact
(
const
Lib_AddressManager
=
getAdvancedContract
({
hre
,
hre
,
contract
:
new
hre
.
ethers
.
Contract
(
'
Lib_AddressManager
'
artifact
.
address
,
)
artifact
.
abi
,
hre
.
ethers
.
provider
),
})
// Impersonate the owner of the AddressManager
// Transfer ownership of the AddressManager to the deployer.
console
.
log
(
`Impersonating owner account...`
)
const
owner
=
await
Lib_AddressManager
.
owner
()
await
hre
.
ethers
.
provider
.
send
(
'
hardhat_impersonateAccount
'
,
[
owner
])
console
.
log
(
`Started impersonating
${
owner
}
`
)
console
.
log
(
`Setting AddressManager owner to
${
deployer
}
`
)
console
.
log
(
`Setting AddressManager owner to
${
deployer
}
`
)
const
signer
=
await
hre
.
ethers
.
getSigner
(
owner
)
await
sendImpersonatedTx
({
await
Lib_AddressManager
.
connect
(
signer
).
transferOwnership
(
deployer
)
hre
,
contract
:
Lib_AddressManager
,
fn
:
'
transferOwnership
'
,
from
:
await
Lib_AddressManager
.
owner
(),
gas
:
ethers
.
BigNumber
.
from
(
2
_000_000
).
toHexString
(),
args
:
[
deployer
],
})
console
.
log
(
`Waiting for owner to be correctly set...`
)
console
.
log
(
`Waiting for owner to be correctly set...`
)
await
waitUntilTrue
(
async
()
=>
{
await
waitUntilTrue
(
async
()
=>
{
return
(
await
Lib_AddressManager
.
owner
())
===
deployer
return
(
await
Lib_AddressManager
.
owner
())
===
deployer
})
})
console
.
log
(
`Disabling impersonation...`
)
// Get a reference to the L1StandardBridge contract.
await
hre
.
ethers
.
provider
.
send
(
'
hardhat_stopImpersonatingAccount
'
,
[
owner
])
const
Proxy__OVM_L1StandardBridge
=
await
getContractFromArtifact
(
hre
,
'
Proxy__OVM_L1StandardBridge
'
)
// Transfer ownership of the L1StandardBridge to the deployer.
console
.
log
(
`Setting L1StandardBridge owner to
${
deployer
}
`
)
await
sendImpersonatedTx
({
hre
,
contract
:
Proxy__OVM_L1StandardBridge
,
fn
:
'
setOwner
'
,
from
:
await
Proxy__OVM_L1StandardBridge
.
callStatic
.
getOwner
({
from
:
hre
.
ethers
.
constants
.
AddressZero
,
}),
gas
:
ethers
.
BigNumber
.
from
(
2
_000_000
).
toHexString
(),
args
:
[
deployer
],
})
console
.
log
(
`Waiting for owner to be correctly set...`
)
await
waitUntilTrue
(
async
()
=>
{
return
(
(
await
Proxy__OVM_L1StandardBridge
.
callStatic
.
getOwner
({
from
:
hre
.
ethers
.
constants
.
AddressZero
,
}))
===
deployer
)
})
}
}
deployFn
.
tags
=
[
'
hardhat
'
,
'
upgrade
'
]
deployFn
.
tags
=
[
'
hardhat
'
,
'
upgrade
'
]
...
...
packages/contracts/src/hardhat-deploy-ethers.ts
View file @
91e9a748
/* Imports: External */
/* Imports: External */
import
{
Contract
}
from
'
ethers
'
import
{
ethers
,
Contract
}
from
'
ethers
'
import
{
Provider
}
from
'
@ethersproject/abstract-provider
'
import
{
Provider
}
from
'
@ethersproject/abstract-provider
'
import
{
Signer
}
from
'
@ethersproject/abstract-signer
'
import
{
Signer
}
from
'
@ethersproject/abstract-signer
'
import
{
sleep
,
hexStringEquals
}
from
'
@eth-optimism/core-utils
'
import
{
sleep
,
hexStringEquals
}
from
'
@eth-optimism/core-utils
'
import
{
HttpNetworkConfig
}
from
'
hardhat/types
'
export
const
waitUntilTrue
=
async
(
export
const
waitUntilTrue
=
async
(
check
:
()
=>
Promise
<
boolean
>
,
check
:
()
=>
Promise
<
boolean
>
,
...
@@ -208,3 +209,82 @@ export const getDeployedContract = async (
...
@@ -208,3 +209,82 @@ export const getDeployedContract = async (
contract
:
new
Contract
(
deployed
.
address
,
iface
,
signerOrProvider
),
contract
:
new
Contract
(
deployed
.
address
,
iface
,
signerOrProvider
),
})
})
}
}
export
const
fundAccount
=
async
(
hre
:
any
,
address
:
string
,
amount
:
ethers
.
BigNumber
)
=>
{
if
((
hre
as
any
).
deployConfig
.
forked
!==
'
true
'
)
{
throw
new
Error
(
'
this method can only be used against a forked network
'
)
}
console
.
log
(
`Funding account
${
address
}
...`
)
await
hre
.
ethers
.
provider
.
send
(
'
hardhat_setBalance
'
,
[
address
,
amount
.
toHexString
(),
])
console
.
log
(
`Waiting for balance to reflect...`
)
await
waitUntilTrue
(
async
()
=>
{
const
balance
=
await
hre
.
ethers
.
provider
.
getBalance
(
address
)
return
balance
.
gte
(
amount
)
})
console
.
log
(
`Account successfully funded.`
)
}
export
const
sendImpersonatedTx
=
async
(
opts
:
{
hre
:
any
contract
:
ethers
.
Contract
fn
:
string
from
:
string
gas
:
string
args
:
any
[]
})
=>
{
if
((
opts
.
hre
as
any
).
deployConfig
.
forked
!==
'
true
'
)
{
throw
new
Error
(
'
this method can only be used against a forked network
'
)
}
console
.
log
(
`Impersonating account
${
opts
.
from
}
...`
)
await
opts
.
hre
.
ethers
.
provider
.
send
(
'
hardhat_impersonateAccount
'
,
[
opts
.
from
])
console
.
log
(
`Funding account
${
opts
.
from
}
...`
)
await
fundAccount
(
opts
.
hre
,
opts
.
from
,
BIG_BALANCE
)
console
.
log
(
`Sending impersonated transaction...`
)
const
tx
=
await
opts
.
contract
.
populateTransaction
[
opts
.
fn
](...
opts
.
args
)
const
provider
=
new
opts
.
hre
.
ethers
.
providers
.
JsonRpcProvider
(
(
opts
.
hre
.
network
.
config
as
HttpNetworkConfig
).
url
)
await
provider
.
send
(
'
eth_sendTransaction
'
,
[
{
...
tx
,
from
:
opts
.
from
,
gas
:
opts
.
gas
,
},
])
console
.
log
(
`Stopping impersonation of account
${
opts
.
from
}
...`
)
await
opts
.
hre
.
ethers
.
provider
.
send
(
'
hardhat_stopImpersonatingAccount
'
,
[
opts
.
from
,
])
}
export
const
getContractFromArtifact
=
async
(
hre
:
any
,
name
:
string
):
Promise
<
ethers
.
Contract
>
=>
{
const
artifact
=
await
hre
.
deployments
.
get
(
name
)
return
getAdvancedContract
({
hre
,
contract
:
new
hre
.
ethers
.
Contract
(
artifact
.
address
,
artifact
.
abi
,
hre
.
ethers
.
provider
),
})
}
// Large balance to fund accounts with.
export
const
BIG_BALANCE
=
ethers
.
BigNumber
.
from
(
`0xFFFFFFFFFFFFFFFFFFFF`
)
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