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.
impliment AggregatorV3Consumer front end
- Loading branch information
1 parent
5ca024e
commit 26aea23
Showing
18 changed files
with
418 additions
and
272 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 |
---|---|---|
@@ -1,78 +1,27 @@ | ||
# 🏗 Scaffold-ETH 2 | ||
# Scaffold Chainlink | ||
|
||
<h4 align="center"> | ||
<a href="https://docs.scaffoldeth.io">Documentation</a> | | ||
<a href="https://scaffoldeth.io">Website</a> | ||
</h4> | ||
## Getting Started | ||
|
||
🧪 An open-source, up-to-date toolkit for building decentralized applications (dapps) on the Ethereum blockchain. It's designed to make it easier for developers to create and deploy smart contracts and build user interfaces that interact with those contracts. | ||
|
||
⚙️ Built using NextJS, RainbowKit, Hardhat, Wagmi, and Typescript. | ||
|
||
- ✅ **Contract Hot Reload**: Your frontend auto-adapts to your smart contract as you edit it. | ||
- 🔥 **Burner Wallet & Local Faucet**: Quickly test your application with a burner wallet and local faucet. | ||
- 🔐 **Integration with Wallet Providers**: Connect to different wallet providers and interact with the Ethereum network. | ||
|
||
![Debug Contracts tab](https://github.com/scaffold-eth/scaffold-eth-2/assets/55535804/1171422a-0ce4-4203-bcd4-d2d1941d198b) | ||
|
||
## Requirements | ||
|
||
Before you begin, you need to install the following tools: | ||
|
||
- [Node (v18 LTS)](https://nodejs.org/en/download/) | ||
- Yarn ([v1](https://classic.yarnpkg.com/en/docs/install/) or [v2+](https://yarnpkg.com/getting-started/install)) | ||
- [Git](https://git-scm.com/downloads) | ||
|
||
## Quickstart | ||
|
||
To get started with Scaffold-ETH 2, follow the steps below: | ||
|
||
1. Clone this repo & install dependencies | ||
1. Install dependencies | ||
|
||
``` | ||
git clone https://github.com/scaffold-eth/scaffold-eth-2.git | ||
cd scaffold-eth-2 | ||
yarn install | ||
``` | ||
|
||
2. Run a local network in the first terminal: | ||
2. Deploy the contracts on sepolia network. You will need funds in the deployer account. Visit the [sepolia faucet](https://sepoliafaucet.com/) and set up your .env file in the `packages/hardhat/` folder OR use `yarn generate` and send sepolia ETH to the generated address. | ||
|
||
``` | ||
yarn chain | ||
yarn deploy --network sepolia | ||
``` | ||
|
||
This command starts a local Ethereum network using Hardhat. The network runs on your local machine and can be used for testing and development. You can customize the network configuration in `hardhat.config.ts`. | ||
|
||
3. On a second terminal, deploy the test contract: | ||
|
||
``` | ||
yarn deploy | ||
``` | ||
|
||
This command deploys a test smart contract to the local network. The contract is located in `packages/hardhat/contracts` and can be modified to suit your needs. The `yarn deploy` command uses the deploy script located in `packages/hardhat/deploy` to deploy the contract to the network. You can also customize the deploy script. | ||
|
||
4. On a third terminal, start your NextJS app: | ||
3. Start the frontend | ||
|
||
``` | ||
yarn start | ||
``` | ||
|
||
Visit your app on: `http://localhost:3000`. You can interact with your smart contract using the contract component or the example ui in the frontend. You can tweak the app config in `packages/nextjs/scaffold.config.ts`. | ||
|
||
Run smart contract test with `yarn hardhat:test` | ||
|
||
- Edit your smart contract `YourContract.sol` in `packages/hardhat/contracts` | ||
- Edit your frontend in `packages/nextjs/pages` | ||
- Edit your deployment scripts in `packages/hardhat/deploy` | ||
|
||
## Documentation | ||
|
||
Visit our [docs](https://docs.scaffoldeth.io) to learn how to start building with Scaffold-ETH 2. | ||
|
||
To know more about its features, check out our [website](https://scaffoldeth.io). | ||
|
||
## Contributing to Scaffold-ETH 2 | ||
4. Fund the VRFConsumer and AutomationConsumer contracts with LINK (create subscription?) | ||
|
||
We welcome contributions to Scaffold-ETH 2! | ||
## Testing | ||
|
||
Please see [CONTRIBUTING.MD](https://github.com/scaffold-eth/scaffold-eth-2/blob/main/CONTRIBUTING.md) for more information and guidelines for contributing to Scaffold-ETH 2. | ||
- For local testing mock contracts have been included and configured in the deploy scripts |
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,46 @@ | ||
// 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"; | ||
|
||
/** | ||
* @dev the price feed address passed to constructor during deployment determines the asset pair | ||
* @notice https://docs.chain.link/data-feeds/price-feeds/addresses?network=ethereum&page=1 | ||
*/ | ||
contract PriceFeedConsumer { | ||
// Declare state variable of type AggregatorV3Interface | ||
AggregatorV3Interface internal immutable i_priceFeed; | ||
|
||
// Instatiate the state varible using any given price feed address | ||
constructor(address priceFeedAddress) { | ||
i_priceFeed = AggregatorV3Interface(priceFeedAddress); | ||
} | ||
|
||
// Get the latest price from the price feed contract | ||
function getLatestPrice() public view returns (int) { | ||
( | ||
/* uint80 roundID */, | ||
int answer, | ||
/*uint startedAt*/, | ||
/*uint timeStamp*/, | ||
/*uint80 answeredInRound*/ | ||
) = i_priceFeed.latestRoundData(); | ||
return answer; | ||
} | ||
|
||
// The number of decimals in the response | ||
function getDecimals() public view returns (uint8) { | ||
return i_priceFeed.decimals(); | ||
} | ||
|
||
// The description of the aggregator i.e. "ETH / USD" | ||
function getDescription() public view returns (string memory) { | ||
return i_priceFeed.description(); | ||
} | ||
|
||
// The version of the aggregator | ||
function getVersion() public view returns (uint256) { | ||
return i_priceFeed.version(); | ||
} | ||
} |
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,51 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.7; | ||
|
||
import "@chainlink/contracts/src/v0.8/interfaces/FeedRegistryInterface.sol"; | ||
import "@chainlink/contracts/src/v0.8/Denominations.sol"; | ||
|
||
/**Contract to consume the Chainlink FeedRegistry | ||
* | ||
* @notice FeedRegistry address only exists on the Ethereum Mainnet | ||
*/ | ||
contract FeedRegistryConsumer { | ||
|
||
FeedRegistryInterface internal immutable i_registry; | ||
|
||
constructor(address registryAddress) { | ||
i_registry = FeedRegistryInterface(registryAddress); | ||
} | ||
|
||
/** | ||
* Get the latest price of ETH/USD | ||
*/ | ||
function getEthUsdPrice() public view returns (int) { | ||
( | ||
/*uint80 roundID*/, | ||
int price, | ||
/*uint startedAt*/, | ||
/*uint timeStamp*/, | ||
/*uint80 answeredInRound*/ | ||
) = i_registry.latestRoundData(Denominations.ETH, Denominations.USD); | ||
return price; | ||
} | ||
|
||
/** General method capable of returning the relative price of any available asset pair | ||
* | ||
* @param base any denomination from the library or a valid ERC20 token address | ||
* @param quote the quote denomination from the Denominations library or a valid ERC20 token address | ||
*/ | ||
|
||
function getPrice(address base, address quote) public view returns (int) { | ||
// prettier-ignore | ||
( | ||
/*uint80 roundID*/, | ||
int price, | ||
/*uint startedAt*/, | ||
/*uint timeStamp*/, | ||
/*uint80 answeredInRound*/ | ||
) = i_registry.latestRoundData(base, quote); | ||
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
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,34 @@ | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { DeployFunction } from "hardhat-deploy/types"; | ||
|
||
/** | ||
* Deploy PriceFeedConsumer contract | ||
* | ||
* @param hre HardhatRuntimeEnvironment object. | ||
*/ | ||
const deployRegistryFeedConsumer: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
const { deployer } = await hre.getNamedAccounts(); | ||
const { deploy, log } = hre.deployments; | ||
|
||
const chainId = await hre.ethers.provider.getNetwork().then(network => network.chainId); | ||
|
||
log("------------------------------------"); | ||
|
||
// FeedRegistry only available on ethereum mainnet | ||
if (chainId === 1) { | ||
const registryFeedAddress = "0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf"; | ||
const args = [registryFeedAddress]; | ||
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 deployRegistryFeedConsumer; | ||
|
||
deployRegistryFeedConsumer.tags = ["registry", "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
Oops, something went wrong.