Skip to content

Commit

Permalink
feat: specify addresses in config generation instead of reading from …
Browse files Browse the repository at this point in the history
…deployments

Allows one to run config generation tool completely separate of importing
the ua-utils tool to the target repository.

Signed-off-by: Ryan Goulding <[email protected]>
  • Loading branch information
ryandgoulding committed Nov 30, 2023
1 parent ed2ada8 commit c737642
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 13 deletions.
66 changes: 66 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { HardhatUserConfig } from "hardhat/config";

import "./src/index"

// This adds support for typescript paths mappings
import "tsconfig-paths/register";

const config: HardhatUserConfig = {
networks: {
'sepolia-testnet': {
url: 'https://eth-sepolia.public.blastapi.io'
},
'bsc-testnet': {
url: 'https://data-seed-prebsc-1-s1.bnbchain.org:8545'
},
'avalanche-testnet': {
url: 'https://ava-testnet.public.blastapi.io/ext/bc/C/rpc'
},
'idex-testnet': {
url: 'https://rpc-devnet-idex.hardfork.dev'
},


'ethereum-mainnet': {
url: 'https://eth.llamarpc.com'
},
'bsc-mainnet': {
url: 'https://binance.llamarpc.com'
},
'avalanche-mainnet': {
url: 'https://api.avax.network/ext/bc/C/rpc'
},
'polygon-mainnet': {
url: 'https://polygon.llamarpc.com'
},
'arbitrum-mainnet': {
url: 'https://arbitrum.llamarpc.com'
},
'optimism-mainnet': {
url: 'https://mainnet.optimism.io'
},
'fantom-mainnet': {
url: 'https://fantom-mainnet.public.blastapi.io'
},
'base-mainnet': {
url: 'https://base.llamarpc.com'
},
'kava-mainnet': {
url: 'https://kava-evm.publicnode.com'
},
'mantle-mainnet': {
url: 'https://1rpc.io/mantle'
},
'metis-mainnet': {
url: 'https://metis-mainnet.public.blastapi.io'
},
'scroll-mainnet': {
url: 'https://rpc.scroll.io'
},
'zkconsensys-mainnet': {
url: 'https://1rpc.io/linea'
}
}
};

export default config;
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"name": "@layerzerolabs/ua-utils",
<<<<<<< Updated upstream
"version": "0.0.23",
=======
"version": "0.0.25",
>>>>>>> Stashed changes
"repository": "https://github.com/LayerZero-Labs/ua-utils.git",
"license": "MIT",
"main": "dist/index.js",
Expand Down
40 changes: 28 additions & 12 deletions src/generateAppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ interface DefaultConfigMesh {
[network: string]: ChainPathConfig
}

/**
* Input contracts configuration.
*/
type ContractConfigs = {
[network: string]: {
address: string,
}
}

/**
* Gets the remote config for a chain path.
* @param {string} remoteNetwork the remote network name
Expand Down Expand Up @@ -242,21 +251,22 @@ const getVersions = async(
/**
* Gets the default config for the mesh of networks.
* @param {HardhatRuntimeEnvironment} hre the hardhat runtime environment
* @param {string[]} networks the list of networks
* @param {ContractConfigs} configs the contract configs
* @param {string} name the name of the deployed UserApplication
* @param {string} checkConnectionFunctionFragment the checkConnection function fragment
*/
const generateAppConfig = async (
hre: HardhatRuntimeEnvironment,
networks: string[],
configs: ContractConfigs,
name: string,
checkConnectionFunctionFragment: string
): Promise<DefaultConfigMesh> => {
const networks = Object.keys(configs)
return (networks.reduce(async (acc, network: string) => {
const provider = getProvider(hre, network)
const endpointAddress = getEndpointAddress(network)
const endpoint = new ethers.Contract(endpointAddress, ENDPOINT_ABI, provider)
const address = getDeploymentAddress(network, name)
const address = configs[network].address
const { sendVersion, sendLibrary, receiveVersion, receiveLibrary } = await getVersions(endpoint, address, provider)
const remoteConfigs = await getRemoteConfigs(hre, network, address, networks, sendLibrary, receiveLibrary, checkConnectionFunctionFragment)
return {
Expand All @@ -265,6 +275,7 @@ const generateAppConfig = async (
name,
sendVersion,
receiveVersion,
address,
remoteConfigs,
}
}
Expand All @@ -275,12 +286,17 @@ const generateAppConfig = async (
//----------------------------------- HardHat Task Related -----------------------------------//
//--------------------------------------------------------------------------------------------//

/**
* Get networks array from provided csv argument.
* @param {string} networks
*/
const getNetworksFromArgs = (networks: string): string[] =>
networks.split(",")
const getContractConfigs = (inputNetworks: string, name: string): ContractConfigs => {
return inputNetworks.split(",").reduce((acc, inputNetwork) => {
const [key,value] = inputNetwork.split(":")
return {
...acc,
[key]: {
address: value ? value : getDeploymentAddress(key, name),
}
}
}, {})
}

/**
* Sanity check the output file name format.
Expand All @@ -307,9 +323,9 @@ export const generateAppConfigAction: ActionType<TaskArguments> = async (
taskArgs: GenerateDefaultConfigTaskArgs,
hre: HardhatRuntimeEnvironment
): Promise<void> => {
const { networks: csvNetworks, name, outputFileName, checkConnectionFunctionFragment } = taskArgs
const networks = getNetworksFromArgs(csvNetworks)
const { networks: inputNetworks, name, outputFileName, checkConnectionFunctionFragment } = taskArgs
const configs = getContractConfigs(inputNetworks, name)
checkOutputFileName(outputFileName)
const defaultConfigMesh = await generateAppConfig(hre, networks, name, checkConnectionFunctionFragment)
const defaultConfigMesh = await generateAppConfig(hre, configs, name, checkConnectionFunctionFragment)
await writeFile(outputFileName, JSON.stringify(defaultConfigMesh, null, 2))
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ task("getDefaultConfig", "outputs the default Send and Receive Messaging Library

task("generateAppConfig", "generates the config mesh for a User Application", generateAppConfigAction)
.addParam("networks", "comma separated list of networks")
.addParam('name', 'name of the deployed contract. Should be specified only if the deployment information is located in the deployments folder')
.addParam("name", "name of the deployed contract. Should be specified only if the deployment information is located in the deployments folder")
.addOptionalParam("outputFileName", "the path to the output file", "./constants/defaultConfig.json", types.string)
.addOptionalParam("checkConnectionFunctionFragment", "the checkConnection function fragment", LZ_APP_TRUSTED_REMOTE_LOOKUP_FUNCTION_FRAGMENT, types.string)

Expand Down

0 comments on commit c737642

Please sign in to comment.