Problem Mock & package.json

This commit is contained in:
hoelee 2024-08-05 16:57:41 +08:00
parent 6e9c6dd633
commit 3ab5ee37c6
11 changed files with 128 additions and 1096 deletions

View File

@ -7,7 +7,7 @@
pragma solidity ^0.8.0;
import "./PriceConverter.sol";
// Save Gas - constant, immutable
// Save Gas by using constant, immutable for variables
error NotOwner();

View File

@ -6,10 +6,6 @@ import "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.so
// Why is this a library and not abstract?
// Why not an interface?
library PriceConverter {
// Sepolia ETH / USD Address
// https://docs.chain.link/data-feeds/price-feeds/addresses#Sepolia%20Testnet
//0x694AA1769357215DE4FAC081bf1f309aDC325306
// We could make this public, but then we'd have to deploy it
function getPrice(
AggregatorV3Interface priceFeed

View File

@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@chainlink/contracts/src/v0.8/tests/MockV3Aggregator.sol";
// Direct import from the github, located at local node_modules

View File

@ -1,9 +0,0 @@
// For Localhost, Hardhat, Ganache Without Price Feed To Get Price Feed
const { ethers, run, network } = require("hardhat");
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();
const chainId = network.config.chainId;
};

View File

@ -6,18 +6,28 @@ const { networkConfig } = require("../helper-hardhat-config");
const networkConfig = helperConfig.networkConfig;
*/
// main function
//function deployFunc() {
// const {getNamedAccounts, deployments} = hre;
// // Same as hre.getNamedAccounts & hre.deployments
//}
//module.exports.default = deployFunc;
/*
// main function that auto run via hardhat deploy
function deployFunc() {
const { getNamedAccounts, deployments } = hre; // Hardhat runtime environment
// Same as hre.getNamedAccounts & hre.deployments
console.log("Hello World!");
}
module.exports.default = deployFunc;
*/
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();
const { deployer } = await getNamedAccounts(); // Take from hardhat.config.js namedAccounts
const chainId = network.config.chainId;
if (networkConfig[chainId] === undefined) {
console.log("Is Not Testnet / Mainnet! No Mock Up...");
console.log(deployments);
const ethUsdAggregator = await deployments.get("MockV3Aggregator");
return;
}
const ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"];
// if contract doest't exist, we deploy a minimal version for our local testing

View File

@ -0,0 +1,33 @@
// For Localhost, Hardhat, Ganache Without Price Feed To Get Price Feed
const { ethers, run, network } = require("hardhat");
const {
developmentChains,
DECIMALS,
INITIAL_ANSWER,
} = require("../helper-hardhat-config");
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();
const chainId = network.config.chainId;
const networkName = network.name;
// Don't deploy mock contract to real blockchain with price feed
// Here can chekc with chainId as well
if (developmentChains.includes(networkName)) {
log("Local network '" + networkName + "', deploying mocks...");
/*
await deploy(MockV3Aggregator, {
contract: "MockV3Aggregator",
from: deployer,
log: true,
args: [DECIMALS, INITIAL_ANSWER],
});
*/
log("Mocks deployed!");
log("=====================================");
}
};
module.exports.tags = ["all", "mocks"];

View File

@ -7,7 +7,6 @@ require("dotenv").config();
require("./tasks/block-number");
require("hardhat-gas-reporter");
require("solidity-coverage");
require("ethereum-waffle");
require("hardhat-deploy");
const RPC_URL_SEPOLIA = process.env.SEPOLIA_RPC_URL || "https://eth-sepolia";
@ -63,7 +62,6 @@ module.exports = {
outputFile: "gas-report.txt",
noColors: true,
},
plugins: ["@nomiclabs/hardhat-waffle"],
namedAccounts: {
deployer: {
default: 0,

View File

@ -19,6 +19,13 @@ const networkConfig = {
},
};
const developmentChains = ["hardhat", "localhost"];
const DECIMALS = 8;
const INITIAL_ANSWER = 200000000000;
module.exports = {
networkConfig,
developmentChains,
DECIMALS,
INITIAL_ANSWER,
};

View File

@ -21,10 +21,10 @@
"@types/mocha": ">=9.1.0",
"chai": "^4.2.0",
"dotenv": "^16.4.5",
"ethereum-waffle": "^4.0.10",
"ethers": "^5.7.0",
"ethers": "^5.7.2",
"hardhat": "^2.22.7",
"hardhat-deploy": "^0.12.4",
"hardhat-deploy-ethers": "^0.4.2",
"hardhat-gas-reporter": "^1.0.8",
"prettier": "^3.3.3",
"prettier-plugin-solidity": "^1.3.1",

View File

@ -1,26 +1,11 @@
// imports
const { ethers, run, network } = require("hardhat");
const { exit } = require("process");
// async main
async function main() {
const verifyOnly = false;
if (verifyOnly == true) {
const address = "0xF90F7edF515001CD4293255bfaF7D17ffa415e91";
const ETHERSCAN_API_KEY_VERIFY = process.env.ETHERSCAN_API_KEY;
console.log("Network config:", network.config);
console.log("ChainId: " + network.config.chainId);
if (network.config.chainId === 11155111) {
console.log("Currently on Sepolia Testnet");
if (ETHERSCAN_API_KEY_VERIFY !== undefined) {
console.log("Verifying contract...");
await verify(address, []);
console.log("Verification complete");
} else {
console.log("ETHERSCAN_API_KEY is undefined");
}
}
if (true) return;
if (false) {
await runVerifyOnly("0xF90F7edF515001CD4293255bfaF7D17ffa415e91");
}
const simpleStorageFactory =
@ -85,6 +70,23 @@ async function verify(contractAddress, args) {
}
}
async function runVerifyOnly(address) {
const ETHERSCAN_API_KEY_VERIFY = process.env.ETHERSCAN_API_KEY;
console.log("Network config:", network.config);
console.log("ChainId: " + network.config.chainId);
if (network.config.chainId === 11155111) {
console.log("Currently on Sepolia Testnet");
if (ETHERSCAN_API_KEY_VERIFY !== undefined) {
console.log("Verifying contract...");
await verify(address, []);
console.log("Verification complete");
} else {
console.log("ETHERSCAN_API_KEY is undefined");
}
}
process.exit(1);
}
// main
main()
.then(() => process.getMaxListeners(0))

1095
yarn.lock

File diff suppressed because it is too large Load Diff