Skip to content

Commit

Permalink
feat: deploy tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
zengzengzenghuy committed Sep 18, 2024
1 parent 797c5ae commit 29d807c
Show file tree
Hide file tree
Showing 6 changed files with 447 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
DEPLOYER_PRIV_KEY=

SEPOLIA_RPC_URL=
CHIADO_RPC_URL="https://rpc.chiadochain.net"
MAINNET_RPC_URL=
GNOSIS_RPC_URL="https://rpc.gnosischain.com"

ETHERSCAN_API_KEY=""
BLOCKSCOUT_API_KEY=""
GNOSISSCAN_API_KEY=""

FOREIGN_CHAIN_ID=1
HOME_CHAIN_ID=100

FOREIGN_AMB=0x4C36d2919e407f0Cc2Ee3c993ccF8ac26d9CE64e
FOREIGN_HASHI_MANAGER_AMB=
FOREIGN_HASHI_MANAGER_XDAI=

FOREIGN_YAHO=0xbAE4Ebbf42815BB9Bc3720267Ea4496277d60DB8
FOREIGN_YARU=0x30f64a297cc66a873FB603d1e89D5891962C25ba
FOREIGN_XDAI=0x4aa42145Aa6Ebf72e164C9bBC74fbD3788045016

HOME_YAHO=0xbAE4Ebbf42815BB9Bc3720267Ea4496277d60DB8
HOME_YARU=0x153801d0B85D2FCAc6EA07446b6A709ce6720AC5
HOME_HASHI_MANAGER_AMB=
HOME_HASHI_MANAGER_XDAI=
HOME_XDAI=0x7301CFA0e1756B71869E93d4e4Dca5c7d0eb0AA6
HOME_AMB=0x75Df5AF045d91108662D8080fD1FEFAd6aA0bb59
94 changes: 94 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
require('@nomicfoundation/hardhat-toolbox')

Check failure on line 1 in hardhat.config.js

View workflow job for this annotation

GitHub Actions / lint

"@nomicfoundation/hardhat-toolbox" is not found

Check failure on line 1 in hardhat.config.js

View workflow job for this annotation

GitHub Actions / lint

Unable to resolve path to module '@nomicfoundation/hardhat-toolbox'
require('@openzeppelin/hardhat-upgrades')

Check failure on line 2 in hardhat.config.js

View workflow job for this annotation

GitHub Actions / lint

"@openzeppelin/hardhat-upgrades" is not found

Check failure on line 2 in hardhat.config.js

View workflow job for this annotation

GitHub Actions / lint

Unable to resolve path to module '@openzeppelin/hardhat-upgrades'

require('dotenv').config()

Check failure on line 4 in hardhat.config.js

View workflow job for this annotation

GitHub Actions / lint

"dotenv" is not found

Check failure on line 4 in hardhat.config.js

View workflow job for this annotation

GitHub Actions / lint

Unable to resolve path to module 'dotenv'
require('./tasks/deployAMB')
require('./tasks/deloyXDAI')

module.exports = {
networks: {
fgnosis: {
url: 'http://127.0.0.1:8544',

Check failure on line 11 in hardhat.config.js

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
},
fmainnet: {
url: 'http://127.0.0.1:8545',

Check failure on line 14 in hardhat.config.js

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
},
sepolia: {
url: process.env.SEPOLIA_RPC_URL,
accounts: [process.env.DEPLOYER_PRIV_KEY],

Check failure on line 18 in hardhat.config.js

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
},
chiado: {
url: 'https://rpc.chiadochain.net',
accounts: [process.env.DEPLOYER_PRIV_KEY],

Check failure on line 22 in hardhat.config.js

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
},
mainnet: {
url: process.env.MAINNET_RPC_URL,
accounts: [process.env.DEPLOYER_PRIV_KEY],
},
gnosis: {
url: 'https://rpc.gnosischain.com',
accounts: [process.env.DEPLOYER_PRIV_KEY],
},
xdai: {
// use --network xdai to verify on blockscout
url: 'https://rpc.gnosischain.com',
accounts: [process.env.DEPLOYER_PRIV_KEY],
},
},

etherscan: {
apiKey: {
sepolia: process.env.ETHERSCAN_API_KEY,
chiado: process.env.BLOCKSCOUT_API_KEY,
gnosis: process.env.GNOSISSCAN_API_KEY,
xdai: process.env.BLOCKSCOUT_API_KEY, // use --network xdai to verify on blockscout
mainnet: process.env.ETHERSCAN_API_KEY,
},
customChains: [
{
network: 'xdai',
chainId: 100,
urls: {
apiURL: 'https://gnosis.blockscout.com//api',
browserURL: 'https://gnosis.blockscout.com/',
},
},
{
network: 'chiado',
chainId: 10200,
urls: {
apiURL: 'https://gnosis-chiado.blockscout.com/api',
browserURL: 'https://gnosis-chiado.blockscout.com/',
},
},
],
},
path: {
source: 'contracts',
scripts: 'hardhat-deploy',
},
solidity: {
compilers: [
{
version: '0.4.24',
settings: {
optimizer: {
enabled: true,
runs: 100, // NOTE: change to 100 when using HomeBridgeErcToNative
},
evmVersion: 'byzantium',
},
},
{
version: '0.8.20',
settings: {
viaIR: true,
optimizer: {
enabled: true,
runs: 10000,
},
},
},
],
},
}
142 changes: 142 additions & 0 deletions tasks/deloyXDAI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
const { task } = require('hardhat/config')
const verify = require('./verify')
require('dotenv').config()

task('deploy:ForeignxDAIBridge')
.addFlag('verify')
.setAction(async (_taskArgs, hre) => {
const [owner] = await hre.ethers.getSigners()
let ProxyFactory = await hre.ethers.getContractFactory('EternalStorageProxy')
let ForeignxDAIBridgeFactory = await hre.ethers.getContractFactory('XDaiForeignBridge')
let HashiManagerFactory = await hre.ethers.getContractFactory('HashiManager')

console.log('Deploying Foreign xDAI bridge implementation...')

Check warning on line 13 in tasks/deloyXDAI.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
let ForeignxDAIBridge = await ForeignxDAIBridgeFactory.deploy()
await ForeignxDAIBridge.deploymentTransaction().wait()
const ForeignxDAIBridgeAddress = await ForeignxDAIBridge.getAddress()
console.log('Foreign xDAI bridge deployed to ', ForeignxDAIBridgeAddress)

Check warning on line 17 in tasks/deloyXDAI.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

let ForeignHashiManagerProxy
let ForeignHashiManager

if (!process.env.FOREIGN_HASHI_MANAGER_XDAI) {
console.log('Deploying Hashi Manager....')

Check warning on line 23 in tasks/deloyXDAI.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
ForeignHashiManagerProxy = await ProxyFactory.deploy()
await ForeignHashiManagerProxy.deploymentTransaction().wait()
ForeignHashiManager = await HashiManagerFactory.deploy()

await ForeignHashiManager.deploymentTransaction().wait()
console.log('Hashi Manager deployed to', await ForeignHashiManagerProxy.getAddress())

Check warning on line 29 in tasks/deloyXDAI.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

console.log('Upgrading Foreign Hashi Manager Proxy...')

Check warning on line 31 in tasks/deloyXDAI.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
let hashiManagerUpgradeTx = await ForeignHashiManagerProxy.connect(owner).upgradeTo(
'1',
await ForeignHashiManager.getAddress()
)
await hashiManagerUpgradeTx.wait()
console.log(`Foreign Hashi Manager upgrade Tx ${hashiManagerUpgradeTx.hash}`)

Check warning on line 37 in tasks/deloyXDAI.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
ForeignHashiManager = ForeignHashiManager.attach(await ForeignHashiManagerProxy.getAddress())

console.log('Configuring Hashi Manager...')

Check warning on line 40 in tasks/deloyXDAI.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
let setHashiOwner = await ForeignHashiManager.initialize(owner.address)
await setHashiOwner.wait()
console.log(`Hashi Owner set: ${setHashiOwner.hash}`)

Check warning on line 43 in tasks/deloyXDAI.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

let setHashiTargetChainIDTx = await ForeignHashiManager.connect(owner).setTargetChainId(process.env.HOME_CHAIN_ID)
await setHashiTargetChainIDTx.wait()
console.log(`Target ChainID set to ${process.env.HOME_CHAIN_ID}: ${setHashiTargetChainIDTx.hash}`)

Check warning on line 47 in tasks/deloyXDAI.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

let setTargetAddress = await ForeignHashiManager.connect(owner).setTargetAddress(process.env.HOME_XDAI)
await setTargetAddress.wait()
console.log(`Target Address set: ${setTargetAddress.hash}`)

Check warning on line 51 in tasks/deloyXDAI.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

let setYahoTx = await ForeignHashiManager.connect(owner).setYaho(process.env.FOREIGN_YAHO)
await setYahoTx.wait()
console.log(`Yaho set: ${setYahoTx.hash}`)

let setYaruTx = await ForeignHashiManager.connect(owner).setYaru(process.env.FOREIGN_YARU)
await setYaruTx.wait()
console.log(`Yaru set: ${setYaruTx.hash}`)
}

if (_taskArgs.verify) {
console.log('Verifying contracts....')

await verify(hre, ForeignxDAIBridgeAddress, [])
if (!process.env.FOREIGN_HASHI_MANAGER_XDAI) {
await verify(hre, await ForeignHashiManagerProxy.getAddress(), [])
await verify(hre, await ForeignHashiManager.getAddress(), [])
}
}
console.log('Foreign xDAI bridge deployment done')
})

task('deploy:HomexDAIBridge')
.addFlag('verify')
.setAction(async (_taskArgs, hre) => {
const [owner] = await hre.ethers.getSigners()
let ProxyFactory = await hre.ethers.getContractFactory('EternalStorageProxy')

let HomexDAIFactory = await hre.ethers.getContractFactory('HomeBridgeErcToNative')
let HashiManagerFactory = await hre.ethers.getContractFactory('HashiManager')
let HomeHashiManagerProxy
let HomeHashiManager

console.log('Deploying Home xDAI bridge implementation...')
let HomexDAI = await HomexDAIFactory.deploy()
await HomexDAI.deploymentTransaction().wait()
const HomexDAIAddress = await HomexDAI.getAddress()

console.log('Home xDAI bridge deployed to ', HomexDAIAddress)

if (!process.env.HOME_HASHI_MANAGER_XDAI) {
console.log('Deploying Hashi Manager....')
HomeHashiManagerProxy = await ProxyFactory.deploy()
await HomeHashiManagerProxy.deploymentTransaction().wait()

HomeHashiManager = await HashiManagerFactory.deploy()
await HomeHashiManager.deploymentTransaction().wait()

console.log(`Home Hashi Manager deployed to ${await HomeHashiManagerProxy.getAddress()}`)

console.log('Upgrading Home Hashi Manager Proxy...')
let hashiManagerUpgradeTx = await HomeHashiManagerProxy.connect(owner).upgradeTo(
'1',
await HomeHashiManager.getAddress()
)
await hashiManagerUpgradeTx.wait()
console.log(`Hashi Manager upgrade Tx ${hashiManagerUpgradeTx.hash}`)
HomeHashiManager = HomeHashiManager.attach(await HomeHashiManagerProxy.getAddress())

if (_taskArgs.verify) {
console.log('Verifying contracts...')

await verify(hre, HomexDAIAddress, [])
if (!process.env.HOME_HASHI_MANAGER_XDAI) {
await verify(hre, await HomeHashiManagerProxy.getAddress(), [])
await verify(hre, await HomeHashiManager.getAddress(), [])
}
}

let setHashiOwner = await HomeHashiManager.initialize(owner.address)
await setHashiOwner.wait()
console.log(`Hashi Manager Owner set: ${setHashiOwner.hash}`)

let setHashiTargetChainIDTx = await HomeHashiManager.connect(owner).setTargetChainId(process.env.FOREIGN_CHAIN_ID)
await setHashiTargetChainIDTx.wait()
console.log(`Target ChainID set to ${process.env.FOREIGN_CHAIN_ID}: ${setHashiTargetChainIDTx.hash}`)

let setYahoTx = await HomeHashiManager.connect(owner).setYaho(process.env.HOME_YAHO)
await setYahoTx.wait()
console.log(`Yaho set: ${setYahoTx.hash}`)

let setYaruTx = await HomeHashiManager.connect(owner).setYaru(process.env.HOME_YARU)
await setYaruTx.wait()
console.log(`Yaru set: ${setYaruTx.hash}`)

let setTargetAddress = await HomeHashiManager.connect(owner).setTargetAddress(process.env.FOREIGN_XDAI)
await setTargetAddress.wait()
console.log(`Target Address set: ${setTargetAddress.hash}`)
}
console.log('Home xDAI bridge deployment done')
})
Loading

0 comments on commit 29d807c

Please sign in to comment.