TypeError: Member "mint" not found or not visible after argument-dependent lookup in address - npm

I'm trying to compile this contract but it won't work. I know I can point mint and redeem for address, but since I'll get these from compound, how do I point it to make it compile?
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;
import "#openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol";
import "#openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
import {OwnableUpgradeable} from "#openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
contract Myvaultis ERC4626Upgradeable, OwnableUpgradeable {
//compound variable to store address
address _cAsset;
function initialize(
IERC20MetadataUpgradeable asset_,
string memory name_,
string memory symbol_
) public initializer {
__MyVault_init(asset_, name_, symbol_);
_cAsset = 0x00000000000000000000000; //put here cAsset address
}
function __MyVault_init(
IERC20MetadataUpgradeable asset_,
string memory name_,
string memory symbol_
) internal onlyInitializing {
__ERC4626_init_unchained(asset_);
__ERC20_init_unchained(name_, symbol_);
__Ownable_init_unchained();
}
function depositCompound(
IERC20MetadataUpgradeable asset_,
address cAsset_,
uint256 _amount
) public onlyOwner returns (uint) {
asset_.approve(cAsset_, _amount);
// Mint cTokens
uint mintResult = cAsset_.mint(_amount);
return mintResult;
}
function withdrawCompound(
uint256 amount,
bool redeemType,
address cAsset_
) public onlyOwner returns (bool) {
uint256 redeemResult;
if (redeemType == true) {
redeemResult = cAsset_.redeem(amount);
} else {
redeemResult = cAsset_.redeemUnderlying(amount);
}
return true;
}
}
The error i'm getting is
TypeError: Member "mint" not found or not visible after argument-dependent lookup in address.
|
38 | uint mintResult = cAsset_.mint(_amount);
| ^^^^^^^^^^^^
Error HH600: Compilation failed

looks like you haven't defined the contract and your trying to access it via the address.
You might have to define the interface then plug in the address.
contract = interface(address)
then you can use contract.functionName(parameters)

Related

I generated a flattened of my contract using Remix but it gives error: Definition of base has to precede definition of derived contract

I thibk the error is occurring because the contract "ERC721Burnable" is trying to inherit from two other contracts "Context" and "ERC721", but "Context" is not defined in the code you provided. So, the definition of a base contract must precede the definition of a derived contract.
How can I make sure that the definition of the "Context" contract is included before the definition of the "ERC721Burnable" contract. Additionally, How can I make sure that "Context" is defined in the same file or imported from a different file.
Bellow is the code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "#openzeppelin/contracts/token/common/ERC2981.sol";
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "#openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "#openzeppelin/contracts/security/Pausable.sol";
import "#openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "#openzeppelin/contracts/utils/Counters.sol";
import "#openzeppelin/contracts/utils/math/SafeMath.sol";
contract AliveNatureNFT is ERC721, ERC721Enumerable, ERC721URIStorage, ERC2981, Pausable, ERC721Burnable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
// percentage split for commission and liquidity pool
uint96 public commissionPercentage;
uint96 public liquidityPercentage;
// address of the commission recipient
address public commissionRecipient;
// address of the liquidity pool
address public liquidityPoolRecipient;
// Owner address
address public ownerNFT;
//Base URI
string private url;
struct ProjectData {
string name;
uint256 projectTokenId;
string methodology;
string region;
string emissionType;
string uri;
address creator;
}
struct RetireData {
uint256 retireTokenId;
address beneficiary;
string retirementMessage;
uint256 timeStamp;
uint256 amount;
}
mapping (uint256 => ProjectData) private _projectData;
mapping (uint256 => RetireData) private _retireData;
modifier onlyOwner(address _sender) {
require(_sender == ownerNFT, "Only the owner can call this function");
_;
}
modifier onlyAdmin (address _sender) {
require(_sender == commissionRecipient, "Only the heir can call this function");
_;
}
constructor(
uint96 _liquidityPercentage, address _liquidityPoolRecipient,
string memory _MyToken, string memory _Symbol, string memory _url, address _ownerNFT
) ERC721(_MyToken, _Symbol) {
commissionPercentage = 100;
liquidityPercentage = _liquidityPercentage;
commissionRecipient = 0xE3506A38C80D8bA1ef219ADF55E31E18FB88EbF4;
liquidityPoolRecipient = _liquidityPoolRecipient;
ownerNFT = _ownerNFT;
_setDefaultRoyalty(commissionRecipient, commissionPercentage);
url = _url;
}
function _baseURI() internal view override returns (string memory) {
return url;
}
function pause(address _sender) external onlyAdmin(_sender) {
_pause();
}
function unpause(address _sender) external onlyAdmin(_sender) {
_unpause();
}
function safeMint(address _to, string memory _uri, string memory _name,
string memory _methodology, string memory _region, string memory _emissionType, address _sender) public whenNotPaused onlyOwner(_sender) {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(_to, tokenId);
_setTokenURI(tokenId, _uri);
// Create a new ProjectData struct and store it in the contract's storage
_projectData[tokenId] = ProjectData({
projectTokenId : tokenId,
uri : _uri,
name : _name,
methodology : _methodology,
region : _region,
emissionType : _emissionType,
creator : _sender
});
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId, uint256 batchSize)
internal
whenNotPaused
override(ERC721, ERC721Enumerable)
{
super._beforeTokenTransfer(from, to, tokenId, batchSize);
if (from != address(0)) {
address owner = ownerOf(tokenId);
require(owner == msg.sender, "Only the owner of NFT can transfer or burn it");
}
}
function _burn(uint256 tokenId) internal whenNotPaused override(ERC721, ERC721URIStorage) {
super._burn(tokenId);
}
function burnToken(uint256 tokenId, string memory _retirementMessage, uint256 _amount, address _sender) public whenNotPaused onlyOwner(_sender) {
address owner = ownerOf(tokenId);
require(owner == msg.sender, "Only the owner of NFT can burn it");
_burn(tokenId);
// Create a new ProjectData struct and store it in the contract's storage
_retireData[tokenId] = RetireData({
retireTokenId : tokenId,
beneficiary : msg.sender,
retirementMessage : _retirementMessage,
timeStamp : block.timestamp,
amount : _amount
});
}
function tokenURI(uint256 tokenId)
public
view
override(ERC721, ERC721URIStorage)
returns (string memory)
{
return super.tokenURI(tokenId);
}
// The following functions are overrides required by Solidity.
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC2981, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
I'm trying to group everything in a flattened contract to have the complete ABI

DeclarationError: Identifier not found or not unique

I'm trying to compile my sol file, but it's giving me this error. Why am I getting this error?
DeclarationError: Identifier not found or not unique. -->
project:/contracts/MemoTokenSale.sol:11:5: | 11 | MemoToken
public token; | ^^^^^^^^^
Compilation failed. See above. Truffle v5.4.23 (core: 5.4.23) Node
v16.13.0
The following is my code
// SPX-License-Identifier: MIT
pragma solidity ^0.8.0;
import './MemoToken.sol';
import "#chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract MemoTokenSale {
address payable public admin;
address payable private ethFunds = payable(0x15b22B37679eF92672dA117F4357e048319008AD); // Web3 Account
MemoToken public token;
uint256 public tokensSold;
int public tokenPriceUSD;
AggregatorV3Interface internal priceFeed;
uint256 public transactionCount;
event Sell(address _buyer, uint256 _amount);
struct Transaction {
address buyer;
uint256 amount;
}
mapping(uint256 => Transaction) public transaction;
constructor(MemoToken _token) {
priceFeed = AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331); // ChainLink Contracts
tokenPriceUSD = 50;
token = _token;
admin = payable(msg.sender);
}
function getETHPrice() public view returns(int) {
(, int price, , , ) = priceFeed.latestRoundData();
return (price / 10^8);
}
function memoTokenPriceInETH() public view returns(int) {
int ethPrice = getETHPrice();
return tokenPriceUSD / ethPrice;
}
function buyToken(uint256 _amount) public payable {
int memoTokenPriceETH = memoTokenPriceInETH();
// Check that the buyer sends the enough ETH
require(int(msg.value) >= memoTokenPriceETH * int(_amount));
// Check that the sale contract provides the enough ETH to make this transaction.
require(token.balanceOf(address(this)) >= _amount);
// Make the transaction inside of the require
// transfer returns a boolean value.
require(token.transfer(msg.sender, _amount));
// Transfer the ETH of the buyer to us
ethFunds.transfer(msg.value);
// Increase the amount of tokens sold
tokensSold += _amount;
// Increase the amount of transactions
transaction[transactionCount] = Transaction(msg.sender, _amount);
transactionCount++;
// Emit the Sell event
emit Sell(msg.sender, _amount);
}
function endSale() public {
require(msg.sender == admin);
// Return the tokens that were left inside of the sale contract
uint256 amount = token.balanceOf(address(this));
require(token.transfer(admin, amount));
selfdestruct(payable(admin));
}
}

Type address is not implicitly convertible to expected type address payable. owner = msg.sender

I'm getting this error when compiling. I know it's related to v8 and I need to make them payable, and I did but still doesn't work. can a good samaritan help?
contract FundMe {
mapping(address =>uint256) public addressToAmountFunded;
address payable[] public funders;
address payable public owner;
constructor() public {
owner = msg.sender; //LINE WITH ERROR
}
function fund() public payable {
uint256 minimumUSD = 50 * 10 ** 18;
require(getConversionRate(msg.value) >= minimumUSD, "you need to spend more ETH my friend");
addressToAmountFunded[msg.sender] += msg.value;
funders.push(msg.sender); //ERROR AS WELL
}
Try wrapping the addresses like bellow:
payable(msg.sender)

Solidity - Simple API request - Undeclared identifier problem

I am new in Solidity and currently, I am trying to deploy a simple smart contract that requests ETH price "LOWDAY", and "HIGHDAY". I already did a very similar SC that requests only "VOLUME24HOUR" and it worked great. This is the error that I get:
contracts/API_Consumer_Info.sol:24:66: DeclarationError: Undeclared
identifier. Did you mean "jobID"? Chainlink.Request memory request =
buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
^---^
pragma solidity ^0.6.7;
import "#chainlink/contracts/src/v0.6/ChainlinkClient.sol";
contract APIConsumerInfo is ChainlinkClient
{
uint256 public lowDay;
uint256 public highDay;
address private oracle;
bytes32 private jobID;
uint256 private fee;
constructor() public
{
setPublicChainlinkToken();
oracle = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e;
jobID = "29fa9aa13bf1468788b7cc4a500a45b8";
fee = 0.1 * 10 ** 18;
}
function requestLowDay() public returns (bytes32 requestID)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); //Error occur here
request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
request.add("path", "RAW.ETH.USD.LOWDAY");
int timesAmount = 10**2;
request.addInt("times", timesAmount);
return sendChainlinkRequestTo(oracle, request, fee);
}
function fulfill(bytes32 _requestId, uint256 _dayLow) public recordChainlinkFulfillment(_requestId)
{
lowDay = _dayLow;
}
function requestHighDay() public returns (bytes32 requestID)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); //Error occur here
request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
request.add("path", "RAW.ETH.USD.HIGHDAY");
int timesAmount = 10**2;
request.addInt("times", timesAmount);
return sendChainlinkRequestTo(oracle, request, fee);
}
function fulfill(bytes32 _requestId, uint256 _dayHigh) public recordChainlinkFulfillment(_requestId)
{
highDay = _dayHigh;
}
function withdrawLink() external
{
LinkTokenInterface linkToken = LinkTokenInterface(chainlinkTokenAddress());
require(linkToken.transfer(msg.sender, linkToken.balanceOf(address(this))), "Unable to transfer");
}
}
The base code is not written by my and it works perfectly with "VOLUME24HOUR" call. When I did the necessary changes to request.add("path") and added new variable lowDay/highDay it started to throw error.
Thank you ʕっ•ᴥ•ʔっ
Solidity variable names are case-sensitive.
You have defined a bytes32 property named jobID (uppercase D) but then you're trying to pass jobId (lowercase d).
Solution: Pass the correct case-sensitive variable name. In your case jobID.

What is the type of `this` object in solidity

In the following claimPayment function that is used to claim a payment made earlier to this contract, the line bytes32 message = prefixed(keccak256(abi.encodePacked(msg.sender, amount, nonce, this))); has this as part of the signed message. This makes me wonder what is this and what the type of this is. If I'm returning this in a function, what type is used for it? Thanks.
function claimPayment(uint256 amount, uint256 nonce, bytes memory signature) public {
require(!usedNonces[nonce]);
usedNonces[nonce] = true;
// this recreates the message that was signed on the client
bytes32 message = prefixed(keccak256(abi.encodePacked(msg.sender, amount, nonce, this)));
require(recoverSigner(message, signature) == owner);
payable(msg.sender).transfer(amount);
}
this is a pointer to the current class instance, as in many other programming languages. You can for example point to public methods:
pragma solidity ^0.8.0;
contract MyContract {
function foo() external {
this.bar();
}
function bar() public {
}
}
When this is typecasted, it takes a form of the address, where the current instance is deployed.
pragma solidity ^0.8.0;
contract MyContract {
function foo() external view returns (bytes memory) {
return abi.encodePacked(this);
}
function bar() external view returns (address) {
return address(this);
}
}