generated from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mock contracts and start work on price feed page
- Loading branch information
1 parent
5b2c68d
commit 5ca024e
Showing
17 changed files
with
1,504 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.7; | ||
|
||
// Import the AggregatorV3Interface from the "@chainlink/contracts" package | ||
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; | ||
|
||
|
||
/** | ||
* | ||
* | ||
*/ | ||
|
||
contract PriceFeedConsumer { | ||
// Declare state variable of type AggregatorV3Interface | ||
AggregatorV3Interface internal immutable i_priceFeed; | ||
|
||
// Create a constructor that accepts the address of the price feed as an argument | ||
constructor(address priceFeedAddress) { | ||
i_priceFeed = AggregatorV3Interface(priceFeedAddress); | ||
} | ||
|
||
// Create a function to get the latest price | ||
function getLatestPrice() public view returns (int) { | ||
(, int price, , , ) = i_priceFeed.latestRoundData(); | ||
return price; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@chainlink/contracts/src/v0.8/tests/MockV3Aggregator.sol"; | ||
|
||
|
||
/** | ||
* @dev Mock contract implementation of AggregatorV3Interface | ||
* allows for testing and debugging on local network | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.7; | ||
|
||
import "@chainlink/contracts/src/v0.8/mocks/VRFCoordinatorV2Mock.sol"; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { DeployFunction } from "hardhat-deploy/types"; | ||
import { developmentChains } from "../helper-hardhat-config"; | ||
import { network } from "hardhat"; | ||
|
||
/** | ||
* Deploys mock contracts necessary for testing on local networks | ||
* | ||
* @param hre HardhatRuntimeEnvironment object. | ||
*/ | ||
|
||
const deployMocks: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
const { deployer } = await hre.getNamedAccounts(); | ||
const { deploy, log } = hre.deployments; | ||
const { ethers } = hre; | ||
|
||
// MockV3Aggregator constructor arguments | ||
const INTIIAL_PRICE = ethers.utils.parseUnits("1579", 8); // sets MockV3Aggregator.latestRoundData().answer | ||
const DECIMALS = "8"; | ||
|
||
// Chainlink VRF Coordinator constructor arguments | ||
const BASE_FEE = ethers.utils.parseEther("0.25"); // 0.25 is the premium. It costs 0.25 LINK per request | ||
const GAS_PRICE_LINK = 1e9; // calculated value based on the gas price of the chain | ||
|
||
if (developmentChains.includes(network.name)) { | ||
log("Local network detected... Deploying mocks..."); | ||
|
||
log("Deploying MockV3Aggregator..."); | ||
await deploy("MockV3Aggregator", { | ||
from: deployer, | ||
log: true, | ||
args: [DECIMALS, INTIIAL_PRICE], | ||
}); | ||
|
||
log("Deploying VRFCoordinatorV2Mock..."); | ||
await deploy("VRFCoordinatorV2Mock", { | ||
from: deployer, | ||
log: true, | ||
args: [BASE_FEE, GAS_PRICE_LINK], | ||
}); | ||
log("Mock contracts successfully deployed on local network!"); | ||
log("------------------------------------"); | ||
} | ||
}; | ||
|
||
export default deployMocks; | ||
|
||
// Tags are useful if you have multiple deploy files and only want to run one of them. | ||
// e.g. yarn deploy --tags YourContract | ||
deployMocks.tags = ["all", "mocks"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { DeployFunction } from "hardhat-deploy/types"; | ||
import { developmentChains, networkConfig } from "../helper-hardhat-config"; | ||
import { network } from "hardhat"; | ||
|
||
/** | ||
* Deploy PriceFeedConsumer contract | ||
* | ||
* @param hre HardhatRuntimeEnvironment object. | ||
*/ | ||
const deployPriceFeedConsumer: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
const { deployer } = await hre.getNamedAccounts(); | ||
const { deploy, log } = hre.deployments; | ||
const { ethers } = hre; | ||
|
||
// const chainId = network.config.chainId; | ||
const chainId = await hre.ethers.provider.getNetwork().then(network => network.chainId); | ||
console.log(`The current chain ID is: ${chainId}`); | ||
|
||
log("------------------------------------"); | ||
let priceFeedAddress: string | undefined; | ||
|
||
if (developmentChains.includes(network.name)) { | ||
// use mock address if on local network | ||
const MockV3Aggregator = await ethers.getContract("MockV3Aggregator"); | ||
priceFeedAddress = MockV3Aggregator.address; | ||
} else { | ||
// use address from helper-hardhat-config if on testnet or live network | ||
priceFeedAddress = networkConfig[chainId].priceFeeds?.ETH_USD; | ||
} | ||
|
||
const args = [priceFeedAddress]; | ||
await deploy("PriceFeedConsumer", { | ||
from: deployer, | ||
args: args, | ||
log: true, | ||
autoMine: true, | ||
}); | ||
|
||
// * HOW TO VERIFY : https://docs.scaffoldeth.io/deploying/deploy-smart-contracts#4-verify-your-smart-contract | ||
}; | ||
|
||
export default deployPriceFeedConsumer; | ||
|
||
deployPriceFeedConsumer.tags = ["price-consumer", "all"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
interface NetworkConfigEntryTypes { | ||
name?: string; | ||
vrfCoordinatorV2?: string; | ||
subscriptionId?: string; | ||
gasLane?: string; | ||
callbackGasLimit?: string; | ||
interval?: string; | ||
mintFee?: string; | ||
priceFeeds?: { | ||
BTC_USD: string; | ||
ETH_USD: string; | ||
LINK_USD: string; | ||
}; | ||
} | ||
|
||
const networkConfig: { [key: number]: NetworkConfigEntryTypes } = { | ||
31337: { | ||
name: "hardhat", | ||
gasLane: "0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c", | ||
interval: "30", | ||
callbackGasLimit: "500000", // 500,000 gas | ||
mintFee: "100000000000000000", // 0.1 ETH | ||
}, | ||
11155111: { | ||
name: "sepolia", | ||
vrfCoordinatorV2: "0x8103B0A8A00be2DDC778e6e7eaa21791Cd364625", | ||
subscriptionId: "4707", // vrf.chain.link/sepolia/4707 | ||
gasLane: "0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c", | ||
callbackGasLimit: "500000", // 500,000 | ||
interval: "30", | ||
mintFee: "100000000000000000", // 0.1 ETH | ||
priceFeeds: { | ||
BTC_USD: "0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43", | ||
ETH_USD: "0x694AA1769357215DE4FAC081bf1f309aDC325306", | ||
LINK_USD: "0xc59E3633BAAC79493d908e63626716e204A45EdF", | ||
}, | ||
}, | ||
}; | ||
|
||
const developmentChains: string[] = ["hardhat", "localhost"]; | ||
|
||
export { networkConfig, developmentChains }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ArrowTopRightOnSquareIcon } from "@heroicons/react/24/outline"; | ||
|
||
interface ExternalLinkProps { | ||
href: string; | ||
text: string; | ||
} | ||
|
||
export const ExternalLink: React.FC<ExternalLinkProps> = ({ href, text }) => { | ||
return ( | ||
<a href={href} className="capitalize text-accent hover:underline" target="_blank" rel="noopener noreferrer"> | ||
{text} <ArrowTopRightOnSquareIcon className="h-5 w-5 inline mb-1" /> | ||
</a> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.