Skip to content

Commit

Permalink
Merge pull request #10 from aragon/feat/update-config-to-use-commons-…
Browse files Browse the repository at this point in the history
…network-config

Feat: update hardhat config to use commons network config
  • Loading branch information
jordaniza committed Mar 14, 2024
2 parents a69b0b6 + 5ce3d51 commit 583d16f
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 33 deletions.
7 changes: 3 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# GENERAL

## The network used for testing purposes
NETWORK_NAME="sepolia" # ["mainnet", "sepolia", "polygon", "polygonMumbai", "base", "baseSepolia", "arbitrum", "arbitrumSepolia"]
NETWORK_NAME="sepolia" # ["mainnet", "sepolia", "polygon", "mumbai","baseMainnet", "baseGoerli", "baseSepolia", "arbitrum", "arbitrumSepolia"]

# CONTRACTS

## One or multiple hex encoded private keys separated by commas `,` replacing the hardhat default accounts.
PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" # Default hardhat account 0 private key. DON'T USE FOR DEPLOYMENTS

## Infura credentials
INFURA_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

## Alchemy RPC endpoint credentials
ALCHEMY_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
## Gas Reporting
REPORT_GAS='true'
COINMARKETCAP_API_KEY="zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/contracts-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ jobs:
- name: 'Build the contracts'
run: 'yarn build'
env:
INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}

- name: 'Test the contracts and generate the coverage report'
run: 'yarn coverage'
env:
INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/subgraph-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
working-directory: packages/subgraph
env:
SUBGRAPH_NETWORK_NAME: ${{ vars.SUBGRAPH_NETWORK_NAME }}
INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}

- name: 'Test the subgraph'
run: yarn test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ yarn lint

To be able to work on the contracts, make sure that you have created an `.env` file from the `.env.example` file and put in the API keys for

- [Infura](https://www.infura.io/) that we use as the web3 provider
- [Alchemy](https://www.alchemy.com) that we use as the web3 provider
- [Alchemy Subgraphs](https://www.alchemy.com/subgraphs) that we use as the subgraph provider
- the block explorer that you want to use depending on the networks that you want to deploy to

Expand Down
29 changes: 14 additions & 15 deletions packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
NetworkConfigs,
NetworkConfig,
networks,
addRpcUrlToNetwork,
networks as osxCommonsConfigNetworks,
SupportedNetworks,
} from '@aragon/osx-commons-configs';
import '@nomicfoundation/hardhat-chai-matchers';
Expand All @@ -18,14 +17,18 @@ import {
HardhatNetworkAccountsUserConfig,
HardhatRuntimeEnvironment,
} from 'hardhat/types';
import type {NetworkUserConfig} from 'hardhat/types';
import {resolve} from 'path';
import 'solidity-coverage';

const dotenvConfigPath: string = process.env.DOTENV_CONFIG_PATH || '../../.env';
dotenvConfig({path: resolve(__dirname, dotenvConfigPath), override: true});

if (!process.env.INFURA_API_KEY) {
throw new Error('INFURA_API_KEY in .env not set');
// check alchemy Api key existence
if (process.env.ALCHEMY_API_KEY) {
addRpcUrlToNetwork(process.env.ALCHEMY_API_KEY);
} else {
throw new Error('ALCHEMY_API_KEY in .env not set');
}

// Fetch the accounts specified in the .env file
Expand Down Expand Up @@ -56,26 +59,22 @@ function getHardhatNetworkAccountsConfig(

const accountsConfig: HardhatNetworkAccountsUserConfig = accounts.map(
privateKey => {
const oneEther = BigNumber.from(10).pow(18);
const hundredEther = BigNumber.from(100).pow(18);
return {
privateKey,
balance: oneEther.mul(1000).toString(),
balance: hundredEther.mul(1000).toString(),
};
}
);

return accountsConfig;
}

type HardhatNetworksExtension = NetworkConfig & {
accounts?: string[];
};

// Add the accounts specified in the `.env` file to the networks from osx-commons-configs
const osxCommonsConfigNetworks: NetworkConfigs<HardhatNetworksExtension> =
networks;
const networks: {[index: string]: NetworkUserConfig} = osxCommonsConfigNetworks;

for (const network of Object.keys(networks) as SupportedNetworks[]) {
osxCommonsConfigNetworks[network].accounts = specifiedAccounts();
networks[network].accounts = specifiedAccounts();
}

// Extend HardhatRuntimeEnvironment
Expand Down Expand Up @@ -110,7 +109,7 @@ const config: HardhatUserConfig = {
Object.keys(namedAccounts).length
),
},
...osxCommonsConfigNetworks,
...networks,
},

defaultNetwork: 'hardhat',
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@openzeppelin/contracts-upgradeable": "^4.9.5"
},
"devDependencies": {
"@aragon/osx-commons-configs": "0.1.0",
"@aragon/osx-commons-configs": "0.4.0",
"@aragon/osx-ethers": "1.4.0-alpha.0",
"@aragon/osx-commons-sdk": "0.0.1-alpha.5",
"@aragon/osx-v1.0.0": "npm:@aragon/osx@1.0.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
resolved "https://registry.yarnpkg.com/@aragon/osx-artifacts/-/osx-artifacts-1.3.1.tgz#68fa04844086a92d74351df2e9392ade3c8696dc"
integrity sha512-u6IFP8fQZIS65Ks5Sl1DKlw8Qp9s5I7DSn9n/odQohWnN65A17HwHaCPTEcXl2AL3r71rFawldQ8i5/2yU3UGA==

"@aragon/osx-commons-configs@0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@aragon/osx-commons-configs/-/osx-commons-configs-0.1.0.tgz#21bbc5a964eb144e30033a44cc352d35c62982f9"
integrity sha512-qTs/loihwqALBGmhZngORb+p7pjuQJY5UEd8TLNiEW/BGHEpAJPp4GeQu7GSnigRGEKWpPD5W96kfEsaPtLkuQ==
"@aragon/osx-commons-configs@0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@aragon/osx-commons-configs/-/osx-commons-configs-0.4.0.tgz#5b6ae025de1ccf7f9a135bfbcb0aa822c774acf9"
integrity sha512-/2wIQCbv/spMRdOjRXK0RrXG1TK5aMcbD73RvMgMwQwSrKcA1dCntUuSxmTm2W8eEtOzs8E1VPjqZk0cXL4SSQ==
dependencies:
tslib "^2.6.2"

Expand Down
2 changes: 1 addition & 1 deletion packages/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"matchstick-as": "^0.5.2",
"mustache": "^4.2.0",
"@aragon/osx-ethers": "1.4.0-alpha.0",
"@aragon/osx-commons-configs": "0.2.0",
"@aragon/osx-commons-configs": "0.4.0",
"ts-morph": "^17.0.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
Expand Down
8 changes: 4 additions & 4 deletions packages/subgraph/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@aragon/osx-commons-configs@0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@aragon/osx-commons-configs/-/osx-commons-configs-0.2.0.tgz#32f83596f4a2e9e48aef61cf560c1c5b4d32a049"
integrity sha512-wCFtgmuGCzs8L5mCxVCYQ6uEu69IrofS7q2w7E1Fjk7/nWuSmRUpgmif3ki9BQq1qpOvDu2P+u3UNLnIz8J82g==
"@aragon/osx-commons-configs@0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@aragon/osx-commons-configs/-/osx-commons-configs-0.4.0.tgz#5b6ae025de1ccf7f9a135bfbcb0aa822c774acf9"
integrity sha512-/2wIQCbv/spMRdOjRXK0RrXG1TK5aMcbD73RvMgMwQwSrKcA1dCntUuSxmTm2W8eEtOzs8E1VPjqZk0cXL4SSQ==
dependencies:
tslib "^2.6.2"

Expand Down

0 comments on commit 583d16f

Please sign in to comment.