Hi
I have a question to the upgradable Plugin.
I walked trough the Box contract example and i see there is a BoxV2.sol that upgrades the original Box.sol contract.
Lets say i customized the _transfer function in ERC20Upgradeable.sol with custom transaction Fees.
The ERC20Upgradeable.sol is imported on my main contract (lets call it also box.sol as
import “@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol”;
If i now create a 2nd. “BoxV2.sol” contract and change the import path to a new created ERC20UpgradeableV2.sol and then run the migration script.
I get this errors.
DeclarationError: Identifier already declared.
→ /home/ubuntu/contracts/box/contracts/box-V1.2.sol:5:1:
|
5 | import “@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol”;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: The previous declaration is here:
→ @openzeppelin/contracts-upgradeable/token/ERC20/ERC20UpgradeableV2.sol:34:1:
My question is, is it possible to upgrade the _transfer function located in the ERC20Upgradeable.sol?
For example if i want to change the fee or fee receiver i have static coded into the _transfer function?
Example _transfer function:
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
address FeeReceiverAdr = 0xE037D395bB24C69bD0347F4e1652199BF61a41d1;
address payable FeeReceiver = payable(FeeReceiverAdr); // Correct since Solidity >= 0.6.0
_beforeTokenTransfer(sender, recipient, amount);
uint bpsfee = 1618;
uint bps = 100000;
uint fee = amount/bps*bpsfee;
uint taxedValue = amount-fee;
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
_balances[sender] = senderBalance - amount;
_balances[recipient] += taxedValue;
_balances[FeeReceiver] += fee;
emit Transfer(sender, recipient, taxedValue);
emit Transfer(sender, FeeReceiver, fee);
}