简体   繁体   English

测试闪电贷智能合约 - 有一些问题

[英]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:我编写了代码,但在 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.该错误显示钱包、AAVE、Uniswap 和 Sushiswap 所在的位置。

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我尝试了很多东西,它一直向我显示相同的错误,请让我知道问题是什么,因为我是初学者,所以要了解更多信息,非常感谢冠军

You need to specify a contract (similar to class in other OOP languages) in which you want the wallet property declared.您需要指定要在其中声明wallet属性的contract (类似于其他 OOP 语言中的class )。

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM