Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"semi": false,
"singleQuote": true,
"printWidth": 80,
"printWidth": 120,
"endOfLine": "auto",
"tabWidth": 4,
"trailingComma": "all",
Expand Down
121 changes: 31 additions & 90 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ const lazyImport = async (module: any) => {
return await import(module)
}

async function saveDeployments(
env: string,
deploymentData: { [key in string]: string },
branch?: string,
) {
async function saveDeployments(env: string, deploymentData: { [key in string]: string }, branch?: string) {
const deploymentsJsonPath = `${process.cwd()}/deployments.json`

let deploymentsJson = { [env]: {} }
if (fs.existsSync(deploymentsJsonPath)) {
deploymentsJson = JSON.parse(
fs.readFileSync(deploymentsJsonPath).toString(),
)
deploymentsJson = JSON.parse(fs.readFileSync(deploymentsJsonPath).toString())
}

if (branch) {
Expand All @@ -47,9 +41,7 @@ async function saveDeploymentsFacets(
const deploymentsJsonPath = `${process.cwd()}/${filename}`
let deploymentsJson = { [env]: {} }
if (fs.existsSync(deploymentsJsonPath)) {
deploymentsJson = JSON.parse(
fs.readFileSync(deploymentsJsonPath).toString(),
)
deploymentsJson = JSON.parse(fs.readFileSync(deploymentsJsonPath).toString())
}
const facets = deploymentsJson[env]['Facets']
for (const facetIndex in facets) {
Expand All @@ -60,17 +52,12 @@ async function saveDeploymentsFacets(
}
fs.writeFileSync(deploymentsJsonPath, JSON.stringify(deploymentsJson))
}
async function saveSubnetRegistry(
env: string,
subnetRegistryData: { [key in string]: string },
) {
async function saveSubnetRegistry(env: string, subnetRegistryData: { [key in string]: string }) {
const subnetRegistryJsonPath = `${process.cwd()}/subnet.registry.json`

let subnetRegistryJson = { [env]: {} }
if (fs.existsSync(subnetRegistryJsonPath)) {
subnetRegistryJson = JSON.parse(
fs.readFileSync(subnetRegistryJsonPath).toString(),
)
subnetRegistryJson = JSON.parse(fs.readFileSync(subnetRegistryJsonPath).toString())
}

subnetRegistryJson[env] = {
Expand All @@ -84,9 +71,7 @@ async function saveSubnetRegistry(
async function readSubnetActor(subnetActorAddress, network) {
const subnetActorJsonPath = `${process.cwd()}/subnet.actor-${subnetActorAddress}.json`
if (fs.existsSync(subnetActorJsonPath)) {
const subnetActor = JSON.parse(
fs.readFileSync(subnetActorJsonPath).toString(),
)
const subnetActor = JSON.parse(fs.readFileSync(subnetActorJsonPath).toString())
return subnetActor
}
const subnetRegistry = await getSubnetRegistry(network)
Expand All @@ -97,13 +82,8 @@ async function readSubnetActor(subnetActorAddress, network) {
return deployments
}

async function saveSubnetActor(
deployments,
updatedFacets: { [key in string]: string },
) {
const subnetActorJsonPath = `${process.cwd()}/subnet.actor-${
deployments.SubnetActorDiamond
}.json`
async function saveSubnetActor(deployments, updatedFacets: { [key in string]: string }) {
const subnetActorJsonPath = `${process.cwd()}/subnet.actor-${deployments.SubnetActorDiamond}.json`
for (const facetIndex in deployments.Facets) {
const facetName = deployments.Facets[facetIndex].name
if (updatedFacets[facetName]) {
Expand All @@ -113,46 +93,34 @@ async function saveSubnetActor(
fs.writeFileSync(subnetActorJsonPath, JSON.stringify(deployments))
}

async function getSubnetRegistry(
env: string,
): Promise<{ [key in string]: string }> {
async function getSubnetRegistry(env: string): Promise<{ [key in string]: string }> {
const subnetRegistryJsonPath = `${process.cwd()}/subnet.registry.json`

let subnetRegistry = {}
if (fs.existsSync(subnetRegistryJsonPath)) {
subnetRegistry = JSON.parse(
fs.readFileSync(subnetRegistryJsonPath).toString(),
)[env]
subnetRegistry = JSON.parse(fs.readFileSync(subnetRegistryJsonPath).toString())[env]
}

return subnetRegistry
}

async function getSubnetActor(
env: string,
): Promise<{ [key in string]: string }> {
async function getSubnetActor(env: string): Promise<{ [key in string]: string }> {
const subnetRegistryJsonPath = `${process.cwd()}/subnet.actor.json`

let subnetRegistry = {}
if (fs.existsSync(subnetRegistryJsonPath)) {
subnetRegistry = JSON.parse(
fs.readFileSync(subnetRegistryJsonPath).toString(),
)[env]
subnetRegistry = JSON.parse(fs.readFileSync(subnetRegistryJsonPath).toString())[env]
}

return subnetRegistry
}

async function getDeployments(
env: string,
): Promise<{ [key in string]: string }> {
async function getDeployments(env: string): Promise<{ [key in string]: string }> {
const deploymentsJsonPath = `${process.cwd()}/deployments.json`

let deployments = {}
if (fs.existsSync(deploymentsJsonPath)) {
deployments = JSON.parse(
fs.readFileSync(deploymentsJsonPath).toString(),
)[env]
deployments = JSON.parse(fs.readFileSync(deploymentsJsonPath).toString())[env]
}

return deployments
Expand Down Expand Up @@ -205,9 +173,7 @@ task(
async (args, hre: HardhatRuntimeEnvironment) => {
const network = hre.network.name
const deployments = await getDeployments(network)
const { deployDiamond } = await lazyImport(
'./scripts/deploy-gw-diamond',
)
const { deployDiamond } = await lazyImport('./scripts/deploy-gw-diamond')
const gatewayActorDiamond = await deployDiamond(deployments.libs)
await saveDeployments(network, gatewayActorDiamond)
},
Expand All @@ -223,25 +189,17 @@ task(
},
)

task(
'deploy-gw-diamond',
'Builds and deploys Gateway Actor diamond',
async (args, hre: HardhatRuntimeEnvironment) => {
await hre.run('compile')
await hre.run('deploy-libraries')
await hre.run('deploy-gw-diamond-and-facets')
},
)
task('deploy-gw-diamond', 'Builds and deploys Gateway Actor diamond', async (args, hre: HardhatRuntimeEnvironment) => {
await hre.run('compile')
await hre.run('deploy-libraries')
await hre.run('deploy-gw-diamond-and-facets')
})

task(
'deploy-sa-diamond',
'Builds and deploys Subnet Actor diamond',
async (args, hre: HardhatRuntimeEnvironment) => {
await hre.run('compile')
await hre.run('deploy-libraries')
await hre.run('deploy-sa-diamond-and-facets')
},
)
task('deploy-sa-diamond', 'Builds and deploys Subnet Actor diamond', async (args, hre: HardhatRuntimeEnvironment) => {
await hre.run('compile')
await hre.run('deploy-libraries')
await hre.run('deploy-sa-diamond-and-facets')
})

task(
'upgrade-gw-diamond',
Expand All @@ -250,9 +208,7 @@ task(
await hre.run('compile')
const network = hre.network.name
const deployments = await getDeployments(network)
const { upgradeDiamond } = await lazyImport(
'./scripts/upgrade-gw-diamond',
)
const { upgradeDiamond } = await lazyImport('./scripts/upgrade-gw-diamond')
const updatedFacets = await upgradeDiamond(deployments)
await saveDeploymentsFacets('deployments.json', network, updatedFacets)
},
Expand All @@ -265,15 +221,9 @@ task(
await hre.run('compile')
const network = hre.network.name
const subnetRegistry = await getSubnetRegistry(network)
const { upgradeDiamond } = await lazyImport(
'./scripts/upgrade-sr-diamond',
)
const { upgradeDiamond } = await lazyImport('./scripts/upgrade-sr-diamond')
const updatedFacets = await upgradeDiamond(subnetRegistry)
await saveDeploymentsFacets(
'subnet.registry.json',
network,
updatedFacets,
)
await saveDeploymentsFacets('subnet.registry.json', network, updatedFacets)
},
)

Expand All @@ -284,17 +234,13 @@ task(
await hre.run('compile')
const network = hre.network.name
if (!args.address) {
console.error(
'No address provided. Usage: pnpm exec hardhat upgrade-sa-diamond --address 0x80afa...',
)
console.error('No address provided. Usage: pnpm exec hardhat upgrade-sa-diamond --address 0x80afa...')
process.exit(1)
}

const deployments = await readSubnetActor(args.address, network)

const { upgradeDiamond } = await lazyImport(
'./scripts/upgrade-sa-diamond',
)
const { upgradeDiamond } = await lazyImport('./scripts/upgrade-sa-diamond')
const updatedFacets = await upgradeDiamond(deployments)
await saveSubnetActor(deployments, updatedFacets)
},
Expand Down Expand Up @@ -352,12 +298,7 @@ const config: HardhatUserConfig = {
storageLayouts: '.storage-layouts',
},
storageLayoutChanges: {
contracts: [
'GatewayDiamond',
'SubnetActorDiamond',
'GatewayActorModifiers',
'SubnetActorModifiers',
],
contracts: ['GatewayDiamond', 'SubnetActorDiamond', 'GatewayActorModifiers', 'SubnetActorModifiers'],
fullPath: false,
},
}
Expand Down
22 changes: 4 additions & 18 deletions contracts/scripts/deploy-gateway.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ import { ethers } from 'hardhat'
const { getSelectors, FacetCutAction } = require('./js/diamond.js')

function getGitCommitSha(): string {
const commitSha = require('child_process')
.execSync('git rev-parse --short HEAD')
.toString()
.trim()
const commitSha = require('child_process').execSync('git rev-parse --short HEAD').toString().trim()
return commitSha
}
export async function deploy(libs: { [key in string]: string }) {
if (!libs || Object.keys(libs).length === 0)
throw new Error(`Libraries are missing`)
if (!libs || Object.keys(libs).length === 0) throw new Error(`Libraries are missing`)

// choose chain ID according to the network in
// environmental variable
Expand All @@ -32,12 +28,7 @@ export async function deploy(libs: { [key in string]: string }) {

const [deployer] = await ethers.getSigners()
const balance = await ethers.provider.getBalance(deployer.address)
console.log(
'Deploying gateway with the account:',
deployer.address,
' balance:',
ethers.utils.formatEther(balance),
)
console.log('Deploying gateway with the account:', deployer.address, ' balance:', ethers.utils.formatEther(balance))

const txArgs = await getTransactionFees()

Expand Down Expand Up @@ -96,12 +87,7 @@ export async function deploy(libs: { [key in string]: string }) {
]

for (const facet of facets) {
const facetInstance = await deployContractWithDeployer(
deployer,
facet.name,
facet.libs,
txArgs,
)
const facetInstance = await deployContractWithDeployer(deployer, facet.name, facet.libs, txArgs)
await facetInstance.deployed()

facet.address = facetInstance.address
Expand Down
28 changes: 4 additions & 24 deletions contracts/scripts/deploy-libraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,12 @@ export async function deploy() {

const txArgs = await getTransactionFees()

const { address: accountHelperAddress } = await deployContractWithDeployer(
deployer,
'AccountHelper',
{},
txArgs,
)
const { address: libStakingAddress } = await deployContractWithDeployer(
deployer,
'LibStaking',
{},
txArgs,
)
const { address: accountHelperAddress } = await deployContractWithDeployer(deployer, 'AccountHelper', {}, txArgs)
const { address: libStakingAddress } = await deployContractWithDeployer(deployer, 'LibStaking', {}, txArgs)

const { address: subnetIDHelperAddress } = await deployContractWithDeployer(
deployer,
'SubnetIDHelper',
{},
txArgs,
)
const { address: subnetIDHelperAddress } = await deployContractWithDeployer(deployer, 'SubnetIDHelper', {}, txArgs)

const { address: libQuorumAddress } = await deployContractWithDeployer(
deployer,
'LibQuorum',
{},
txArgs,
)
const { address: libQuorumAddress } = await deployContractWithDeployer(deployer, 'LibQuorum', {}, txArgs)

// nested libs
const { address: crossMsgHelperAddress } = await deployContractWithDeployer(
Expand Down
Loading