// SPDX-License-Identifier: MITpragmasolidity ^0.8.20;import"https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.6/contracts/access/Ownable.sol";
import"https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.6/contracts/token/ERC20/ERC20.sol";
import"https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.6/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import"https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.6/contracts/token/ERC20/extensions/ERC20Permit.sol";
import {IApproveAndCallReceiver} from"./interfaces/IApproveAndCallReceiver.sol";
contractTokenisERC20, ERC20Burnable, ERC20Permit, Ownable{
constructor() ERC20("Goodle", "GOODLE") ERC20Permit("Goodle") {
_mint(_msgSender(), 100_000_000_000*1e18);
}
functionapproveAndCall(address spender, uint256 amount, bytescalldata extraData) externalreturns (bool) {
// Approve the spender to spend the tokens
_approve(msg.sender, spender, amount);
// Call the receiveApproval function on the spender contract
IApproveAndCallReceiver(spender).receiveApproval(msg.sender, amount, address(this), extraData);
returntrue;
}
}
Contract Source Code
File 21 of 21: TokenWhitelisted.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.24;import {Token} from"./Token.sol";
import {IWhitelist} from"./interfaces/IWhitelist.sol";
/**
* @title Extended token contract with whitelist contract interactions
* @notice During whitelist period, `_beforeTokenTransfer` function will call `checkWhitelist` function of whitelist contract
* @notice If whitelist period is ended, owner will set whitelist contract address back to address(0) and tokens will be transferred freely
*/contractTokenWhitelistedisToken{
/// @notice whitelist contract addressaddressprivate _whitelistContract;
/// @notice Returns current whitelist contract addressfunctionwhitelistContract() externalviewreturns (address) {
return _whitelistContract;
}
/// @notice Ownable function to set new whitelist contract addressfunctionsetWhitelistContract(address newWhitelistContract) externalonlyOwner{
_whitelistContract = newWhitelistContract;
}
/// @notice Before token transfer hook/// @dev It will call `checkWhitelist` function and if it's succsessful, it will transfer tokens, unless revertfunction_beforeTokenTransfer(addressfrom, address to, uint256 amount) internaloverride{
require(to !=address(this), "Cannot transfer to the token contract address");
if (_whitelistContract !=address(0)) {
IWhitelist(_whitelistContract).checkWhitelist(from, to, amount);
}
super._beforeTokenTransfer(from, to, amount);
}
}