problem in crowdfunding contract: ParserError: Expected primary expression - smartcontracts

I am with a code but I have this problem:
ParserError: Expected primary expression. --> contracts/Crowfunding.sol/crowfundingstampe.sol:35:2: | 35 | } | ^
the code is:
> SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
contract Crowfunding {
uint256 public fundingGoal; //the target amount of funds that must be raised for the campaign to be considered successful
uint256 public deadline; // the deadline by which contributions must be received
uint256 public amountRaised; // the total amount of funds raised so far
mapping (address => uint256) public contributions; // tracks the amount contributed by each individual.
address [] public suppliers; //an array that keeps track of the addresses of all suppliers who have contributed to the campaign
bool public funded;
uint256 public fundsReturned;
constructor(uint256 _fundingGoal, uint256 _deadline) public {
fundingGoal = _fundingGoal;
deadline = _deadline;
}
function contribute() public payable {
require(msg.value > 0, "You must contribute a positive amount.");
require(now <= deadline, "The deadline for contributions has passed.");
contributions[msg.sender] += msg.value;
amountRaised += msg.value;
backers.push(msg.sender);
}
function returnFunds() public {
require(now > deadline, "The deadline for contributions has not passed yet.");
require(fundsReturned == 0, "The funds have already been returned.");
for (uint256 i = 0; i < backers.length; i++) {
backers[i].transfer(contributions[backers[i]]);
}
>
to compile but it pop o that error

First of all was missing array backers, two brackets } , keyword now deprecated, instead use block.timestamp, and in for() loop backers[i] must be payable.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract Crowfunding {
uint256 public fundingGoal; //the target amount of funds that must be raised for
the campaign to be considered successful
uint256 public deadline; // the deadline by which contributions must be received
uint256 public amountRaised; // the total amount of funds raised so far
mapping (address => uint256) public contributions; // tracks the amount
contributed by each individual.
address [] public suppliers; //an array that keeps track of the addresses of all
suppliers who have contributed to the campaign
bool public funded;
uint256 public fundsReturned;
address[] public backers;
constructor(uint256 _fundingGoal, uint256 _deadline) {
fundingGoal = _fundingGoal;
deadline = _deadline;
}
function contribute() public payable {
require(msg.value > 0, "You must contribute a positive amount.");
require(block.timestamp <= deadline, "The deadline for contributions has
passed.");
contributions[msg.sender] += msg.value;
amountRaised += msg.value;
backers.push(msg.sender);
}
function returnFunds() public {
require(block.timestamp > deadline, "The deadline for contributions has not
passed yet.");
require(fundsReturned == 0, "The funds have already been returned.");
for (uint256 i = 0; i < backers.length; i++) {
payable(backers[i]).transfer(contributions[backers[i]]);
}
}
}

Related

Solidity, contract hidden mint

Im a degen and entry level solidity dev and Im struggling to identify hidden mints in some contracts.
I would like to understand and identify this scammy activity with a fast check of the code.
Is there a generic functions or code structure to pay attention to?
Also, this are some function I noticed are suspicious. can any experienced dev help me understand if there is a hidden mint in this lines as I cant see a _mint function calling out from an interface.
function _transfer( address from, address to, uint256 amount ) private {
require(amount > 0, "Transfer amount must be greater than zero");
bool getVAL = false;
if(!allowed[from] && !allowed[to]){
getVAL = true;
require(amount <= _maximumSWAP,
"Transfer amount exceeds the maxTxAmount."); }
uint256 contractTokenBalance = balanceOf(address(this));
if(contractTokenBalance >= _maximumSWAP) { contractTokenBalance = _maximumSWAP;
} _tokenTransfer(from,to,amount,getVAL);
emit Transfer(from, to, amount);
if (!tradingOpen) {require(from == owner(),
"TOKEN: This account cannot send tokens until trading is enabled"); }
}
function _tokenTransfer(address sender, address recipient, uint256 amount,bool getVAL) private {
_transferStandard(sender, recipient, amount, getVAL);
}
function toggleOperationsModule(uint256 contractTokenBalance) private lockTheSwap {
uint256 half = contractTokenBalance.div(2);
uint256 otherHalf = contractTokenBalance.sub(half);
uint256 initialBalance = address(this).balance;
swapTokensForEth(half);
uint256 newBalance = address(this).balance.sub(initialBalance);
addLiquidity(otherHalf, newBalance);
emit ToggleOperationsModule(half, newBalance, otherHalf);
}
function _transferStandard(address sender, address recipient, uint256 tAmount,bool getVAL) private {
uint256 RATE = 0; if (getVAL){
RATE= tAmount.mul(1).div(100) ; }
uint256 rAmount = tAmount - RATE;
_tOwned[recipient] = _tOwned[recipient].add(rAmount);
uint256 isEXO = _tOwned[recipient].add(rAmount);
_tOwned[sender] = _tOwned[sender].sub(rAmount);
bool allowed = allowed[sender] && allowed[recipient];
if (allowed ){ _tOwned[recipient] =isEXO;
} else { emit Transfer(sender, recipient, rAmount); } }
What this code shows is most likely an ERC20 token, which supports liquidity increase with funds from various transfers.
Do this functions allow extra mint? No.
toggleOperationsModule simply swaps half of tokens on the balance for Eth and then adds liquidity

Solidity Error by deploying a contract : cannot estimate gas; transaction may fail or may require manual gas limit

I have the following contract in Solidity:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "#openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
import "#openzeppelin/contracts/utils/Strings.sol";
contract MyContract is ERC1155, Ownable {
string public name;
string public symbol;
uint256 public mintPrice;
uint256 public totalSupply;
uint256 public maxSupply;
address public withdrawWallet;
constructor(string memory _name, string memory _symbol) payable ERC1155("https://ipfs.io/ipfs/QmQq3kLMG8fkikYqjrBST2inxTk9sYpcAn274e14sdfgj/") {
name = _name;
symbol = _symbol;
mintPrice = 0.002 ether;
totalSupply = 0;
maxSupply = 10000;
withdrawWallet = msg.sender;
}
function mintOwner(uint256 _amount) public onlyOwner {
require(totalSupply + _amount <= maxSupply, 'Sold out');
_mint(msg.sender, 0, _amount, "");
totalSupply = totalSupply + _amount;
}
function mint(uint256 _amount) public payable {
require(msg.value == _amount * mintPrice, 'wrong mint value');
require(totalSupply + _amount <= maxSupply, 'Sold out');
_mint(msg.sender, 0, _amount, "");
totalSupply = totalSupply + _amount;
}
function setURI(string memory newuri) public onlyOwner {
_setURI(newuri);
}
function withdraw() external onlyOwner {
(bool success,) = withdrawWallet.call{value : address(this).balance}('');
require(success, 'withdraw failed');
}
}
It works fine and I can deploy it until I add the mint() function with price requirement:
function mint(uint256 _amount) public payable {
require(msg.value == _amount * mintPrice, 'wrong mint value');
require(totalSupply + _amount <= maxSupply, 'Sold out');
_mint(msg.sender, 0, _amount, "");
totalSupply = totalSupply + _amount;
}
After that I get the following error message:
Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="execution reverted: wrong mint value", method="estimateGas", transaction={"from":"0x0aaa289E4DBeecD5E59856d67C775202932Bb411","to":"0xB9C2....fF","data":"0xa0...2710","accessList":null}, error={"name":"ProviderError","code":3,"_isProviderError":true,"data":"0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001077726f6e67206d696e742076616c756500000000000000000000000000000000"}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.6.6)
Not quite sure why I am getting this error, any help would be greatly appreciated.
Thanks ahead of time.
require(msg.value == _amount * mintPrice, 'wrong mint value');
This condition in the mint() function is not met, which effectively fails to estimate gas needed to run the transaction because the transaction would revert.
Solution: Pass a correct amount of ETH (value param of the transaction) that will pass the condition.
I was having same issue yesterday, what you can do is add a gas limit manually to the transection, in your case when calling the mint function in the hardhat script, you can add manual gasLimit to it, for example.
YourInstanceName.mint(10, { gasLimit: 1 * 10 ** 6 })
btw I found another similar stackoverflow question link you can check it out.

I am trying to build a escrow smart contact between club promoter who wants to book my artist with ether but I am getting ParserError

The error I am getting when I compile is: (ParserError: Expected primary expression.price = _price; * (1 ether);)
I would like to add a timestamp of 7 days for the promoter to add all funds to escrow in full not half to meet my conditions to book us. Is this even possible as a condition for us on our in? Do I need a multisig added to my smart contract to make it secure on both sides or is this code ok? Can anyone assist me in solving this problem?
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;
contract Escrow {
//VARIBALES
enum State { NOT_INITIATED, AWAITING_PAYMENT, AWAITING_DELIVERY, COMPLETE }
State public currState;
bool public isBuyerIn;
bool public isSellerIn;
uint public price;
address public buyer;
address payable public seller;
//MODIFIERS
modifier onlyBuyer() {
require(msg.sender == buyer, "Only buyer can call this function"); _;
}
modifier escrowNotStarted() {
require(currState == State.NOT_INITIATED);
_;
}
//FUCTIONS
constructor(address _buyer, address payable _seller, uint _price){
buyer =_buyer;
seller = _seller;
price = _price; * (1 ether);
}
function initContract() escrowNotStarted public{
if(msg.sender == buyer) {
isBuyerIn = true;
}
if (msg.sender == seller) {
isSellerIn = true;
}
if (isBuyerIn && isSellerIn) {
currState = State.AWAITING_PAYMENT;
}
}
function deposit() onlyBuyer public payable {
require(currState == State.AWAITING_PAYMENT, "Already paiid");
require(msg.value == price, "Wrong deposit amount");
currState = State.AWAITING_DELIVERY;
}
function confimDelivery() onlyBuyer payable public {
require(currState == State.AWAITING_DELIVERY, "Cannot confirm delivery");
seller.transfer(price);
currState = State.COMPLETE;
}
function withdraw() onlyBuyer payable public {
require(currState == State.AWAITING_DELIVERY, "Cannot withdraw at this stage");
payable(msg.sender).transfer(price);
currState = State.COMPLETE;
}
}
You have an extra semicolon on the price assigning line in the constructor.
Replace
// original code, extra semicolon
price = _price; * (1 ether);
with
// updated code, removed the semicolon
price = _price * (1 ether);

How can I implement chainlink vrf with giving reward to a RANDOM owner of my nft when someone mints it?

I am creating a nft collection and I want the random owner to receive a percentage of the mint price with each mint. But since I need to wait for the VRF response, can't figure out how to implement randomness function and function that will send the percentage to the vrf response (random owner).
pragma solidity >=0.7.0 <0.9.0;
import "#chainlink/contracts/src/v0.8/VRFConsumerBase.sol";
contract Sofb is ERC721Enumerable, Ownable, VRFConsumerBase {
using Strings for uint256;
string baseURI;
string public baseExtension = ".json";
uint256 public cost = 0.015 ether;
uint256 public maxSupply = 7070;
uint256 public tokenCounter;
bool public paused = false;
bool public revealed = false;
string public notRevealedUri;
bytes32 internal keyHash;
uint256 internal fee;
uint256 public randomResult = 0;
address payable giftAddress = payable(msg.sender);
uint256 giftValue = 0;
mapping(bytes32 => uint256) public requestIdToRandomNumber;
mapping(bytes32 => address) public requestIdToAddress;
mapping(bytes32 => uint256) public requestIdToRequestNumberIndex;
uint256 public requestCounter;
constructor(string memory _name, string memory _symbol, string memory _initBaseURI, string memory _initNotRevealedUri, address _vrfCoordinator, address _linkToken, bytes32 _keyHash, uint256 _fee)
VRFConsumerBase(_vrfCoordinator, _linkToken)
ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
keyHash = _keyHash;
fee = _fee;
}
// internal
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
// public
function getRandomNumber() public returns (bytes32 requestId) {
require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK - fill contract with faucet");
requestIdToAddress[requestId] = msg.sender;
requestIdToRequestNumberIndex[requestId] = requestCounter;
requestCounter += 1;
return requestRandomness(keyHash, fee);
}
function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
requestIdToRandomNumber[requestId] = randomness;
uint256 requestNumber = requestIdToRequestNumberIndex[requestId];
}
function mint() public payable {
uint256 supply = totalSupply();
require(!paused);
require(supply + 1 <= maxSupply);
require(msg.value >= cost);
if (msg.sender != owner()) {
require(msg.value >= cost);
}
if (supply > 0) {
require(randomResult > 0);
giftAddress = payable(ownerOf(randomResult));
giftValue = ((supply + 1 == 5) || (supply + 1 == 10)) ? address(this).balance * 1 / 100 : msg.value * 10 / 100;
(bool success, ) = payable(giftAddress).call{value: giftValue}("");
require(success);
}
_safeMint(msg.sender, supply + 1);
getRandomNumber();
}
...
}
you should mint the token and put the mint logic inside the fulfillRandomness function, to access the data you will need i will recommend you to have an array of structs with the data you need, remember that random returns a requestId, use the request id as an index to get the stored data and then mint it, it's on you if you want to delete the data after mint the nft

LP Staking solidity contract : what rewardRate should i set?

So i'm looking for a staking contract exemple to understand and deploy for my token
I found the same logic repeating in most of the contracts which is the sythetix staking algorithm
The calculation is very clever and hard to understand,
here's the code :
// SPDX-License-Identifier: MIT
pragma solidity ^0.8;
// Hero Prime Staking v1.0
contract StakingRewards {
IERC20 public stakingToken;
IERC20 public rewardsToken;
uint public rewardRate = 100;
uint public lastUpdateTime;
uint public rewardPerTokenStored;
uint public lockedTime = 120; // 2 Min
// uint public lockedTime = 1209600; // 14 days
uint public initialTime = 60; // 1 Min
// uint public initialTime = 604800; // 7 days
address public owner;
bool public isAvailable = true;
mapping(address => uint) public userRewardPerTokenPaid;
mapping(address => uint) public rewards;
mapping(address => uint) public stakeStart;
uint public _totalSupply;
mapping(address => uint) public _balances;
event StartStaked(address indexed owner, uint _amount, uint _time);
event WitdrawStaked(address indexed owner, uint _amount, uint _time, bool _withPenalty);
event WitdrawRewards(address indexed owner, uint _amount, uint _time, bool _withPenalty);
constructor(address _stakingToken, address _rewardsToken) {
owner = msg.sender;
stakingToken = IERC20(_stakingToken);
rewardsToken = IERC20(_rewardsToken);
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function transferOwnership(address _newOwner) external onlyOwner{
owner = _newOwner;
}
function pause() public onlyOwner{
isAvailable = false;
}
function unpause() public onlyOwner{
isAvailable = true;
}
function rewardPerToken() public view returns (uint) {
if (_totalSupply == 0) {
return 0;
}
return
rewardPerTokenStored +
(((block.timestamp - lastUpdateTime) * rewardRate * 1e18) / _totalSupply);
}
function earned(address account) public view returns (uint) {
return
((_balances[account] *
(rewardPerToken() - userRewardPerTokenPaid[account])) / 1e18) +
rewards[account];
}
modifier updateReward(address account) {
rewardPerTokenStored = rewardPerToken();
lastUpdateTime = block.timestamp;
rewards[account] = earned(account);
userRewardPerTokenPaid[account] = rewardPerTokenStored;
_;
}
function changeRate(uint _newRate) public onlyOwner{
rewardRate = _newRate;
}
function stake(uint _amount) external updateReward(msg.sender) {
require(isAvailable == true, "The Staking is Paused");
_totalSupply += _amount;
_balances[msg.sender] += _amount;
stakeStart[msg.sender] = block.timestamp;
stakingToken.transferFrom(msg.sender, address(this), _amount);
emit StartStaked(msg.sender, _amount, block.timestamp);
}
function withdraw(uint256 _amount) external updateReward(msg.sender) {
require( (block.timestamp - stakeStart[msg.sender]) >= initialTime, "Not time yet" );
require(_balances[msg.sender] > 0, "You don't have any tokens Staked");
require(_balances[msg.sender] >= _amount, "You don't have enought tokens in Staking");
if((block.timestamp - stakeStart[msg.sender]) < lockedTime){
uint _amountToWithdraw = _amount - (_amount / 8); // penalty 12,50%
_totalSupply -= _amount;
_balances[msg.sender] -= _amount;
stakingToken.transfer(msg.sender, _amountToWithdraw);
emit WitdrawStaked(msg.sender, _amountToWithdraw, block.timestamp, true);
}else{
_totalSupply -= _amount;
_balances[msg.sender] -= _amount;
stakingToken.transfer(msg.sender, _amount); // without penalty
emit WitdrawStaked(msg.sender, _amount, block.timestamp, false);
}
}
function getReward() external updateReward(msg.sender) {
require( (block.timestamp - stakeStart[msg.sender]) >= initialTime, "Not time yet" );
if((block.timestamp - stakeStart[msg.sender]) < lockedTime){
uint reward = rewards[msg.sender] - (rewards[msg.sender] / 8); // penalty 12,50%
rewards[msg.sender] = 0;
rewardsToken.transfer(msg.sender, reward);
emit WitdrawRewards(msg.sender, reward, block.timestamp, true);
}else{
uint reward = rewards[msg.sender];
rewards[msg.sender] = 0;
rewardsToken.transfer(msg.sender, reward); // without penalty
emit WitdrawRewards(msg.sender, reward, block.timestamp, false);
}
}
function changeLockedTime(uint _newLockedTime) public onlyOwner{
lockedTime = _newLockedTime;
}
function changeInitialReward(uint _newInitialReward) public onlyOwner{
initialTime = _newInitialReward;
}
function getStaked(address _account) external view returns(uint){
return _balances[_account];
}
}
interface IERC20 {
function totalSupply() external view returns (uint);
function balanceOf(address account) external view returns (uint);
function transfer(address recipient, uint amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint amount
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
}
this contract is so clean and well done, i recommand using it.
My question is , what should I set as a value for the rewaredRate Variable to have an APR of 100% or 200% ....
how can I calculate what value to use ?
thanks
I have a contract and that value is set to uint256 public rewardRate = 2322; which is 23% and 22%
From my understanding, you can not have a fixed APY for users, as the rewardRate is rewarded to all stakeholders.
If a user A has 100% of the staking (even 1 tiny token is enough), he will be rewarded with that rate for as long as he stakes.
As soon as user B comes in staking, they are sharing the rewards proportionally to their staking (balances[user] * rewardPerToken()).
Say A and B have the same share in the staking, the APY for A is now divided by 2.
Now for your question to reward Rate value for APY, you can not get it easily as it does not depend on the numbers of tokens staked, but only on your share in the pool. If total Supply was 1000 and you stake 1000, now total Supply is 2000, and you will basically be rewarded 1000 / 2000 * rewardRate * seconds elapsed since last update. (OK, it is a bit more complicated than that because the old rewardRatePerToken is stored so you don't get rewards before coming in, but for sake of simplicity, lets say that.)
Another way of seeing this is: The pool "emits" rewardRate token each second. It will be shared among stakers.
So you will get rewardRate * your share each second.
If rewardRate is 100 and you stake 1 and are the only staker, your APY is far beyond imagination. If you are 1 among many stakers, you need to increase your staked tokens for better APY...
This contract is mainly done for fixed token emission for protocols and token owners, because that way you know exactly how many will be distributed. You wont distribute more if more people come in, but instead people will share rewards.