move just contract address data to its own file
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 32s Details

This commit is contained in:
Ladd Hoffman 2024-03-17 11:48:05 -05:00
parent d55a219dbb
commit 5fd2841e77
10 changed files with 52 additions and 28 deletions

View File

@ -11,8 +11,7 @@ import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
import Stack from 'react-bootstrap/Stack';
import { getContractByChainId } from 'contract-config';
import { getContractByChainId } from './contract-config';
import Web3Context from './Web3Context';
import DAOArtifact from './assets/DAO.json';
import work1Artifact from './assets/Work1.json';

View File

@ -2,8 +2,7 @@ import { useCallback, useContext } from 'react';
import { PropTypes } from 'prop-types';
import Button from 'react-bootstrap/Button';
import { getContractByChainId } from 'contract-config';
import { getContractByChainId } from './contract-config';
import Web3Context from './Web3Context';
const getAvailabilityStatus = (stake) => {

View File

@ -1,6 +1,6 @@
import contractAddresses from './addresses.json';
import contractAddresses from '../../contract-addresses.json';
export const networks = {
const networks = {
localhost: '0x539',
sepolia: '0xaa36a7',
};
@ -12,7 +12,7 @@ export const getContractByNetworkName = (networkName, contractName) => {
};
export const getContractByChainId = (chainId, contractName) => {
const network = Object.entries(networks).find(([_, id]) => id === chainId)[0];
const network = Object.entries(networks).find(([, id]) => id === chainId)[0];
if (!network) throw new Error(`Chain ID ${chainId} not recognized`);
return getContractByNetworkName(network, contractName);
};
};

View File

@ -1,11 +0,0 @@
{
"name": "contract-config",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

View File

@ -17,6 +17,7 @@
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.5",
"chai": "^4.4.1",
"contract-config": "file://../contract-config",
"eslint": "^8.57.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-chai-friendly": "^0.7.4",
@ -30,6 +31,11 @@
"prettier-plugin-solidity": "^1.3.1"
}
},
"../contract-config": {
"version": "1.0.0",
"dev": true,
"license": "ISC"
},
"node_modules/@aashutoshrathi/word-wrap": {
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz",
@ -3483,6 +3489,10 @@
"integrity": "sha512-JsPKdmh8ZkmnHxDk55FZ1TqVLvEQTvoByJZRN9jzI0UjxK/QgAmsphz7PGtqgPieQZ/CQcHWXCR7ATDNhGe+YA==",
"dev": true
},
"node_modules/contract-config": {
"resolved": "../contract-config",
"link": true
},
"node_modules/cookie": {
"version": "0.4.2",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",

View File

@ -11,6 +11,7 @@
"author": "",
"license": "ISC",
"devDependencies": {
"contract-config": "file://../contract-config",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.6",
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.5",

View File

@ -1,9 +1,5 @@
const { ethers } = require('hardhat');
const DAOAddress = {
localhost: '0x76Dfe9F47f06112a1b78960bf37d87CfbB6D6133',
sepolia: '0x39B7522Ee1A5B13aE5580C40114239D4cE0e7D29',
};
const { getContractByNetworkName } = require('./contract-config');
let dao;
let account;
@ -34,10 +30,8 @@ const fetchValidationPools = async () => {
const initialize = async () => {
const network = process.env.HARDHAT_NETWORK;
if (!DAOAddress[network]) {
throw new Error(`network '${network}' is unknown`);
}
dao = await ethers.getContractAt('DAO', DAOAddress[network]);
const DAOAddress = getContractByNetworkName(network, 'DAO');
dao = await ethers.getContractAt('DAO', DAOAddress);
[account] = await ethers.getSigners();
const address = await account.getAddress();
console.log(`account: ${address}`);

View File

@ -0,0 +1,23 @@
const contractAddresses = require('../../contract-addresses.json');
const networks = {
localhost: '0x539',
sepolia: '0xaa36a7',
};
const getContractByNetworkName = (networkName, contractName) => {
const address = contractAddresses[networkName][contractName];
if (!address) throw new Error(`Contract ${contractName} not recognized`);
return address;
};
const getContractByChainId = (chainId, contractName) => {
const network = Object.entries(networks).find(([, id]) => id === chainId)[0];
if (!network) throw new Error(`Chain ID ${chainId} not recognized`);
return getContractByNetworkName(network, contractName);
};
module.exports = {
getContractByChainId,
getContractByNetworkName,
};

View File

@ -1,16 +1,25 @@
const { ethers } = require('hardhat');
const fs = require('fs');
const contractAddresses = require('../../contract-addresses.json');
const network = process.env.HARDHAT_NETWORK;
async function main() {
const dao = await ethers.deployContract('DAO');
await dao.waitForDeployment();
console.log(`DAO deployed to ${dao.target}`);
contractAddresses[network].DAO = dao.target;
const WORK1_PRICE = ethers.parseEther('0.001');
const work1 = await ethers.deployContract('Work1', [dao.target, WORK1_PRICE]);
await work1.waitForDeployment();
console.log(`Work1 deployed to ${work1.target}`);
contractAddresses[network].Work1 = work1.target;
fs.writeFileSync('../../contract-addresses.json', JSON.stringify(contractAddresses, null, 2));
}
// We recommend this pattern to be able to use async/await everywhere