smartcontractkit / chainlink-brownie-contracts

A repository for automatically using the latest chainlink repo from the core chainlink repo.
303 stars 65 forks source link

[FundMe] could not import AggregatorV3Interface #35

Open neelesh004 opened 1 month ago

neelesh004 commented 1 month ago

THIS IS MY ERROR

akashneelesh@Akashs-MacBook-Air foundry-fund-me-f24 % forge build
[⠊] Compiling...
[⠒] Compiling 3 files with Solc 0.8.26
[⠢] Solc 0.8.26 finished in 25.44ms
Error: 
Compiler run failed:
Error (6275): Source "lib/chainlink-brownie-contracts/contracts/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol" not found: File not found. Searched the following locations: "/Users/akashneelesh/foundry-simple-storage-f24/foundry-fund-me-f24".
ParserError: Source "lib/chainlink-brownie-contracts/contracts/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol" not found: File not found. Searched the following locations: "/Users/akashneelesh/foundry-simple-storage-f24/foundry-fund-me-f24".
 --> src/FundMe.sol:6:1:
  |
6 | import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Error (6275): Source "lib/chainlink-brownie-contracts/contracts/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol" not found: File not found. Searched the following locations: "/Users/akashneelesh/foundry-simple-storage-f24/foundry-fund-me-f24".
ParserError: Source "lib/chainlink-brownie-contracts/contracts/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol" not found: File not found. Searched the following locations: "/Users/akashneelesh/foundry-simple-storage-f24/foundry-fund-me-f24".
 --> src/PriceConverter.sol:4:1:
  |
4 | import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

THIS IS MY CODING

  // SPDX-License-Identifier: MIT
// 1. Pragma
pragma solidity 0.8.26;
// 2. Imports

import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol";
import {PriceConverter} from "./PriceConverter.sol";

// 3. Interfaces, Libraries, Contracts
error FundMe__NotOwner();

/**
 * @title A sample Funding Contract
 * @author Patrick Collins
 * @notice This contract is for creating a sample funding contract
 * @dev This implements price feeds as our library
 */
contract FundMe {
    // Type Declarations
    using PriceConverter for uint256;

    // State variables
    uint256 public constant MINIMUM_USD = 5 * 10 ** 18;
    address private immutable i_owner;
    address[] private s_funders;
    mapping(address => uint256) private s_addressToAmountFunded;
    AggregatorV3Interface private s_priceFeed;

    // Events (we have none!)

    // Modifiers
    modifier onlyOwner() {
        // require(msg.sender == i_owner);
        if (msg.sender != i_owner) revert FundMe__NotOwner();
        _;
    }

    // Functions Order:
    //// constructor
    //// receive
    //// fallback
    //// external
    //// public
    //// internal
    //// private
    //// view / pure

    constructor(address priceFeed) {
        s_priceFeed = AggregatorV3Interface(priceFeed);
        i_owner = msg.sender;
    }

    /// @notice Funds our contract based on the ETH/USD price
    function fund() public payable {
        require(
            msg.value.getConversionRate(s_priceFeed) >= MINIMUM_USD,
            "You need to spend more ETH!"
        );
        // require(PriceConverter.getConversionRate(msg.value) >= MINIMUM_USD, "You need to spend more ETH!");
        s_addressToAmountFunded[msg.sender] += msg.value;
        s_funders.push(msg.sender);
    }

    function withdraw() public onlyOwner {
        for (
            uint256 funderIndex = 0;
            funderIndex < s_funders.length;
            funderIndex++
        ) {
            address funder = s_funders[funderIndex];
            s_addressToAmountFunded[funder] = 0;
        }
        s_funders = new address[](0);
        // Transfer vs call vs Send
        // payable(msg.sender).transfer(address(this).balance);
        (bool success, ) = i_owner.call{value: address(this).balance}("");
        require(success);
    }

    function cheaperWithdraw() public onlyOwner {
        address[] memory funders = s_funders;
        // mappings can't be in memory, sorry!
        for (
            uint256 funderIndex = 0;
            funderIndex < funders.length;
            funderIndex++
        ) {
            address funder = funders[funderIndex];
            s_addressToAmountFunded[funder] = 0;
        }
        s_funders = new address[](0);
        // payable(msg.sender).transfer(address(this).balance);
        (bool success, ) = i_owner.call{value: address(this).balance}("");
        require(success);
    }

    /**
     * Getter Functions
     */

    /**
     * @notice Gets the amount that an address has funded
     *  @param fundingAddress the address of the funder
     *  @return the amount funded
     */
    function getAddressToAmountFunded(
        address fundingAddress
    ) public view returns (uint256) {
        return s_addressToAmountFunded[fundingAddress];
    }

    function getVersion() public view returns (uint256) {
        return s_priceFeed.version();
    }

    function getFunder(uint256 index) public view returns (address) {
        return s_funders[index];
    }

    function getOwner() public view returns (address) {
        return i_owner;
    }

    function getPriceFeed() public view returns (AggregatorV3Interface) {
        return s_priceFeed;
    }
}