Cyfrin / foundry-defi-stablecoin-cu

241 stars 107 forks source link

ERC20 constructor doesnt pass the name and symbol #90

Closed nymus933 closed 2 months ago

nymus933 commented 2 months ago

Before here i checked many places and searched on internet and also asked to GPT but there is something wrong i cant understand.

Error is;

[{
    "resource": "/home/enes/advanced-foundry-course-f23/defi-stablecoin-f24/src/DecentralizedStableCoin.sol",
    "owner": "solidity-language-server",
    "code": "3415",
    "severity": 8,
    "message": "No arguments passed to the base constructor. Specify the arguments or mark \"DecentralizedStableCoin\" as abstract.",
    "source": "solidity",
    "startLineNumber": 41,
    "startColumn": 1,
    "endLineNumber": 72,
    "endColumn": 2
}]

My code is;

pragma solidity ^0.8.18;

import {ERC20Burnable, ERC20} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

contract DecentralizedStableCoin is ERC20Burnable, Ownable {
    error DecentralizedStableCoin__MustBeMoreThanZero();
    error DecentralizedStableCoin__BurnAmountExceedsBalance();
    error DecentralizedStableCoin__NotZeroAddress();

    constructor() ERC20("DecentralizedStableCoin", "DSC") {}

    function burn(uint256 _amount) public override onlyOwner {
        uint256 balance = balanceOf(msg.sender);
        if (_amount <= 0) {
            revert DecentralizedStableCoin__MustBeMoreThanZero();
        }
        if (balance <= _amount) {
            revert DecentralizedStableCoin__BurnAmountExceedsBalance();
        }
        super.burn(_amount);
    }

    function mint(
        address _to,
        uint256 _amount
    ) external onlyOwner returns (bool) {
        if (_to == address(0)) {
            revert DecentralizedStableCoin__NotZeroAddress();
        }
        if (_amount <= 0) {
            revert DecentralizedStableCoin__MustBeMoreThanZero();
        }
        _mint(_to, _amount);
        return true;
    }
}
EngrPips commented 2 months ago

Hello @nymus933, you have used the wrong channel. Please post this using the discussions channel.

cromewar commented 2 months ago

@nymus933 yes, @EngrPips is correct please can we move this to the discussions section?

Just to give you some context, when you import from a library like OpenZeppelin or you using a interface this means you are using all the functions on the origin smart contract, some of those functions are not implemented by default and when you don't implement the functions it becomes either an Abstract contract or another interface.

That's why you need to implement all the functions required on the origin smart contract import.

In this case I'd say you are not implementing all the functions required on ERCBurnable.

nymus933 commented 2 months ago

Hello @nymus933, you have used the wrong channel. Please post this using the discussions channel.

This is my first post on GitHub. I am sorry for wrong place 👍 I should get used to use GitHub in time :)

nymus933 commented 2 months ago

@nymus933 yes, @EngrPips is correct please can we move this to the discussions section?

Just to give you some context, when you import from a library like OpenZeppelin or you using a interface this means you are using all the functions on the origin smart contract, some of those functions are not implemented by default and when you don't implement the functions it becomes either an Abstract contract or another interface.

That's why you need to implement all the functions required on the origin smart contract import.

In this case I'd say you are not implementing all the functions required on ERCBurnable.

Thanks a lot for the response. I understand how it works now. Is there any short way to move my post to the discussions section? Or should I complete this one only?

EngrPips commented 2 months ago

You can complete this and use the discussion channel instead next time for stuff like this