Search code examples
blockchainsoliditypragmaremix

Testing a Flash Loan Smart Contract - Have some issues


I am making a smart contract as I'm still learning solidity and practicing. I wrote the code, and I am receiving this error on Remix:

contracts/flash.sol:8:1: ParserError: Expected pragma, import directive or contract/interface/library/struct/enum definition.
address private wallet = 0x7e31a8ba5cF188fd39f9aaCF667E9dFE2311A882;
^-----^

This is all the code that I have right now:

pragma solidity ^0.6.0;

import "https://github.com/aave/aave-solidity/contracts/AAVE.sol";
import "https://github.com/Uniswap/uniswap-v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import "https://github.com/sushiswap/sushiswap-v2-core/contracts/interfaces/ISushiV2Pair.sol";

// Set the wallet address
address private wallet = 0x0000000000000000000000000;

// Set the contract addresses
address private aave = 0x7deB5e830be29F91E298ba5FF1356BB7fC8B8C9D; // AAVE contract address
address private uniswap = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f; // Uniswap contract address
address private sushiswap = 0x6b3595068778dd592e39a122f4f5a5cf09c90fe2; // SushiSwap contract address

// Set the token addresses
address private eth = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; // ETH token address
address private ape = 0x27Dce1e12396F3a2B49E4FdD7a4C9d938E5e5F97; // APE token address

// Set the contract ABIs
AAVE aaveContract;
IUniswapV2Pair uniswapContract;
ISushiV2Pair sushiswapContract;

constructor() public {
    aaveContract = AAVE(aave);
    uniswapContract = IUniswapV2Pair(uniswap);
    sushiswapContract = ISushiV2Pair(sushiswap);
}

// Borrow 100 ETH from AAVE
function borrowFromAAVE() public {
    aaveContract.borrow(eth, 100 ether, wallet);
}

// Swap 20 ETH to APE on SushiSwap
function swapETHtoAPEonSushiSwap(uint amount) public {
    sushiswapContract.swap(amount ether, 10**18, ape, wallet, address(this));
}

// Swap 80 ETH to APE on Uniswap
function swapETHtoAPEonUniswap(uint amount) public {
    uniswapContract.swapETHForExactTokens(amount ether, 10**18, ape, wallet, address(this));
}

// Swap all APE to ETH on SushiSwap
function swapAPEtoETHonSushiSwap(uint amount) public {
    sushiswapContract.swap(amount, 10**18, eth, wallet, address(this));
}

// Pay back the loan to AAVE
function payBackLoanToAAVE() public {
    // First, check if the wallet has sufficient balance to pay back the loan
    require(wallet.balance >= aaveContract.borrowBalance(eth, wallet), "Insufficient balance to pay back the loan.");

    // Pay back the loan
    aaveContract.repayBorrow(eth, wallet);
}

// Keep the profit in the wallet
function keepProfitInWallet(uint amount) public {
    // First, check if the contract has sufficient balance to transfer the profit to the wallet
    require(address(this).balance >= amount, "Insufficient balance in the contract.");

    // Transfer the profit to the wallet
    wallet.transfer(amount);
}

what am I doing wrong? The error is showing where Wallet, AAVE, Uniswap and Sushiswap are located.

I tried many things, it keeps showing me the same error, please let me know what the issue is to learn more as I am a beginner, much appreciated champs


Solution

  • You need to specify a contract (similar to class in other OOP languages) in which you want the wallet property declared.

    pragma solidity ^0.6.0;
    
    import "https://github.com/aave/aave-solidity/contracts/AAVE.sol";
    import "https://github.com/Uniswap/uniswap-v2-core/contracts/interfaces/IUniswapV2Pair.sol";
    import "https://github.com/sushiswap/sushiswap-v2-core/contracts/interfaces/ISushiV2Pair.sol";
    
    contract MyContract {
      // Set the wallet address
      address private wallet = 0x0000000000000000000000000;
    
      // rest of your code
    }