Verified contractExact
NXDERC20
Address0xcd6db53abd32c1b58265e5468a94efa3b41e37e4
- Balance
0 ETH
- Transactions
203
- Compiler
solc 0.8.24
- Same code
Only this contract
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- paris
- License
- Not stated
- Match
- Exactcreation code: no, runtime code: yes
- Verified on Sourcify
- Created in block
- 24,775,434
12 files
- contracts/NXDERC20.solmain19.42 KB
- @openzeppelin/contracts/token/ERC20/ERC20.sol12.85 KB
- @openzeppelin/contracts/token/ERC20/IERC20.sol2.74 KB
- @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol683 B
- @openzeppelin/contracts/utils/Context.sol962 B
- contracts/TaxRecipient.sol1.96 KB
- contracts/interfaces/INXDProtocol.sol506 B
- contracts/interfaces/IUniswapV2Pair.sol2.66 KB
- contracts/interfaces/IUniswapV2Router01.sol3.97 KB
- contracts/interfaces/IUniswapV2Router02.sol1.31 KB
- contracts/interfaces/IV2Oracle.sol337 B
- contracts/interfaces/draft-IERC6093.sol1.8 KB
contracts/NXDERC20.sol
pragma solidity ^0.8.13;
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
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";
import {IERC20Errors} from "./interfaces/draft-IERC6093.sol";
import "./interfaces/IUniswapV2Router02.sol";
import "./interfaces/IUniswapV2Pair.sol";
import "./interfaces/IV2Oracle.sol";
import "./interfaces/INXDProtocol.sol";
import "./TaxRecipient.sol";
interface IUniV2Factory {
function getPair(address tokenA, address tokenB) external view returns (address pair);
}
/**
* @dev NXD Token contract that implements the ERC20 standard. It also includes:
* - A tax mechanism for selling NXD tokens.
* - A mechanism to remove NXD tokens from unauthorized LPs. Only called by the governance
* - A mechanism to mint NXD tokens Only by the protocol contract.
* - A mechanism to set the Uniswap V2 pair address and the V2 Oracle address. Only by the protocol contract.
* - A mechanism to remove NXD tokens from unauthorized LPs. Only by the governance.
*/
contract NXDERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
error Unauthorized();
error NoRemovalZeroAddress();
error NoLPWithdraw();
error MaxSupply();
error NoRemovalMainLP();
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
address public constant DEADBEEF = 0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* The address of the NXDProtocol.sol contract instance.
*/
address public immutable protocol;
uint256 public constant SELL_TAX_X100 = 500; // 5%
struct TaxWhitelist {
bool isExcludedWhenSender;
bool isExcludedWhenRecipient;
}
// Whitelist for tax exclusion. address => (isExcludedWhenSender, isExcludedWhenRecipient)
mapping(address => TaxWhitelist) public isExcludedFromTax;
mapping(address => uint256) public lpSupplyOfPair;
IUniV2Factory public UNISWAP_V2_FACTORY = IUniV2Factory(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f);
IUniswapV2Router02 public UNISWAP_V2_ROUTER = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
IUniswapV2Pair public uniswapV2Pair;
IV2Oracle public v2Oracle;
IERC20 public dxn;
// Max to be minted as rewards for staking DXN
uint256 public constant MAX_REWARDS_SUPPLY = 730_000 ether; // 730k NXD
// Max to be minted for dev alloc (2% of total supply)
uint256 public constant MAX_DEV_ALLOC = 15_000 ether; // 15k NXD
// Max rewards supply + initial supply for liquidity
uint256 public immutable maxSupply;
TaxRecipient public immutable taxRecipient;
uint256 public lastSupplyOfNXDInPair;
uint256 public lastSupplyOfDXNInPair;
address public governance;
address public devFeeTo;
uint256 public totalNXDBurned;
// variables used to calculate rewards apy
uint256 public contractStartBlock;
uint256 public epochCalculationStartBlock;
uint256 public epoch;
// Returns burns since start of this contract
function averageBurnedPerBlockSinceStart() external view returns (uint256 averagePerBlock) {
uint256 burnedInThisEpoch =
_balances[0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF] - totalBurnAddressBalUpToLastEpoch;
averagePerBlock = (totalBurnAddressBalUpToLastEpoch + burnedInThisEpoch) / (block.number - (contractStartBlock));
}
// Returns averge burned in this epoch
function averageBurnedPerBlockEpoch() external view returns (uint256 averagePerBlock) {
uint256 burnedInThisEpoch =
_balances[0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF] - totalBurnAddressBalUpToLastEpoch;
averagePerBlock = burnedInThisEpoch / (block.number - epochCalculationStartBlock);
}
struct EpochBurn {
uint256 burned;
uint256 totalSupply;
}
// For easy graphing historical epoch burns
mapping(uint256 => EpochBurn) public epochBurns;
uint256 public totalBurnAddressBalUpToLastEpoch;
//Starts a new calculation epoch
// Because averge since start will not be accurate
function startNewEpochIfReady() public {
if (epochCalculationStartBlock + 50000 < block.number) {
uint256 burnedInThisEpoch =
_balances[0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF] - totalBurnAddressBalUpToLastEpoch;
totalBurnAddressBalUpToLastEpoch = _balances[0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF];
epochBurns[epoch] = EpochBurn(burnedInThisEpoch, _totalSupply);
epochCalculationStartBlock = block.number;
++epoch;
}
}
modifier onlyGovernance() {
if (msg.sender != governance) {
revert Unauthorized();
}
_;
}
/**
* Called from within the NXDProtocol.sol constructor.
*/
constructor(
uint256 _initialSupply,
address _initialSupplyTo,
IERC20 _dxn,
address _governance,
address _vesting,
address _devFeeTo
) {
_name = "NXD Token V2";
_symbol = "NXDv2";
protocol = msg.sender;
devFeeTo = _devFeeTo;
_mint(_initialSupplyTo, _initialSupply);
dxn = _dxn;
maxSupply = _initialSupply + MAX_REWARDS_SUPPLY + MAX_DEV_ALLOC;
taxRecipient = new TaxRecipient(msg.sender);
governance = _governance;
_updateTaxWhitelist(address(this), true, false);
_updateTaxWhitelist(address(taxRecipient), true, false);
_updateTaxWhitelist(protocol, true, true);
_updateTaxWhitelist(_vesting, true, true);
contractStartBlock = block.number;
startNewEpochIfReady();
}
function setUniswapV2Pair(address _uniswapV2Pair) external {
if (msg.sender != protocol) {
revert Unauthorized();
}
uniswapV2Pair = IUniswapV2Pair(_uniswapV2Pair);
_updateTaxWhitelist(_uniswapV2Pair, true, false);
}
function setV2Oracle(address _v2Oracle) external {
if (msg.sender != protocol) {
revert Unauthorized();
}
v2Oracle = IV2Oracle(_v2Oracle);
}
function updateTaxWhitelist(address account, bool whenSender, bool whenRecipient) external {
// Only governance or protocol can update tax whitelist
if (msg.sender != governance && msg.sender != protocol) {
revert Unauthorized();
}
_updateTaxWhitelist(account, whenSender, whenRecipient);
}
/**
* @dev Sets the governance address. Only callable by the current governance. Can be set to the zero address.
* @param _governance The address of the new governance.
*/
function setGovernance(address _governance) external onlyGovernance {
governance = _governance;
}
function _updateTaxWhitelist(address account, bool whenSender, bool whenRecipient) internal {
isExcludedFromTax[account] = TaxWhitelist(whenSender, whenRecipient);
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
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}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (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.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @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 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(address from, address to, uint256 value) internal virtual {
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 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:
* ```
* 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) internal virtual {
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) internal virtual {
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);
}
}
}
function mint(address account, uint256 amount) external {
if (msg.sender != protocol) {
revert Unauthorized();
}
if (totalSupply() + amount > maxSupply - MAX_DEV_ALLOC) {
revert MaxSupply();
}
_mint(account, amount);
}
function mintDevAlloc(address account, uint256 amount) external {
if (msg.sender != protocol) {
revert Unauthorized();
}
if (totalSupply() + amount > maxSupply) {
revert MaxSupply();
}
_mint(account, amount);
}
/**
* @dev Returns the amount after tax and the tax amount. Whitelist is:
* - When sender is this contract: To be able to swap NXD to DXN in `_transfer_ function.
* - When sender is the `protocol` contract: To be able to burn NXD.
* - When recipient is the `protocol` contract: To be able to create initial liquidity.
* - When sender is the `taxRecipient` contract: To be able to handle tax: adding liquidity to NXD/DXN.
* - When sender is the `uniswapV2Pair` contract: No tax on buys.
* @param from The address of the sender.
* @param to The address of the recipient.
* @param amount The amount to calculate the tax for.
* @return uint256 The amount after tax.
* @return uint256 The tax amount.
*/
function getAmountsAfterTax(address from, address to, uint256 amount) public view returns (uint256, uint256) {
if (isExcludedFromTax[from].isExcludedWhenSender || isExcludedFromTax[to].isExcludedWhenRecipient) {
return (amount, 0);
}
// Apply tax
uint256 taxAmount = (amount * SELL_TAX_X100) / 10000;
uint256 amountAfterTax = amount - taxAmount;
return (amountAfterTax, taxAmount);
}
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
if (value > _balances[from]) {
revert ERC20InsufficientBalance(from, _balances[from], value);
}
_balances[from] -= value;
(uint256 amountAfterTax, uint256 taxAmount) = getAmountsAfterTax(from, to, value);
if (taxAmount > 0) {
// NXD burn - 2.0%
// DXN buy and stake - 1.5%
// LP add - 1%
// Dev Fee - 0.5%
_balances[address(this)] += taxAmount;
emit Transfer(from, address(this), taxAmount);
address[] memory nxdDXNPath = new address[](2);
nxdDXNPath[0] = address(this);
nxdDXNPath[1] = address(dxn);
// Sell NXD, buy DXN and stake
uint256 sellNXDAmount = (taxAmount * 4000) / 10000; // 40% (2/5) of total tax amount, which is 1.5% buy and stake DXN + 0.5% buy DXN to add liquidity
_approve(address(this), address(UNISWAP_V2_ROUTER), sellNXDAmount);
if (v2Oracle.canUpdate()) {
v2Oracle.update();
}
uint256 amountOutMin = v2Oracle.consult(address(this), sellNXDAmount);
// - 3%
amountOutMin = (amountOutMin * 9700) / 10000;
// Send to taxRecipient to add LP
UNISWAP_V2_ROUTER.swapExactTokensForTokensSupportingFeeOnTransferTokens(
sellNXDAmount, amountOutMin, nxdDXNPath, address(taxRecipient), block.timestamp
);
// We now have DXN
uint256 remainingTax = taxAmount - sellNXDAmount; // 60%
uint256 burnAmount = (taxAmount * 3000) / 10000; // 30% of tax = 1.5% of transfer
uint256 devFeeAmount = (taxAmount * 2000) / 10000; // 20% of tax = 1% of transfer
_balances[address(this)] -= remainingTax;
startNewEpochIfReady();
// Burn 10% from tax amount
_balances[0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF] += burnAmount;
totalNXDBurned += burnAmount;
emit Transfer(address(this), 0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF, burnAmount);
_balances[devFeeTo] += devFeeAmount;
emit Transfer(address(this), devFeeTo, devFeeAmount);
uint256 amountToTaxHandler = remainingTax - burnAmount - devFeeAmount;
// Send NXD to Tax recipient to add liquidity
_balances[address(taxRecipient)] += amountToTaxHandler;
emit Transfer(address(this), address(taxRecipient), amountToTaxHandler);
taxRecipient.handleTax();
}
_balances[to] += amountAfterTax;
emit Transfer(from, to, amountAfterTax);
}
function setDevFeeTo(address _devFeeTo) external {
if (msg.sender != devFeeTo) {
revert Unauthorized();
}
devFeeTo = _devFeeTo;
}
function transfer(address to, uint256 value) public virtual override returns (bool) {
_transfer(_msgSender(), to, value);
return true;
}
function transferFrom(address from, address to, uint256 value) public virtual override returns (bool) {
_spendAllowance(from, _msgSender(), value);
_transfer(from, to, value);
return true;
}
}
@openzeppelin/contracts/token/ERC20/ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @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}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* 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 ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _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(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
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}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` 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.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* 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 `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `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.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` 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.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed 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.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (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.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` 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.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @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.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
contracts/TaxRecipient.sol
pragma solidity >=0.8.0;
import "./interfaces/INXDProtocol.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./interfaces/IUniswapV2Router02.sol";
contract TaxRecipient {
error OnlyNXD();
IERC20 public immutable nxd;
address public immutable protocol;
IERC20 public dxn = IERC20(0x1B08d317963CC65932F3f79F00987B2E23df52Ab);
IUniswapV2Router02 public UNISWAP_V2_ROUTER = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
uint256 public nxdAddedToLp;
uint256 public dxnAddedToLp;
uint256 public dxnStaked;
constructor(address _protocol) {
nxd = IERC20(msg.sender);
protocol = _protocol;
}
/**
* @dev Handle tax from NXD protocol. Stakes 80% of received DXN and adds liquidity with the rest.
*/
function handleTax() external {
if (msg.sender != address(nxd)) {
revert OnlyNXD();
}
uint256 ourDXNBalance = dxn.balanceOf(address(this));
uint256 ratio = 750000000000000000; // Stake 1.5% of all our DXN balance (1.5*1e18 /2)
uint256 dxnToStake = (ourDXNBalance * ratio) / 1e18;
// Stake 8% of total tax after swap to DXN
dxn.approve(protocol, dxnToStake);
INXDProtocol(protocol).depositNoMint(dxnToStake);
dxnStaked += dxnToStake;
// Add liquidity with remaining NXD and DXN
ourDXNBalance = dxn.balanceOf(address(this));
uint256 ourNXDBalance = nxd.balanceOf(address(this));
// Approve tokens
dxn.approve(address(UNISWAP_V2_ROUTER), ourDXNBalance);
nxd.approve(address(UNISWAP_V2_ROUTER), ourNXDBalance);
// Add liquidity
(uint256 amountA, uint256 amountB,) = UNISWAP_V2_ROUTER.addLiquidity(
address(nxd), address(dxn), ourNXDBalance, ourDXNBalance, 0, 0, address(this), block.timestamp
);
nxdAddedToLp += amountA;
dxnAddedToLp += amountB;
}
}
contracts/interfaces/INXDProtocol.sol
pragma solidity ^0.8.13;
interface INXDProtocol {
function depositNoMint(uint256 _amount) external;
function collectFees() external;
function stakeOurDXN() external;
function totalDXNBurned() external view returns (uint256);
function pendingDXNToStake() external view returns (uint256);
function totalNXDBurned() external view returns (uint256);
function totalETHToStakingVault() external view returns (uint256);
function bridgeMint(address to, uint256 amount) external;
}
contracts/interfaces/IUniswapV2Pair.sol
pragma solidity >=0.5.0;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(
address owner,
address spender
) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(
address from,
address to,
uint value
) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(
address owner,
address spender,
uint value,
uint deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(
address indexed sender,
uint amount0,
uint amount1,
address indexed to
);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves()
external
view
returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(
uint amount0Out,
uint amount1Out,
address to,
bytes calldata data
) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
contracts/interfaces/IUniswapV2Router01.sol
pragma solidity >=0.6.2;
interface IUniswapV2Router01 {
function factory() external returns (address);
function WETH() external returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityETH(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountToken, uint256 amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityETHWithPermit(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountToken, uint256 amountETH);
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactETHForTokens(uint256 amountOutMin, address[] calldata path, address to, uint256 deadline)
external
payable
returns (uint256[] memory amounts);
function swapTokensForExactETH(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapETHForExactTokens(uint256 amountOut, address[] calldata path, address to, uint256 deadline)
external
payable
returns (uint256[] memory amounts);
function quote(uint256 amountA, uint256 reserveA, uint256 reserveB) external pure returns (uint256 amountB);
function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut)
external
pure
returns (uint256 amountOut);
function getAmountIn(uint256 amountOut, uint256 reserveIn, uint256 reserveOut)
external
pure
returns (uint256 amountIn);
function getAmountsOut(uint256 amountIn, address[] calldata path)
external
view
returns (uint256[] memory amounts);
function getAmountsIn(uint256 amountOut, address[] calldata path)
external
view
returns (uint256[] memory amounts);
}
contracts/interfaces/IUniswapV2Router02.sol
pragma solidity >=0.6.2;
import "./IUniswapV2Router01.sol";
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
contracts/interfaces/IV2Oracle.sol
pragma solidity ^0.8.13;
interface IV2Oracle {
function update() external;
// note this will always return 0 before update has been called successfully for the first time.
function consult(address token, uint256 amountIn) external view returns (uint256 amountOut);
function canUpdate() external view returns (bool);
}
contracts/interfaces/draft-IERC6093.sol
// SPDX-License-Identifier: MIT
// Vendored from OpenZeppelin Contracts v5.0.0 (interfaces/draft-IERC6093.sol)
// Original pragma was >=0.8.20; relaxed to >=0.8.4 for 0.8.13+ compatibility.
pragma solidity >=0.8.4;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
error ERC20InvalidSender(address sender);
error ERC20InvalidReceiver(address receiver);
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
error ERC20InvalidApprover(address approver);
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
*/
interface IERC721Errors {
error ERC721InvalidOwner(address owner);
error ERC721NonexistentToken(uint256 tokenId);
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
error ERC721InvalidSender(address sender);
error ERC721InvalidReceiver(address receiver);
error ERC721InsufficientApproval(address operator, uint256 tokenId);
error ERC721InvalidApprover(address approver);
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
*/
interface IERC1155Errors {
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 id);
error ERC1155InvalidSender(address sender);
error ERC1155InvalidReceiver(address receiver);
error ERC1155MissingApprovalForAll(address operator, address owner);
error ERC1155InvalidApprover(address approver);
error ERC1155InvalidOperator(address operator);
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "paris"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.