Can you please help me out with this code, where I get the six warnings shown bellow? As a result, the withdrawal doesn't go through with the specified amount. But I don't know how to get around it. This code same in Analogy would in Python for sure.
And a secondary question, why does hardhat/console.sol work in Remix only on local blockchain, but not when I deploy it Goerli for example?
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "hardhat/console.sol";
import "https://github.com/f22daniel/helpful_smart_contracts
/blob/main/GoerliPriceFeedV2.sol";
contract SimpleExchange is ReentrancyGuard{
address owner;
address priceFeedContract;
event Transaction(address _from, address _to, uint transactDate, uint _amount, string currency);
User[] public user;
struct User {
address account;
uint date;
uint amount;
}
constructor() {
priceFeedContract = 0x99479b65dCCB46AdfB55B04822BFb1A09944295f;
owner = msg.sender;
console.log("View transaction");
}
function usdWeiConverter(uint _amount) public view returns(uint) {
uint priceEthUsd = GoerliPriceConsumerV3(priceFeedContract).UintEthUsd() * 10**10;
uint amount = _amount * 10**18;
uint ethAmountSent = (amount * 10**18)/priceEthUsd;
return ethAmountSent;
}
function czkUsdConverter(uint _amount) public view returns(uint) {
uint priceCzkUsd = (10**18 / GoerliPriceConsumerV3(priceFeedContract).UintCzkUsd() * 10**18) / 10**26;
uint usdAmount = _amount * 100 / priceCzkUsd;
return usdAmount;
}
function jpyUsdConverter(uint _amount) public view returns(uint) {
uint priceJpyUsd = (10**18 / GoerliPriceConsumerV3(priceFeedContract).UintJpyUsd() * 10**18) / 10**18;
uint jpyAmount = _amount / priceJpyUsd;
return jpyAmount;
}
function sendEthViaUsd(uint _amount) public payable {
bool sent = false;
uint amount = msg.value;
uint requiredAmount = usdWeiConverter(_amount);
require(_amount >= 20, "Min. $20 needed");
require(amount >= requiredAmount, "User needs to send higher ETH value.");
for (uint i = 0; i < user.length; ++i){
User storage _user = user[i];
if (_user.account == msg.sender) {
_user.amount += msg.value - (amount - requiredAmount);
payable(msg.sender).transfer(amount - requiredAmount);
sent = true;
emit Transaction(msg.sender, address(this), block.timestamp, (msg.value - (amount - requiredAmount)), "USD");
require(sent, "Transaction failed!");
return ;
}
}
payable(msg.sender).transfer(amount - requiredAmount);
user.push(User(msg.sender, block.timestamp, (msg.value - (amount - requiredAmount))));
sent = true;
emit Transaction(msg.sender, address(this), block.timestamp, (msg.value - (amount - requiredAmount)), "USD");
require(sent, "Transaction failed!");
}
function sendEthViaCzk(uint _amount) public payable {
bool sent = false;
uint amount = msg.value;
uint CzkUsdCost = czkUsdConverter(_amount);
uint requiredAmount = usdWeiConverter(CzkUsdCost);
require(_amount >= 800, "Min. 800 CZK needed");
require(amount >= requiredAmount, "User needs to send higher ETH value.");
for (uint i = 0; i < user.length; ++i){
User storage _user = user[i];
if (_user.account == msg.sender) {
_user.amount += msg.value - (amount - requiredAmount);
payable(msg.sender).transfer(amount - requiredAmount);
sent = true;
emit Transaction(msg.sender, address(this), block.timestamp, (msg.value - (amount - requiredAmount)), "USD");
require(sent, "Transaction failed!");
return ;
}
}
payable(msg.sender).transfer(amount - requiredAmount);
user.push(User(msg.sender, block.timestamp, (msg.value - (amount - requiredAmount))));
sent = true;
emit Transaction(msg.sender, address(this), block.timestamp, (msg.value - (amount - requiredAmount)), "USD");
require(sent, "Transaction failed!");
}
function sendEthViaJpy(uint _amount) public payable {
bool sent = false;
uint amount = msg.value;
uint JpyUsdCost = jpyUsdConverter(_amount);
uint requiredAmount = usdWeiConverter(JpyUsdCost);
require(_amount >= 2800, "Min. 2 800 JPY needed");
require(amount >= requiredAmount, "User needs to send higher ETH value.");
for (uint i = 0; i < user.length; ++i){
User storage _user = user[i];
if (_user.account == msg.sender) {
_user.amount += msg.value - (amount - requiredAmount);
payable(msg.sender).transfer(amount - requiredAmount);
sent = true;
emit Transaction(msg.sender, address(this), block.timestamp, (msg.value - (amount - requiredAmount)), "USD");
require(sent, "Transaction failed!");
return ;
}
}
payable(msg.sender).transfer(amount - requiredAmount);
user.push(User(msg.sender, block.timestamp, (msg.value - (amount - requiredAmount))));
sent = true;
emit Transaction(msg.sender, address(this), block.timestamp, (msg.value - (amount - requiredAmount)), "USD");
require(sent, "Transaction failed!");
}
function withdraw(uint _amount, string calldata _currency) external nonReentrant {
bool sent = false;
uint withdrawAmount;
if (keccak256(abi.encode(_currency)) == keccak256(abi.encode("USD"))){
uint withdrawAmount = usdWeiConverter(_amount);
}
else if (keccak256(abi.encode(_currency)) == keccak256(abi.encode("CZK"))){
uint CzkUsdConversion = czkUsdConverter(_amount);
uint withdrawAmount = usdWeiConverter(CzkUsdConversion);
}
else if (keccak256(abi.encode(_currency)) == keccak256(abi.encode("JPY"))){
uint JpyUsdConversion = jpyUsdConverter(_amount);
uint withdrawAmount = usdWeiConverter(JpyUsdConversion);
}
else {
revert("Currency has to be USD, CZK or JPY");
}
for (uint i = 0; i <= user.length; ++i) {
User storage _user = user[i];
if (_user.account == msg.sender) {
require(withdrawAmount <= _user.amount, "Not enough funds!");
payable(msg.sender).transfer(withdrawAmount);
_user.amount -= withdrawAmount;
// user[i] = user[user.length - 1];
// user.pop();
sent = true;
return ;
}
}
require(sent, "Withdrawal failed");
}
function withdrawAll() external {
require(msg.sender == owner, "Not owner!");
payable(msg.sender).transfer(address(this).balance);
}
}