Parser error when trying to compile Flashswap smart contract for Binance Smart Chain - parsing

I'm getting an error when trying to compile my own custom Flashswap smart contract. After compiling using Hardhat on VS Code, it throws up an error for the Pancakefactory script.
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IPancakeFactory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
require(msg.sender == feeToSetter, 'Pancakeswap: FORBIDDEN');
feeTo = _feeTo;
}
function setFeeToSetter(address) external;
require(msg.sender == feeToSetter, 'Pancakeswap: FORBIDDEN');
feeToSetter = _feeToSetter;
}
}
The error is for the line beneath function setFeeTo(address) external;. The parser error that's thrown up is "Expected identifier but got ( ".
Am I writing the line require(msg.sender == feeToSetter, 'Pancakeswap: FORBIDDEN'); inncorrectly? Is there something missing here or do I need to change where the brackets are?

Related

Bug trying to use .call with non-native ERC20 token in Solidity

I have this function called "exchangeCall" in my contract with which I can send an amount of its native ETH token ("values"), data in bytes ("callData") and an estimated gas ("estimatedGas") towards another contract ("target"). The purpose is to send the byte data ("callData"), which already contains a previously defined series of steps.
This script works perfectly when I try (for example) to exchange through the Uniswap contract, ETH (native token) for UNI (or another token).
However, when I try to do it the other way around by exchanging any token other than ETH for another one it generates an error.
In the following video you can find a more specific explanation through an example:
Videolink -> https://drive.google.com/file/d/1ujP5Q_-_PHpkDNb1Jeldo1HveReWZUMT/view
For my case, it is important that this code is made only in solidity (not web3 or similar).
I have already checked the permissions so that the non-native token can be used by the contract, it can be done with the other auxiliary functions present in the contract or through the IERC20 which is also invoked there.
I hope someone can help me, and I share the script code.
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;
import {IERC20} from "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";
contract SimpleExchange {
address payable owner;
// SOME TOKENS FOR TEST
address private immutable uniAddress =
0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984; // UNI TOKEN
address private immutable usdcAddress =
0xA2025B15a1757311bfD68cb14eaeFCc237AF5b43; // USDC TOKEN
address dexContractAddress =
0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45; // Contrato Objetivo
// FUNCTION FOR EXCHANGE
function exchangeCall(address target, bytes memory callData, uint values, uint estimatedGas) public payable returns (uint256 blockNumber) {
blockNumber = block.number;
(bool success, bytes memory ret) = target.call{value:values,gas:estimatedGas}(callData);
require(success);
}
//OPTIONAL FUNCTIONS FOR DEVELOPMENT TESTS
function approveUSDC(uint256 _amount) external returns (bool) {
return IERC20(usdcAddress).approve(dexContractAddress, _amount);
}
function allowanceUSDC() external view returns (uint256) {
return IERC20(usdcAddress).allowance(address(this), dexContractAddress);
}
function approveUNI(uint256 _amount) external returns (bool) {
return IERC20(uniAddress).approve(dexContractAddress, _amount);
}
function allowanceUNI() external view returns (uint256) {
return IERC20(uniAddress).allowance(address(this), dexContractAddress);
}
function getBalance(address _tokenAddress) external view returns (uint256) {
return IERC20(_tokenAddress).balanceOf(address(this));
}
function transfer(address _tokenAddress, address receiverAddr, uint receiverAmnt) public payable{
IERC20 token = IERC20(_tokenAddress);
token.transfer(receiverAddr, receiverAmnt);
}
function transferFrom(address sender, address recipient, uint256 amount,address token) external returns (bool){
IERC20(token).transferFrom(sender,recipient,amount);
return true;
}
function withdraw(address _tokenAddress) external {
IERC20 token = IERC20(_tokenAddress);
token.transfer(msg.sender, token.balanceOf(address(this)));
}
// Function to receive Ether. msg.data must be empty
receive() external payable {}
// Fallback function is called when msg.data is not empty
fallback() external payable {}
}

Is DartDocs about the entry of `Isolate.spawn` wrong or something?

I'm using Dart 2.18.0 now. Here's what the docs say about
the entry of Isolate.spawn.
The function must be a top-level function or a static method that can be called with a single argument, that is, a compile-time constant function value which accepts at least one positional parameter and has at most one required positional parameter. The function may accept any number of optional parameters, as long as it can be called with just a single argument. The function must not be the value of a function expression or an instance method tear-off.
Here's the code I write,
import 'dart:io';
import 'dart:isolate';
void main(List<String> args) {
Isolate.spawn((message) {
print("$message ${Isolate.current.debugName}");
}, "Hello world!", debugName: "block");
final p = Person();
Isolate.spawn(p.saySomething, "Nice to meet you!",
debugName: "Object method");
Isolate.spawn(
p.saySomething2(), "A function from the value of a function expression!",
debugName: "Function Expression");
sleep(Duration(seconds: 1));
}
class Person {
void saySomething(String something) {
print("$something ${Isolate.current.debugName}");
}
void Function(String message) saySomething2() {
return saySomething;
}
}
See, I pass a block and a method of a instance to each Isolate.spawn. The code runs well and it prints the following logs.
Hello world! block
Nice to meet you! Object method
A function from the value of a function expression! Function Expression
But how? Block is neither a top level function nor a static function. The function from a value of a function expression and the method of an instance can also be passed as Isolate entry.
Do I get it wrong? Or these features has been supported, the doc has not updated yet?
I think the problem here is that you're passing a function as a parameter, when
Isolate.spawn
expects a function expression.
The docs say:
The function must be a top-level function or a static method that can be called with a single argument, that is, a compile-time constant function value which accepts at least one positional parameter and has at most one required positional parameter. The function may accept any number of optional parameters, as long as it can be called with just a single argument. The function must not be the value of a function expression or an instance method tear-off.
You can see an example of a function expression in the docs here:
int foo(int a, int b) => a + b;
Your
saySomething2
Function returns a function expression, so you can use that directly:
Isolate.spawn(p.saySomething2(), "A function from the value of a function expression!", debugName: "Function Expression");

"expected primary expression" error - Trying to compile a smart contract on remix - ethereum ide

I'm being honest this code is taken from a website that is supposed to ease the creation of a smart contract/token on the binance smart chain. (short backstory: Me and some friends thought it would be fun to have our own token to e.g. take bets, play poker whatsoever and are now trying to create our own through deploying our smart contract on the BSC)
Here is a link to the template I used: https://github.com/binance-chain/bsc-genesis-contract/blob/master/contracts/bep20_template/BEP20Token.template
I am trying to compile the code but in line 352 the error "expected primary expression" occurs. What does that mean? I am really just a layman. The token is supposed to be called Omega and the Symbol OHM.
Thank you for your suggestions!
The linked contract contains this function which causes the syntax error.
constructor() public {
_name = {{TOKEN_NAME}};
_symbol = {{TOKEN_SYMBOL}};
_decimals = {{DECIMALS}};
_totalSupply = {{TOTAL_SUPPLY}};
_balances[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}
I'm assuming that it was the contract author's intention to use these placeholders as a way to point out where you can fill in your own values.
After you replace the placeholders with real values, the contract compiles successfully.
constructor() public {
_name = "MyToken";
_symbol = "MyT";
_decimals = 18;
_totalSupply = 1000000000000000000;
_balances[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}

Solidity - ParserError: Expected primary expression when using var

I am trying to create a struct and add mapping in such a way that it can be retrieved later on using its address using the below code.
pragma solidity ^0.8.0;
contract Courses {
struct Instructor {
uint age;
string fName;
string lName;
}
mapping (address => Instructor) instructors;
address[] public instructorAccts;
function setInstructor(address _address, uint _age, string _fName, string _lName) public {
var instructor = instructors[_address]; //ERROR HERE
instructor.age = _age;
instructor.fName = _fName;
instructor.lName = _lName;
instructorAccts.push(_address) -1;
}
}
However, I am getting an error at the line var instructor = instructors[_address]
The error is ParserError: Expected primary expression
I am unable to understand what the issue is and how to resolve it. Could anyone help with this?
Solidity uses typed variables, doesn't have the generic var keyword (that is used in JavaScript for example).
When declaring reference types (in your case string and struct), you need to specify their data location - in your case memory for the string argument. And either memory or storage for the struct depending on whether you want to set the values just in the context of the setInstructor() function (location memory), or if you want to set its values in the contract storage (location storage).
function setInstructor(address _address, uint _age, string memory _fName, string memory _lName) public {
// either `memory` or `storage` depending on your use case
Instructor storage instructor = instructors[_address];
// ... rest of your code
There also is a syntax error on this line
instructorAccts.push(_address) -1;
you can fix it by removing the -1
instructorAccts.push(_address);

pragma solidity - compilation error in jpmorganchase cakeshop

I am running a simple code from SimpleStorage example and just added few lines on top of it which I was using for my other contracts. The contract compiles fine from truffle. But on the Cakeshop Integrated IDE it shows compilation error.
pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2;
contract SimpleStorage {
uint public storedData;
event Change(string message, uint newVal);
function SimpleStorage(uint initVal) {
Change("initialized", initVal);
storedData = initVal;
}
function set(uint x) {
Change("set", x);
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}
}
It should compile on the cakeshop web UI as it compiles on local machine
Utilizing Remix, it seems the following could be potential issues with your contract:
You are using the Contract name for the constructor. You should use the constructor keyword instead.
All of your functions are missing visibility modifiers. Consider adding the public modifier to each function including the constructor.
Events should be invoked using the emit keyword. Example: emit Change("set", x);

Resources