0

Lottery.sol file
" CompilerError: solc returned the following errors:

"contracts/Lottery.sol:4:1: ParserError: Source "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol" not found: File outside of allowed directories. import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol"; ^--------------------------------------------------------------------------^

contracts/Lottery.sol:5:1: ParserError: Source "@openzeppelin/contracts/access/Ownable.sol" not found: File outside of allowed directories. import "@openzeppelin/contracts/access/Ownable.sol"; ^--------------------------------------------------^"

// SPDX-License-Identifier: MIT
    pragma solidity ^0.6.6;
    
    import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
    import "@openzeppelin/contracts/access/Ownable.sol";
    
    contract Lottery is Ownable {
        address payable[] public players;
        uint256 public usdEntryFee;
        AggregatorV3Interface internal ethUsdPriceFeed;
        enum LOTTERY_STATE {
            OPEN,
            CLOSED,
            CALCULATING_WINNER
        }
        LOTTERY_STATE public lottery_state;
        // OPEN = 0
        //CLOSED = 1
        //CALCULATING_WINNER = 2
    
        LOTTERY_STATE public lottery_state;
    
        constructor(address _priceFeedAddress) public {
            usdEntryFee = 50 * (10**18);
            ethUsdPriceFeed = AggregatorV3Interface(_priceFeedAddress);
            lottery_state = LOTTERY_STATE.CLOSED; // or "lottery_state = 1;
        }
    
        function enter() public {
            // $50 minimum
            require(lottery_state == LOTTERY_STATE.OPEN); // or lottery_state == 0;
            require(msg.sender >= getEntranceFee(), "Not enough ETH!");
            players.push(msg.sender);
        }
    
        function getEntranceFee() public view returns (uint256) {
            (, int256 price, , , ) = ethUsdPriceFeed.latestRoundData();
            uint256 adjustedPrice = uint256(price) * 10**10; //18 decimals
            //50, 2000 / ETH
            // 50/2,000
            //50 * 100000 / 2000
            uint256 costToEnter = (usdEntryFee * 10**18) / adjustedPrice;
            return costToEnter;
        }
    
        function startLottery() public onlyOwner {
            require(
                lottery_state == LOTTERY_STATE.CLOSED,
                "Can't start a new lottery yet!"
            );
            lottery_state = LOTTERY_STATE.OPEN;
        }
    
        function endLottery() public {
            //require(lottery_state == 50.000, "The winner is 50.000");
            //lottery_state = LOTTERY_STATE.CALCULATING_WINNER;
        }
    }

brownie-config.yaml file

dependecies: 
  - smartcontractgit/[email protected]
  - OpenZeppelin/[email protected] // the error is probably here
compile:
  solc:
    remappings:
      - '@chainlink=smartcontractkit/[email protected]'
      - '@openzeppelin=OpenZeppelin/[email protected]' // The error can be here
       
networks: 
   mainnet-fork: 
    eth_usd_price_feed: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419'

1 Answer 1

0

The problem is in the .yaml.

The dependencies don't match the remappings. The following should work.

dependecies: 
  -  smartcontractkit/[email protected] //error was here
  - OpenZeppelin/[email protected] 
compiler: // The error was also here
  solc:
    remappings:
      - '@chainlink=smartcontractkit/[email protected]'
      - '@openzeppelin=OpenZeppelin/[email protected]'

After this you will get a few errors on your contract logic but the dependencies will be fixed.

In your contract you declare twice the variable auction_state, delete one of them. Also, the enter() function must be payable public since it recives eth. You should change msg.sender for msg.value. Those changes will get your contract compiled. I'll copy the compilable contract.

// SPDX-License-Identifier: MIT
    pragma solidity ^0.6.6;
    
    import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
    import "@openzeppelin/contracts/access/Ownable.sol";
    
    contract Lottery is Ownable {
        address payable[] public players;
        uint256 public usdEntryFee;
        AggregatorV3Interface internal ethUsdPriceFeed;

        enum LOTTERY_STATE {
            OPEN,
            CLOSED,
            CALCULATING_WINNER
        }

        // OPEN = 0
        //CLOSED = 1
        //CALCULATING_WINNER = 2
    
        LOTTERY_STATE public lottery_state;
    
        constructor(address _priceFeedAddress) public {
            usdEntryFee = 50 * (10**18);
            ethUsdPriceFeed = AggregatorV3Interface(_priceFeedAddress);
            lottery_state = LOTTERY_STATE.CLOSED; // or "lottery_state = 1;
        }
    
        function enter() payable public {
            // $50 minimum
            require(lottery_state == LOTTERY_STATE.OPEN); // or lottery_state == 0;
            require(msg.value >= getEntranceFee(), "Not enough ETH!");
            players.push(msg.sender);
        }
    
        function getEntranceFee() public view returns (uint256) {
            (, int256 price, , , ) = ethUsdPriceFeed.latestRoundData();
            uint256 adjustedPrice = uint256(price) * 10**10; //18 decimals
            //50, 2000 / ETH
            // 50/2,000
            //50 * 100000 / 2000
            uint256 costToEnter = (usdEntryFee * 10**18) / adjustedPrice;
            return costToEnter;
        }
    
        function startLottery() public onlyOwner {
            require(
                lottery_state == LOTTERY_STATE.CLOSED,
                "Can't start a new lottery yet!"
            );
            lottery_state = LOTTERY_STATE.OPEN;
        }
    
        function endLottery() public {
            //require(lottery_state == 50.000, "The winner is 50.000");
            //lottery_state = LOTTERY_STATE.CALCULATING_WINNER;
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.