// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)pragmasolidity ^0.8.20;/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (address) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytescalldata) {
returnmsg.data;
}
function_contextSuffixLength() internalviewvirtualreturns (uint256) {
return0;
}
}
Contract Source Code
File 2 of 9: ERC20.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)pragmasolidity 0.8.20;import {IERC20} from"@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {Context} from"@openzeppelin/contracts/utils/Context.sol";
interfaceIERC20Errors{
errorERC20InvalidSender(address sender);
errorERC20InvalidReceiver(address receiver);
errorERC20InvalidApprover(address approver);
errorERC20InvalidSpender(address spender);
errorERC20InsufficientBalance(address owner, uint256 balance, uint256 value);
errorERC20InsufficientAllowance(address spender, uint256 allowance, uint256 value);
}
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/abstractcontractERC20isContext, IERC20, IERC20Metadata, IERC20Errors{
mapping(address account =>uint256) internal _balances;
mapping(address account =>mapping(address spender =>uint256)) private _allowances;
uint256internal _totalSupply;
stringprivate _name;
stringprivate _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/constructor(stringmemory name_, stringmemory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/functionname() publicviewvirtualreturns (stringmemory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/functionsymbol() publicviewvirtualreturns (stringmemory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/functiondecimals() publicviewvirtualreturns (uint8) {
return18;
}
/**
* @dev See {IERC20-totalSupply}.
*/functiontotalSupply() publicviewvirtualreturns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/functionbalanceOf(address account) publicviewvirtualreturns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/functiontransfer(address to, uint256 value) publicvirtualreturns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
returntrue;
}
/**
* @dev See {IERC20-allowance}.
*/functionallowance(address owner, address spender) publicviewvirtualreturns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionapprove(address spender, uint256 value) publicvirtualreturns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
returntrue;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/functiontransferFrom(addressfrom, address to, uint256 value) publicvirtualreturns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
returntrue;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/function_transfer(addressfrom, address to, uint256 value) internal{
if (from==address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to ==address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/function_update(addressfrom, address to, uint256 value) internalvirtual{
if (from==address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to ==address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/function_mint(address account, uint256 value) internal{
if (account ==address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/function_burn(address account, uint256 value) internal{
if (account ==address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/function_approve(address owner, address spender, uint256 value) internal{
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/function_approve(address owner, address spender, uint256 value, bool emitEvent) internalvirtual{
if (owner ==address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender ==address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/function_spendAllowance(address owner, address spender, uint256 value) internalvirtual{
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance !=type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}
Contract Source Code
File 3 of 9: IERC20.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)pragmasolidity ^0.8.20;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address to, uint256 value) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/functionapprove(address spender, uint256 value) externalreturns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(addressfrom, address to, uint256 value) externalreturns (bool);
}
Contract Source Code
File 4 of 9: IERC20Metadata.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)pragmasolidity ^0.8.20;import {IERC20} from"../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*/interfaceIERC20MetadataisIERC20{
/**
* @dev Returns the name of the token.
*/functionname() externalviewreturns (stringmemory);
/**
* @dev Returns the symbol of the token.
*/functionsymbol() externalviewreturns (stringmemory);
/**
* @dev Returns the decimals places of the token.
*/functiondecimals() externalviewreturns (uint8);
}
// SPDX-License-Identifier: UNLICENSEDpragmasolidity 0.8.20;import {TaxToken} from"./TaxToken.sol";
import {TokenErrors} from"./lib/TokenErrors.sol";
interfaceILotteryMaster{
functionupkeep(uint256 loops) external;
functionaddEntry(address user, uint256 entryAmount) external;
}
/**
* @title Lottery Token
* @author Robert M.C. Forster
* @notice Actual token for the lottery scheme. Tax token that also adds taxes to a lottery pot.
* @dev On every single token transfer it also calls back to the lottery master to check
* whether previous entries for any token have won their own lottery.
*/contractLotteryTokenisTaxToken{
uint256publicconstant POT_PERCENT_UPDATE_DELAY =1days;
// The maximum amount over entry amount that the user can win.// 10000 == 100xuint256public maxWinMultiplier;
// Factory contract that holds all lottery token entries.addresspublic lotteryMaster;
eventLotteryWin(address user, uint256 entryAmount, uint256 winnings, uint256 timestamp);
constructor(stringmemory _name,
stringmemory _symbol,
uint256 _initialSupply,
uint256 _maxWinMultiplier,
address _weth,
address _lotteryMaster,
address _limitOrderContract
) TaxToken(_name, _symbol, _initialSupply, _weth, _limitOrderContract) {
maxWinMultiplier = _maxWinMultiplier;
lotteryMaster = _lotteryMaster;
}
/* ********************************************* INTERNAL ********************************************* */// OpenZeppelin ERC20 _update with only change being upkeep and entry calls.function_update(addressfrom, address to, uint256 value) internaloverride{
// Every transfer calls to upkeep the lottery.if (lotteryMaster !=address(0)) ILotteryMaster(lotteryMaster).upkeep(0);
uint256 tax = _determineTax(from, to, value);
// We need to sell taxes before updating balances because user transfer// to pair contract will trigger sell taxes and update reserves by using// the new balance reverting the transaction.if (tax >0) {
_awardTaxes(from, tax);
} else {
uint256 balance = _balances[address(this)];
if (balance !=0) _sellTaxes(balance);
}
// Final value to be received by address.uint256 receiveValue = value - tax;
if (from==address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
// Add lottery entry for the user receiving tokens.// Making sure that `to` is not taxed so that dexes don't win the lottery.if (taxed[from] &&!taxed[to] && lotteryMaster !=address(0)) {
ILotteryMaster(lotteryMaster).addEntry(to, value);
}
}
if (to ==address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.// Weird situation with taxes but if you somehow tax burning it should be receiveValue here.
_totalSupply -= receiveValue;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.// Default value here changed to receiveValue to account for possible taxes.
_balances[to] += receiveValue;
}
}
emit Transfer(from, to, value);
}
/**
* @dev In versions with more advanced tax features, this function will be overridden.
* @param _amount Amount of tax tokens to be awarded.
*
*/function_awardTaxes(address _from, uint256 _amount) internaloverride{
_balances[lotteryMaster] += _amount;
emit Transfer(_from, lotteryMaster, _amount);
}
/* ********************************************* PRIVILEGED ********************************************* *//**
* @notice Lottery master calls in here to payout a win.
* @param _user The user address who's won the lottery.
* @param _entryAmount The amount of tokens they purchased with this entry which determines their maximum win.
*
*/functionpayWinner(address _user, uint256 _entryAmount) external{
if (msg.sender!= lotteryMaster) revert TokenErrors.OnlyLotteryMaster();
uint256 lotteryPot = _balances[lotteryMaster];
uint256 maxWin = (_entryAmount * maxWinMultiplier) / _DIVISOR;
uint256 winnings = maxWin < lotteryPot ? maxWin : lotteryPot;
_balances[lotteryMaster] -= winnings;
_balances[_user] += winnings;
emit Transfer(lotteryMaster, _user, winnings);
emit LotteryWin(_user, _entryAmount, winnings, block.timestamp);
}
}
Contract Source Code
File 7 of 9: Ownable.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)pragmasolidity ^0.8.20;import {Context} from"../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/abstractcontractOwnableisContext{
addressprivate _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/errorOwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/errorOwnableInvalidOwner(address owner);
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/constructor(address initialOwner) {
if (initialOwner ==address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/modifieronlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewvirtualreturns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/function_checkOwner() internalviewvirtual{
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/functionrenounceOwnership() publicvirtualonlyOwner{
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
if (newOwner ==address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/function_transferOwnership(address newOwner) internalvirtual{
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Contract Source Code
File 8 of 9: TaxToken.sol
// SPDX-License-Identifier: UNLICENSEDpragmasolidity 0.8.20;import {Ownable} from"@openzeppelin/contracts/access/Ownable.sol";
import {ERC20, IERC20} from"./ERC20.sol";
import {TokenErrors} from"./lib/TokenErrors.sol";
import {IUniswapV3Pool} from"../interfaces/IUniswapV3Pool.sol";
/**
* @title Plain Tax Token
* @author Robert M.C. Forster
* @notice This is a pretty plain tax token. When a transfer is made to or from a dex, a sell or buy tax is applied respectively.
* The tax is taken in tokens, then when it gets past a minimum amount a dex swap is automatically executed to trade the
* taxes for Ether. Ownership is split between "owner" and "treasury" so the power to change taxes can be relinquished
* without losing the power to change where taxes are sent or change what dex taxes are sold on.
*
*/contractTaxTokenisERC20, Ownable{
uint256internalconstant _DIVISOR =10_000;
uint256internalconstant _TAX_MAX =1_000;
addressinternalimmutable _WETH;
addresspublic limitOrderContract;
IUniswapV3Pool public pool;
eventDexUpdated(addressindexed oldDex, addressindexed newDex);
eventTaxesUpdated(addressindexed dex, uint256 buyTax, uint256 sellTax);
/// @notice swap routeraddresspublic dex;
uint24internal poolFee;
// Pool address => % tax on the pool, 100 == 1%, 1000 (10%) maximum.mapping(address=>uint256) public buyTax;
mapping(address=>uint256) public sellTax;
// Used in some iterations such as TaxShare in a situation where a dex should be excluded from activity.mapping(address=>bool) public taxed;
/* ********************************************* CONSTRUCTOR ********************************************* */constructor(stringmemory _name,
stringmemory _symbol,
uint256 _initialSupply,
address _weth,
address _limitOrderContract
) ERC20(_name, _symbol) Ownable(msg.sender) {
_WETH = _weth;
_mint(msg.sender, _initialSupply);
// Default pool fee is 1%
poolFee =10000;
limitOrderContract = _limitOrderContract;
}
/* ********************************************* INTERNAL ********************************************* */// If transfer is from a dex, apply buy tax// If transfer is to a dex, apply sell tax// Add tax to token contract balance and/or rewardAmount or lotteryAmount// If token contract balance is above a certain amount, sell tokens// OpenZeppelin ERC20 _update with only change being _updateRewards calls.function_update(addressfrom, address to, uint256 value) internalvirtualoverride{
uint256 tax = _determineTax(from, to, value);
// We need to sell taxes before updating balances because user transfer// to pair contract will trigger sell taxes and update reserves by using// the new balance reverting the transaction.if (tax >0) {
_awardTaxes(from, tax);
} else {
uint256 balance = _balances[address(this)];
if (balance !=0) _sellTaxes(balance);
}
// Final value to be received by address.uint256 receiveValue = value - tax;
if (from==address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to ==address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= receiveValue;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.// Default value here changed to receiveValue to account for possible taxes.
_balances[to] += receiveValue;
}
}
emit Transfer(from, to, receiveValue);
}
/**
* @notice Determine how much tax needs to be paid.
* @param _from User/contract that funds are being sent from.
* @param _to User/contract that funds are being sent to.
* @param _value Value of the funds being sent.
*
*/function_determineTax(address _from, address _to, uint256 _value) internalviewreturns (uint256 taxAmount) {
// Bypass tax if the transfer is from the LimitOrder contractif (_from == limitOrderContract) return0;
uint256 fromTax = buyTax[_from];
uint256 toTax = sellTax[_to];
// If there's no tax, will just equal 0.
taxAmount += _value * fromTax / _DIVISOR;
taxAmount += _value * toTax / _DIVISOR;
}
/**
* @notice Give tax balances to a new address.
* @dev In versions with more advanced tax features, this function will be overridden.
* @param _amount Amount of tax tokens to be awarded.
*
*/function_awardTaxes(address _from, uint256 _amount) internalvirtual{
address to =address(this);
_balances[to] += _amount;
emit Transfer(_from, to, _amount);
}
/**
* @notice Sells the collected tax tokens in a pool.
* @param tokens amount of tokens to sell
*/function_sellTaxes(uint256 tokens) internalvirtual{
// Implementation to be provided in child contracts
}
/* ********************************************* ONLY OWNER ********************************************* *//**
* @notice Change the dex that taxes are to be sold on. Requires V3 Router interface
* @param _dexAddress router address
*
*/functionchangeDex(address _dexAddress) externalonlyOwner{
address oldDex = dex;
if (dex !=address(0)) {
IERC20(address(this)).approve(dex, 0);
}
dex = _dexAddress;
IERC20(address(this)).approve(_dexAddress, type(uint256).max);
emit DexUpdated(oldDex, _dexAddress);
}
/* ********************************************* ONLY OWNER ********************************************* *//**
* @notice Set taxes of a specific dex/address based on buy and sell.
* @dev This is onlyOwner rather than including treasury so that a team can renounce ownership
* of this critical function while maintaining ownership of non-critical treasury functions.
* @param _dex Address of the dex that taxes are being added to when a transfer is made from/to it.
* @param _buyTax The tax for buys (transactions coming from the address). 1% == 100.
* @param _sellTax The tax for sells (transactions going to the address). 1% == 100.
*/functionsetTaxes(address _dex, uint256 _buyTax, uint256 _sellTax) externalvirtualonlyOwner{
_setTaxes(_dex, _buyTax, _sellTax);
}
/**
* @notice Internal helper function to set taxes for a specific dex/address.
* @dev Performs all the checks and updates related to setting taxes.
* @param _dex Address of the dex that taxes are being added to when a transfer is made from/to it.
* @param _buyTax The tax for buys (transactions coming from the address). 1% == 100.
* @param _sellTax The tax for sells (transactions going to the address). 1% == 100.
*/function_setTaxes(address _dex, uint256 _buyTax, uint256 _sellTax) internal{
if (_buyTax > _TAX_MAX || _sellTax > _TAX_MAX) revert TokenErrors.TaxTooHigh();
if (taxed[_dex] && _buyTax !=0&& _sellTax !=0) revert TokenErrors.TaxAlreadySet();
if (_dex ==address(this)) revert TokenErrors.CannotTaxSelf();
buyTax[_dex] = _buyTax;
sellTax[_dex] = _sellTax;
if (_buyTax >0|| _sellTax >0) taxed[_dex] =true;
else taxed[_dex] =false;
emit TaxesUpdated(_dex, _buyTax, _sellTax);
}
functionsetPoolFee(uint24 fee) externalonlyOwner{
poolFee = fee;
}
functionsetPool(address _pool) externalonlyOwner{
pool = IUniswapV3Pool(_pool);
}
/* ********************************************* VIEW FUNCTIONS ********************************************* */functiongetTaxes(address _dex) externalviewreturns (uint256 buy, uint256 sell) {
return (buyTax[_dex], sellTax[_dex]);
}
}