Skip to content

Commit

Permalink
feat: update contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
wellitongervickas committed Dec 8, 2023
1 parent f561298 commit 01311f5
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 116 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# accounts
ACCOUNTS_PRIVATE_KEY_1=""

ACCOUNTS_PRIVATE_KEY_2=""

# networks
PUBLIC_NETWORK_43113_HTTP_RPC=""
PUBLIC_NETWORK_420_HTTP_RPC=""
PUBLIC_NETWORK_80001_HTTP_RPC=""

# api keys
ETHERSCAN_API_KEY=""
AVALANCHE_FUJI_API_KEY=""
OPTIMISM_GOERLI_API_KEY=""
POLYGON_MUMBAI_API_KEY=""
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ Please, read [extra guides here](guides-examples.md).
## Networks

- Avalanche Fuji (43113)
- Mumbai (80001)

## Contracts

### Avalanche Fuji (43113)
### Avalanche fuji

- AccessManagement:
- Hub:
- [AccessManagement](https://testnet.snowtrace.dev/address/0xA77Bb3B4aC78198208922A6c919921b274be0F9c)
- [Hub](https://testnet.snowtrace.dev/address/0x68000Cd65cCCd59F5DB32e74115Ead44C391A391)

### Mumbai (80001)
### Mumbai

- AccessManagement:
- Hub:
- [AccessManagement](https://mumbai.polygonscan.com/address/0x52Ef16e646A21150b6f8D7A41F0D6A9483EC2196)
- [Hub](https://mumbai.polygonscan.com/address/0xf327D8cEEf6A89DF6081d046697842C7153e1B2c)

## Getting Started

Expand Down
22 changes: 12 additions & 10 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { Chain } from './config/types'
import { NetworksUserConfig } from 'hardhat/types'

const config: HardhatUserConfig = {
defaultNetwork: 'hardhat',

networks:
process.env.NODE_ENV !== 'development'
? reduce(
Expand Down Expand Up @@ -60,17 +62,17 @@ const config: HardhatUserConfig = {
// snowtrace: 'snowtrace'
}
// uncomment snowtrace if any issue with avalanche fuji
// customChains: [
// {
// network: 'snowtrace',
// chainId: 43113,
// urls: {
// apiURL:
// 'https://api.routescan.io/v2/network/testnet/evm/43113/etherscan',
// browserURL: 'https://avalanche.testnet.routescan.io'
// customChains: [
// {
// network: 'snowtrace',
// chainId: 43113,
// urls: {
// apiURL:
// 'https://api.routescan.io/v2/network/testnet/evm/43113/etherscan',
// browserURL: 'https://avalanche.testnet.routescan.io'
// }
// }
// }
// ]
// ]
}
}

Expand Down
93 changes: 53 additions & 40 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,59 @@ const spinner: Spinner = new Spinner(cliSpinner.triangle)
const main = async () => {
spinner.start()

console.log(`ℹ️ Deploying...`)
const { chainId } = await getNetwork()
console.log(`ℹ️ chainId: ${chainId}`)

const [owner] = await getSigners()
console.log(`ℹ️ owner: ${owner.address}`)

/// deploy access management contract

console.log(`ℹ️ Deploying access management...`)

const accessManagement = await deployContract(
'AccessManagement',
owner.address
)
const accessManagementAddress = await getContractAddress(accessManagement)
console.log(`✅ Access management deployed: ${accessManagementAddress}`)

// grant role to developer
console.log(`ℹ️ granting developer role...`)

const accessManagementContract = await getContractAt(
'AccessManagement',
accessManagementAddress
)

await accessManagementContract.grantRole(
DEVELOPER_ROLE,
owner.address,
DEVELOPER_ROLE_DELAY
)

console.log(`✅ developer role granted`)

// deploy hub contract
console.log(`ℹ️ Deploying hub...`)
const hubContract = await deployContract('Hub', accessManagementAddress)
const hubAddress = await getContractAddress(hubContract)
spinner.stop()
console.log(`✅ Hub deployed: ${hubAddress}`)
try {
console.log(`ℹ️ Deploying...`)
const { chainId } = await getNetwork()
console.log(`ℹ️ chainId: ${chainId}`)

const [owner] = await getSigners()
console.log(`ℹ️ owner: ${owner.address}`)

/// deploy access management contract

console.log(`ℹ️ Deploying access management...`)

const accessManagement = await deployContract(
'AccessManagement',
owner.address
)

await accessManagement.waitForDeployment()

const accessManagementAddress = await getContractAddress(accessManagement)
console.log(`✅ Access management deployed: ${accessManagementAddress}`)

// grant role to developer
console.log(`ℹ️ granting developer role...`)

const accessManagementContract = await getContractAt(
'AccessManagement',
accessManagementAddress
)

const tx = await accessManagementContract.grantRole(
DEVELOPER_ROLE,
owner.address,
DEVELOPER_ROLE_DELAY
)

await tx.wait()

console.log(`✅ developer role granted`)

// deploy hub contract
console.log(`ℹ️ Deploying hub...`)
const hubContract = await deployContract('Hub', accessManagementAddress)
await hubContract.waitForDeployment()

const hubAddress = await getContractAddress(hubContract)
spinner.stop()
console.log(`✅ Hub deployed: ${hubAddress}`)
} catch (error) {
spinner.stop()
console.log(error)
console.log(`❌ Hub deploy failed`)
}
}

main().catch((error) => {
Expand Down
84 changes: 61 additions & 23 deletions tasks/add-new-app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { task } from 'hardhat/config'
import { task, types } from 'hardhat/config'
import { Spinner } from '../scripts/spinner'
import cliSpinner from 'cli-spinners'
import { allowedChainsConfig } from '@/config/config'

const spinner: Spinner = new Spinner(cliSpinner.triangle)

Expand All @@ -9,43 +10,80 @@ export type AddNewAppTask = {
appAddress: string
name: string
description: string
accountIndex: number
}

task('add-new-app', 'Add new app to the hub')
.addParam('hubAddress', 'The address of the hub')
.addParam('appAddress', 'The address of the app')
.addParam('name', 'The name of the app')
.addParam('description', 'The description of the app')
.addOptionalParam(
'accountIndex',
'Account index to use for deployment',
0,
types.int
)
.setAction(
async (
{ hubAddress, appAddress, name, description }: AddNewAppTask,
{
hubAddress,
appAddress,
name,
description,
accountIndex
}: AddNewAppTask,
hre
) => {
spinner.start()

/// get hub contract
const hubContract = await hre.ethers.getContractAt('Hub', hubAddress)
try {
const chainConfig = allowedChainsConfig[+hre.network.name]
if (!chainConfig) {
spinner.stop()
throw new Error('Chain config not found')
}

// /// create payload
const payload = {
address: appAddress,
name,
description
} as {
address: string
name: string
description: string
}
const provider = new hre.ethers.JsonRpcProvider(
chainConfig.rpcUrls.default.http[0],
chainConfig.id
)

const deployer = new hre.ethers.Wallet(
chainConfig.accounts[accountIndex],
provider
)

console.log(`ℹ️ Adding app to hub...`)
const hubContract = await hre.ethers.getContractAt(
'Hub',
hubAddress,
deployer
)

/// call addApp with app
await hubContract.addApp(
payload.address,
payload.name,
payload.description
)
spinner.stop()
console.log(`✅ App ${name} added to hub ${hubAddress}`)
const payload = {
address: appAddress,
name,
description
} as {
address: string
name: string
description: string
}

console.log(`ℹ️ Adding app to hub...`)

await hubContract.addApp(
payload.address,
payload.name,
payload.description
)

spinner.stop()
console.log(`✅ App ${name} added to hub ${hubAddress}`)
} catch (error) {
spinner.stop()
console.log(error)
console.log(`❌ Add new app failed`)
}
}
)
57 changes: 47 additions & 10 deletions tasks/grant-role.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { task } from 'hardhat/config'
import { types, task } from 'hardhat/config'
import { Spinner } from '../scripts/spinner'
import cliSpinner from 'cli-spinners'
import { allowedChainsConfig } from '@/config/config'

const spinner: Spinner = new Spinner(cliSpinner.triangle)

export type SetFunctionRole = {
accessManagementAddress: string
targetAddress: string
role: number
accountIndex: number
}

task('grant-role', 'Set function role to target')
Expand All @@ -17,21 +19,56 @@ task('grant-role', 'Set function role to target')
)
.addParam('targetAddress', 'The address of the target contract')
.addParam('role', 'The role to set')
.addOptionalParam(
'accountIndex',
'Account index to use for deployment',
0,
types.int
)
.setAction(
async (
{ accessManagementAddress, targetAddress, role }: SetFunctionRole,
{
accessManagementAddress,
accountIndex,
targetAddress,
role
}: SetFunctionRole,
hre
) => {
spinner.start()

console.log(`ℹ️ Granting role ${role} to ${targetAddress}`)
const accessManagementContract = await hre.ethers.getContractAt(
'AccessManagement',
accessManagementAddress
)
try {
const chainConfig = allowedChainsConfig[+hre.network.name]

if (!chainConfig) {
spinner.stop()
throw new Error('Chain config not found')
}

const provider = new hre.ethers.JsonRpcProvider(
chainConfig.rpcUrls.default.http[0],
chainConfig.id
)

const deployer = new hre.ethers.Wallet(
chainConfig.accounts[accountIndex],
provider
)

console.log(`ℹ️ Granting role ${role} to ${targetAddress}`)
const accessManagementContract = await hre.ethers.getContractAt(
'AccessManagement',
accessManagementAddress,
deployer
)

await accessManagementContract.grantRole(role, targetAddress, 0)
spinner.stop()
console.log(`✅ Role ${role} granted to ${targetAddress}`)
await accessManagementContract.grantRole(role, targetAddress, 0)
spinner.stop()
console.log(`✅ Role ${role} granted to ${targetAddress}`)
} catch (error) {
spinner.stop()
console.log(error)
console.log(`❌ Grant role failed`)
}
}
)
Loading

0 comments on commit 01311f5

Please sign in to comment.