CompileError: ParserError: Function, variable, struct or modifier declaration expected

Hi guys, when migrating my DEX contract which has 1 error which I don’t know how to fix as it underlines the last curly bracket of the contract brackets, and the terminal outputs

CompileError: ParserError: Function, variable, struct or modifier declaration expected.
  --> project:/contracts/Dex.sol:76:2:
   |
76 | }
   |  ^

Compilation failed. See above.
    at C:\Users\maksd\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\dist\run.js:64:1
    at Generator.next (<anonymous>)
    at fulfilled (C:\Users\maksd\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\dist\run.js:4:43)

This is my contract code.

// SPDX-License-Identifier: MIT

pragma solidity 0.8.16;

import "../contracts/Wallet.sol";

contract Dex is Wallet {

   

    using SafeMath for uint256;

    enum Side {

        BUY,

        SELL

    }

    struct Order {

        uint id;

        address trader;

        Side side;

        bytes32 ticker;

        uint quant;

        uint price;

    }

    mapping(bytes32 => mapping(uint => Order[])) public OrderBook;

     

    uint public nextOrderId = 0;

    function getOrderBook(bytes32 ticker, Side side) public view returns(Order[] memory){

        return OrderBook[ticker][uint(side)];

    }

    function createLimitOrder(Side side, bytes32 ticker, uint amount, uint price) public {

        if(side == Side.BUY){

            require(balances[msg.sender]["ETH"] >= amount.mul(price));

        }

        else if(side == Side.SELL){

            require(balances[msg.sender][ticker] >= amount);

        }

        Order[] storage orders = orderBook[ticker][uint(side)];

        orders.push(

            Order(nextOrderId, msg.sender, side, ticker, amount, price)

        );

        uint i = orders.length > 0 ? orders.length -1 : 0;

        if(side == Side.BUY){

            while(i > 0){

                if(orders[i - 1].price > orders[i].price){

                    break;

                }

                Orders memory orderToMove = orders[i-1];

                orders[i-1] = orders[i];

                orders[i] = orderToMove;

                i--;

            }

        }

        else if(side == Side.SELL){

                while(i > 0){

                    if(orders[i - 1].price < orders[i].price){

                        break;

                }

                Orders memory orderToMove = orders[i-1];

                orders[i-1] = orders[i];

                orders[i] = orderToMove;

                i--;

        }

        nextOrderId++;

    }

}

Would appreciate it if anyone could help, thanks.

1 Like

you have a syntax error you did not close one of your brackets properly please refer to thr fixed code below

// SPDX-License-Identifier: MIT

pragma solidity 0.8.7;

import "../contracts/Wallet.sol";

contract Dex is Wallet {

   

    using SafeMath for uint256;

    enum Side {

        BUY,

        SELL

    }

    struct Order {

        uint id;

        address trader;

        Side side;

        bytes32 ticker;

        uint quant;

        uint price;

    }

    mapping(bytes32 => mapping(uint => Order[])) public OrderBook;

     

    uint public nextOrderId = 0;

    function getOrderBook(bytes32 ticker, Side side) public view returns(Order[] memory){

        return OrderBook[ticker][uint(side)];

    }

    function createLimitOrder(Side side, bytes32 ticker, uint amount, uint price) public {

        if(side == Side.BUY){

            require(balances[msg.sender]["ETH"] >= amount.mul(price));

        }

        else if(side == Side.SELL){

            require(balances[msg.sender][ticker] >= amount);

        }

        Order[] storage orders = orderBook[ticker][uint(side)];

        orders.push(

            Order(nextOrderId, msg.sender, side, ticker, amount, price)

        );

        uint i = orders.length > 0 ? orders.length -1 : 0;

        if(side == Side.BUY){

            while(i > 0){

                if(orders[i - 1].price > orders[i].price){

                    break;

                }

                Orders memory orderToMove = orders[i-1];

                orders[i-1] = orders[i];

                orders[i] = orderToMove;

                i--;

            }

        }

        else if(side == Side.SELL){

                while(i > 0){

                    if(orders[i - 1].price < orders[i].price){

                        break;

                }

                Orders memory orderToMove = orders[i-1];

                orders[i-1] = orders[i];

                orders[i] = orderToMove;

                i--;

        }

        nextOrderId++;

    }

    }
}
2 Likes

Thank you so much, fixed it now.

2 Likes

hi have a similar problem it seems, can someone please help me.? I can’t find the error in my contract

pragma solidity ^0.5.0;

import "./DappToken.sol";
import "./DaiToken.sol";

contract TokenFarm {
    string public name = "Dapp Token Farm";
    address public owner; 
    DappToken public dappToken;
    DaiToken public daiToken;

    address[] public stakers; 
    mapping(address => uint) public stakingBalance; 
    mapping(address => bool) public hasStaked; 
    mapping(address => bool) public isStaking;

    constructor(DappToken _dappToken, DaiToken _daiToken) public {
        dappToken = _dappToken;
        daiToken = _daiToken;
        owner = msg.sender;
    }
    
    // Stakes Tokens
    function stakeTokens(uint _amount) public {

        // Require amount greater than 0
        require(_amount > 0, "amount cannot be 0");
        
        // Transfer Mock Dai Tokens to this contract for staking
        daiToken.transferFrom(msg.sender, address(this), _amount);
        
        //Update staking balance
        stakingBalance[msg.sender] = stakingBalance[msg.sender] + _amount; 

        // Add user to stakers array *only* if they haven't staked already
        if(!hasStaked[msg.sender]) { 
            stakers.push(msg.sender);
        }

         //Update staking status
        isStaking[msg.sender] = true;
        hasStaked[msg.sender] = true; 
    }

    // Unstake Tokens 

    // Issuing Tokens
    function issueTokens() public {
        // Only owner can call this function
        require(msg.sender = owner, "caller must be the owner");

        //Issue tokens to all stakers
        for (uint i=0; i<stakers.length; i++) {
            address recipient = stakers[i];
            uint balance = stakingBalance[recipient];
            if(balance > 0) {
                dappToken.transfer(recipient, balance);
        }
    }
}

1 Like

Your code is missing one closing bracket. If you add } at the end of your code it should fix that error.

Thx it worked
I appreciate it a lot.

1 Like

one more question, have ever made a arbitrage or some sort of trading/passive income bot?

I have tested arbitrage trades on testnet a long back but never tried on mainnet. They way I tried is just learning purpose by doing manual transactions. I did not make any trading bot out of it :grinning:

oh okay cool that is interesting

1 Like

Hey, hope you don’t mind, I tried so many things already but could you please help me? Because you seem to know more than me and idk what is going on here and idkwhat any of this means

{
  code: -32603,
  message: 'Unknown Error: invalid project id\n',
  data: { originalError: {} },
  stack: 'Error: Unknown Error: invalid project id\n' +
    '\n' +
    '    at Request._callback (/home/dylan/trading-bot/node_modules/@trufflesuite/web3-provider-engine/subproviders/rpc.js:57:23)\n' +
    '    at self.callback (/home/dylan/trading-bot/node_modules/request/request.js:185:22)\n' +
    '    at Request.emit (node:events:513:28)\n' +
    '    at Request.<anonymous> (/home/dylan/trading-bot/node_modules/request/request.js:1154:10)\n' +
    '    at Request.emit (node:events:513:28)\n' +
    '    at IncomingMessage.<anonymous> (/home/dylan/trading-bot/node_modules/request/request.js:1076:12)\n' +
    '    at Object.onceWrapper (node:events:627:28)\n' +
    '    at IncomingMessage.emit (node:events:525:35)\n' +
    '    at endReadableNT (node:internal/streams/readable:1359:12)\n' +
    '    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)'
}

Please man.

Hi @Dylan_Katsch, As per the error you shared, there seems to be something wrong with the project id.

I need more context on what you were trying to do to give more details on what caused the error. If possible share the tutorial that you are following.

Hi, @JohnVersus thank you so much.
I was following this tutorial (https://youtu.be/bcFflveRJG0) and at some point it said I had to use the “Ropsten test net” but then I found out it’s not supported by meta mask wallet nor was it any longer supported by INFURA, so I tried many things and found that the Goerli test net is supported by bot.
So the problem is Idk how or what to change in the bots code.
and to best of my knowledge I change the RPC_URL in the project from the Ropsten test net to Goerli test net and got the Goerli test net addresses of that was cryptos used in the project and replaced them.

so yeah, I can show the code or do you want to go get it from the link?

The code from that tutorial shows has two constants named EXCHANGE_ADDRESS and DAI_ADDRESS which are the addresses of contracts on ropsten network. These need to be replaced with contract addresses from goerli network.
And ropsten url in line 53 need to replaced with goerli

I hope this helps.

ahh, I replaced the addresses but not the url in line 53
once again thank you so much and I hope it doesn’t bother you that I come to you so often

1 Like

No worries @Dylan_Katsch. Happy to help :slightly_smiling_face:

I’ll probably need your help again in the near future :sweat_smile: :smiley:

1 Like

Bro one more favor please
can you send me the right links because I can’t get the right ones?
all three please

( that was sooner than I expected :joy: )

DAI_ADDRESS is 0xf2edF1c091f683E3fb452497d9a98A49cBA84666 and I could not find anything valid for EXCHANGE_ADDRESS that match with the ropsten exchange contract.

line 53 would be

console.log(`Successful Swap: https://goerli.etherscan.io/tx/${result.transactionHash}`)

thank you once again man.

1 Like

@JohnVersus
Hello, my bro can you help me with this please

// contracts/DokenToken.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.17;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";


contract DokenToken is ERC20Capped, ERC20Burnable {
    address payable public owner;
    uint256 public blockReward;

    constructor(uint256 cap, uint256 reward) ERC20("DokenToken", "DTK") ERC20Capped(cap * (10 ** decimals())) {
        owner = payable(msg.sender); 
        _mint(owner, 70000000 * (10 ** decimals()));
        blockReward = reward * (10 ** decimals());
    }

    function _mint(address account, uint256 amount) internal virtual override(ERC20Capped, ERC20) {
        require(ERC20.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
        super._mint(account, amount);
    }

    function _mintMinerReward() internal {
        _mint(block.coinbase, blockReward); 
    }

    function _beforeTokenTransfer(address from, address to, uint256 value) internal virtual override {
        if(from != address(0) && to != block.coinbase && block.coinbase != address(0)) {
        _mintMinerReward();
    }
    super._BerforeTokenTransfer(from, to, value); 

    function setBlockReward(uint256 reward) public olnyOwner {
        blockReward = reward * (10 ** decimals());
    }

    function destroy() pulic onlyOwner {
        selfdestruct(owner); 
    }

    modifier olnyOwner {
        require(msg.sender == owner, "Only the owner can call this function");
        _;
    }
}
}  

that’s the contract I’m currently working on and I keep getting this error

ParserError: Expected '(' but got identifier
  --> contracts/DokenToken.sol:36:14:
   |
36 |     function setBlockReward(uint256 reward) public olnyOwner {
   |              ^^^^^^^^^^^^^^

Idk how to fix it
thanks man

1 Like