this is is my contract im pretty new to coding and so far have this much done.
i want to be able to get it to finally pass deployment test
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
contract BlackNaga is ERC20Upgradeable, ERC20BurnableUpgradeable, OwnableUpgradeable {
address public constant BURN_ADDRESS = 0x000000000000000000000000000000000000dEaD;
// Tokenomics parameters
uint256 public burnPercent;
uint256 public marketingDevFeePercent;
uint256 public reflectionFeePercent;
uint256 public charityFeePercent;
uint256 public teamDevelopmentFeePercent;
// Limits and balances
uint256 public maxTransactionAmount;
uint256 public maxBurnAmount;
uint256 public maxWalletBalance;
// Addresses
address public marketingDevAddress;
address public reflectionAddress;
address public teamDevelopmentAddress;
address public charityAddress;
// State variables
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
// Initialize contract
function initialize() public initializer {
__ERC20_init("BlackNaga", "BLNA");
__ERC20Burnable_init();
__Ownable_init(msg.sender);
uint256 initialSupply = 400 * (10 ** 18); // Total supply of 400 sextillion tokens with 18 decimals
uint256 tokensToBurn = initialSupply / 2; // Burn 50% of the initial supply
_mint(msg.sender, initialSupply); // Mint initial supply to the deployer
_burn(msg.sender, tokensToBurn); // Burn tokens immediately
// Set initial values
burnPercent = 5;
marketingDevFeePercent = 2;
reflectionFeePercent = 2;
charityFeePercent = 1;
teamDevelopmentFeePercent = 2;
maxTransactionAmount = (400 * 10**21) / 100;
maxBurnAmount = 200000000 * 10**18; // 200 million tokens
maxWalletBalance = 400 * 10**21;
// Set initial addresses (update with actual addresses)
marketingDevAddress = 0xfeB4660C633beE5ecE0955e3330B4619923B6d7C;
reflectionAddress = 0x81B6777039559c7396938ED17Ba39e71cE740cE7;
teamDevelopmentAddress = 0x10a0FF128b37176277EC259E2CC469cD3cd10276;
charityAddress = 0xD1b3A8E763d6c36d57BF9696a8595402BD54120E;
// Ensure addresses are set correctly
require(marketingDevAddress != address(0), "Invalid marketingDevAddress");
require(reflectionAddress != address(0), "Invalid reflectionAddress");
require(teamDevelopmentAddress != address(0), "Invalid teamDevelopmentAddress");
require(charityAddress != address(0), "Invalid charityAddress");
transferOwnership(msg.sender);
}
event MaxTransactionAmountChanged(uint256 newMaxTransactionAmount);
event MaxWalletBalanceChanged(uint256 newMaxWalletBalance);
// Function to set max transaction amount (only owner)
function setMaxTransactionAmount(uint256 amount) external onlyOwner {
require(amount > 0, "Max transaction amount must be greater than zero");
maxTransactionAmount = amount;
emit MaxTransactionAmountChanged(amount);
}
function setMaxWalletBalance(uint256 balance) external onlyOwner {
require(balance > 0, "Max wallet balance must be greater than zero");
maxWalletBalance = balance;
emit MaxWalletBalanceChanged(balance);
}
// Function to transfer ownership of the contract
function transferOwnership(address newOwner) public virtual override onlyOwner {
require(newOwner != address(0), "New owner is the zero address");
emit OwnershipTransferred(owner(), newOwner);
_transferOwnership(newOwner);
}
// ERC20 functions
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_customTransfer(msg.sender, recipient, amount);
return true;
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_customTransfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][msg.sender];
require(currentAllowance >= amount, "Transfer amount exceeds allowance");
unchecked {
_approve(sender, msg.sender, currentAllowance - amount);
}
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
require(addedValue > 0, "Cannot increase allowance to zero");
_approve(msg.sender, spender, _allowances[msg.sender][spender] + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
uint256 currentAllowance = _allowances[msg.sender][spender];
require(currentAllowance >= subtractedValue, "Decreased allowance below zero");
unchecked {
_approve(msg.sender, spender, currentAllowance - subtractedValue);
}
return true;
}
function burn(uint256 amount) public virtual override onlyOwner {
super.burn(amount);
}
// Internal function to handle custom token transfers between addresses
function _customTransfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "Transfer from the zero address");
require(recipient != address(0), "Transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
require(amount <= maxTransactionAmount, "Transfer amount exceeds the max transaction limit");
require(recipient.code.length == 0, "Transfer to a contract address is not allowed");
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "Transfer amount exceeds balance");
if (sender != owner() && recipient != owner()) {
require(_balances[recipient] + amount <= maxWalletBalance, "Transfer amount exceeds the max wallet balance");
}
uint256 burnAmount = 0;
if (totalSupply() > 200000000 * 10**18) {
burnAmount = (amount * burnPercent) / 100;
}
uint256 marketingDevFee = (amount * marketingDevFeePercent) / 100;
uint256 reflectionFee = (amount * reflectionFeePercent) / 100;
uint256 charityFee = (amount * charityFeePercent) / 100;
uint256 teamDevelopmentFee = (amount * teamDevelopmentFeePercent) / 100;
uint256 transferAmount = amount - (burnAmount + marketingDevFee + reflectionFee + charityFee + teamDevelopmentFee);
unchecked {
_balances[sender] = senderBalance - amount;
_balances[recipient] += transferAmount;
_balances[BURN_ADDRESS] += burnAmount;
_balances[marketingDevAddress] += marketingDevFee;
_balances[reflectionAddress] += reflectionFee;
_balances[charityAddress] += charityFee;
_balances[teamDevelopmentAddress] += teamDevelopmentFee;
}
emit Transfer(sender, recipient, transferAmount);
emit Transfer(sender, BURN_ADDRESS, burnAmount);
emit Transfer(sender, marketingDevAddress, marketingDevFee);
emit Transfer(sender, reflectionAddress, reflectionFee);
emit Transfer(sender, charityAddress, charityFee);
emit Transfer(sender, teamDevelopmentAddress, teamDevelopmentFee);
}
}
im failing these test
1 passing (5s)
7 failing
-
Contract: BlackNaga
should deploy and initialize correctly:
Error: Assertion failed
at assert (node_modules\web3-utils\node_modules\bn.js\lib\bn.js:6:21)
at BN._initNumber (node_modules\web3-utils\node_modules\bn.js\lib\bn.js:128:7)
at BN.init [as _init] (node_modules\web3-utils\node_modules\bn.js\lib\bn.js:82:19)
at new BN (node_modules\web3-utils\node_modules\bn.js\lib\bn.js:39:12)
at new BNwrapped (node_modules\web3-utils\lib\utils.js:488:16)
at Context. (test\BlackNagatest.js:35:47)
at processTicksAndRejections (node:internal/process/task_queues:95:5) -
Contract: BlackNaga
should allow owner to set max transaction amount:Wrong kind of exception received
- expected - actual
-VM Exception while processing transaction: revert -- Reason given: Custom error (could not decode).
+Ownable: caller is not the ownerat expectException (node_modules@openzeppelin\test-helpers\src\expectRevert.js:20:30)
at expectRevert (node_modules@openzeppelin\test-helpers\src\expectRevert.js:75:3)
at Context. (test\BlackNagatest.js:48:9) -
Contract: BlackNaga
should allow owner to set max wallet balance:Wrong kind of exception received
- expected - actual
-VM Exception while processing transaction: revert -- Reason given: Custom error (could not decode).
+Ownable: caller is not the ownerat expectException (node_modules@openzeppelin\test-helpers\src\expectRevert.js:20:30)
at expectRevert (node_modules@openzeppelin\test-helpers\src\expectRevert.js:75:3)
at Context. (test\BlackNagatest.js:63:9) -
Contract: BlackNaga
should allow owner to transfer ownership:Wrong kind of exception received
- expected - actual
-VM Exception while processing transaction: revert -- Reason given: Custom error (could not decode).
+Ownable: caller is not the ownerat expectException (node_modules@openzeppelin\test-helpers\src\expectRevert.js:20:30)
at expectRevert (node_modules@openzeppelin\test-helpers\src\expectRevert.js:75:3)
at Context. (test\BlackNagatest.js:84:9) -
Contract: BlackNaga
should transfer tokens correctly:
Error: VM Exception while processing transaction: revert Transfer amount exceeds balance -- Reason given: Transfer amount exceeds balance.
at Context. (test\BlackNagatest.js:94:52)
at processTicksAndRejections (node:internal/process/task_queues:95:5) -
Contract: BlackNaga
should transfer from tokens correctly:
Error: VM Exception while processing transaction: revert Transfer amount exceeds balance -- Reason given: Transfer amount exceeds balance.
at Context. (test\BlackNagatest.js:141:56)
at processTicksAndRejections (node:internal/process/task_queues:95:5) -
Contract: BlackNaga
should burn tokens correctly:
Error: Assertion failed
at assert (node_modules\web3-utils\node_modules\bn.js\lib\bn.js:6:21)
at BN._initNumber (node_modules\web3-utils\node_modules\bn.js\lib\bn.js:128:7)
at BN.init [as _init] (node_modules\web3-utils\node_modules\bn.js\lib\bn.js:82:19)
at new BN (node_modules\web3-utils\node_modules\bn.js\lib\bn.js:39:12)
at new BNwrapped (node_modules\web3-utils\lib\utils.js:488:16)
at Context. (test\BlackNagatest.js:168:31)
at processTicksAndRejections (node:internal/process/task_queues:95:5)