Contract Source Code:
File 1 of 1 : PaxGold
/**
*Submitted for verification at Etherscan.io on 2023-05-01
*/
/*
██████ ████ ██ ███ ██
██ ██ ██ ██ ████ ██
██ ███ ████████ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██
██████ ██ ██ ██ ██ ███
GOLD AI NETWORK TOKEN.
PAXOS Gold airdrops, Personalised trading bots, sustainable fair reward protocol, trading profits buy back and burn $GAIN.
...
https://www.gaingold.pro
http://t.me/GAIN_PAXG
https://twitter.com/GAIN_PAXG
https://gain.gitbook.io/gain-gold-ai-network/
https://medium.com/@gaingoldpro/introducing-golden-ai-network-gain-token-80de62d7bd88
*/
pragma solidity ^0.8.19;
// SPDX-License-Identifier: Unlicensed
interface IERC20 {
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 `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool);
/**
* @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);
}
library SafeMathInt {
int256 private constant MIN_INT256 = int256(1) << 255;
int256 private constant MAX_INT256 = ~(int256(1) << 255);
function mul(int256 a, int256 b) internal pure returns (int256) {
int256 c = a * b;
// Detect overflow when multiplying MIN_INT256 with -1
require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256));
require((b == 0) || (c / b == a));
return c;
}
function div(int256 a, int256 b) internal pure returns (int256) {
// Prevent overflow when dividing MIN_INT256 by -1
require(b != - 1 || a != MIN_INT256);
// Solidity already throws when dividing by 0.
return a / b;
}
function sub(int256 a, int256 b) internal pure returns (int256) {
int256 c = a - b;
require((b >= 0 && c <= a) || (b < 0 && c > a));
return c;
}
function add(int256 a, int256 b) internal pure returns (int256) {
int256 c = a + b;
require((b >= 0 && c >= a) || (b < 0 && c < a));
return c;
}
function abs(int256 a) internal pure returns (int256) {
require(a != MIN_INT256);
return a < 0 ? - a : a;
}
function toUint256Safe(int256 a) internal pure returns (uint256) {
require(a >= 0);
return uint256(a);
}
}
library SafeMathUint {
function toInt256Safe(uint256 a) internal pure returns (int256) {
int256 b = int256(a);
require(b >= 0);
return b;
}
}
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
abstract contract Context {
//function _msgSender() internal view virtual returns (address payable) {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this;
// silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly {codehash := extcodehash(account)}
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success,) = recipient.call{value : amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{value : weiValue}(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
/**
* @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.
*
* By default, the owner account will be the one that deploys the contract. 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.
*/
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IUniswapV2Router02 {
function swapExactTokensForETHSupportingFeeOnTransferTokens(
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 factory() external pure returns (address);
function WETH() external pure returns (address);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] memory path) external view returns (uint[] memory amounts);
}
contract PaxGold is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
event HolderBuySell(address holder, string actionType, uint256 ethAmount, uint256 ethBalance);
event SwapAndLiquifyEnabledUpdated(bool enabled);
event SwapAndLiquify(
uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiqudity
);
modifier lockTheSwap {
inSwapAndLiquify = true;
_;
inSwapAndLiquify = false;
}
IUniswapV2Router02 public uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
address public uniswapV2Pair = address(0);
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => bool) private botWallets;
mapping(address => bool) private _isExcludedFromFee;
mapping(address => bool) private _isExcludedFromRewards;
string private _name = "GOLD AI NETWORK TOKEN";
string private _symbol = "GAIN";
uint8 private _decimals = 9;
uint256 private _tTotal = 24_000 * 10 ** _decimals;
bool inSwapAndLiquify;
bool public swapAndLiquifyEnabled = true;
uint256 public ethPriceToSwap = .4 ether;
uint256 public highSellFeeSwapAmount = 3 ether;
uint256 public _maxWalletAmount = 480 * 10 ** _decimals;
address public goldTreasuryAddress = 0xd9C2DCaBb3F5900AF45fF0Aa8929002DE0f9126d;
address developmentAddress = 0x518ce0A930a46903578c3Ec2146094c773Bf61B7;
address public deadWallet = address(0xdead);
uint256 public gasForProcessing = 50000;
event ProcessedDividendTracker(uint256 iterations, uint256 claims, uint256 lastProcessedIndex, bool indexed automatic, uint256 gas, address indexed processor);
event SendDividends(uint256 EthAmount);
IterableMapping private holderBalanceMap = new IterableMapping();
struct Distribution {
uint256 goldTreasury;
uint256 development;
uint256 paxGoldDividend;
}
struct TaxFees {
uint256 buyFee;
uint256 sellFee;
uint256 highSellFee;
}
TaxFees public taxFees;
DividendTracker public dividendTracker;
Distribution public distribution = Distribution(50,50,0);
constructor () {
_balances[_msgSender()] = _tTotal;
_isExcludedFromFee[owner()] = true;
_isExcludedFromRewards[owner()] = true;
_isExcludedFromRewards[deadWallet] = true;
uniswapV2Pair = IUniswapV2Factory(uniswapV2Router.factory()).createPair(address(this), uniswapV2Router.WETH());
_isExcludedFromRewards[uniswapV2Pair] = true;
taxFees = TaxFees(30, 35, 35);
emit Transfer(address(0), _msgSender(), _tTotal);
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function totalSupply() public view override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
function ethHolderBalance(address account) public view returns (uint) {
return holderBalanceMap.get(account);
}
function setMaxWalletAmount(uint256 maxWalletAmount) external onlyOwner() {
_maxWalletAmount = maxWalletAmount * 10 ** 9;
}
function excludeIncludeFromFee(address[] calldata addresses, bool isExcludeFromFee) public onlyOwner {
addRemoveFee(addresses, isExcludeFromFee);
}
function excludeIncludeFromRewards(address[] calldata addresses, bool isExcluded) public onlyOwner {
addRemoveRewards(addresses, isExcluded);
}
function isExcludedFromRewards(address addr) public view returns (bool) {
return _isExcludedFromRewards[addr];
}
function addRemoveRewards(address[] calldata addresses, bool flag) private {
for (uint256 i = 0; i < addresses.length; i++) {
address addr = addresses[i];
_isExcludedFromRewards[addr] = flag;
}
}
function setEthPriceToSwap(uint256 ethPriceToSwap_) external onlyOwner {
ethPriceToSwap = ethPriceToSwap_;
}
function setHighSellFeeSwapAmount(uint256 ethAmount) external onlyOwner {
highSellFeeSwapAmount = ethAmount;
}
function addRemoveFee(address[] calldata addresses, bool flag) private {
for (uint256 i = 0; i < addresses.length; i++) {
address addr = addresses[i];
_isExcludedFromFee[addr] = flag;
}
}
function setTaxFees(uint256 buyFee, uint256 sellFee, uint256 highSellFee) external onlyOwner {
taxFees.buyFee = buyFee;
taxFees.sellFee = sellFee;
taxFees.highSellFee = highSellFee;
}
function isAddressBlocked(address addr) public view returns (bool) {
return botWallets[addr];
}
function blockAddresses(address[] memory addresses) external onlyOwner() {
blockUnblockAddress(addresses, true);
}
function unblockAddresses(address[] memory addresses) external onlyOwner() {
blockUnblockAddress(addresses, false);
}
function blockUnblockAddress(address[] memory addresses, bool doBlock) private {
for (uint256 i = 0; i < addresses.length; i++) {
address addr = addresses[i];
if (doBlock) {
botWallets[addr] = true;
} else {
delete botWallets[addr];
}
}
}
function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner {
swapAndLiquifyEnabled = _enabled;
emit SwapAndLiquifyEnabledUpdated(_enabled);
}
receive() external payable {}
function getTokenAmountByEthPrice() public view returns (uint256) {
address[] memory path = new address[](2);
path[0] = uniswapV2Router.WETH();
path[1] = address(this);
return uniswapV2Router.getAmountsOut(ethPriceToSwap, path)[1];
}
function isExcludedFromFee(address account) public view returns (bool) {
return _isExcludedFromFee[account];
}
function _approve(address owner, address spender, uint256 amount) private {
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);
}
function _transfer(address from, address to, uint256 amount) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
bool takeFees = !_isExcludedFromFee[from] && !_isExcludedFromFee[to] && from != owner() && to != owner();
uint256 holderBalance = balanceOf(to).add(amount);
uint256 taxAmount = 0;
//block the bots, but allow them to transfer to dead wallet if they are blocked
if (from != owner() && to != owner() && to != deadWallet && from != address(this) && to != address(this)) {
require(!botWallets[from] && !botWallets[to], "bots are not allowed to sell or transfer tokens");
if (from == uniswapV2Pair) {
require(holderBalance <= _maxWalletAmount, "Wallet cannot exceed max Wallet limit");
taxAmount = takeFees ? amount.mul(taxFees.buyFee).div(100) : 0;
uint ethBuy = getEthValueFromTokens(amount);
uint newBalance = holderBalanceMap.get(to).add(ethBuy);
holderBalanceMap.set(to, newBalance);
emit HolderBuySell(to, "BUY", ethBuy, newBalance);
}
if (from != uniswapV2Pair && to == uniswapV2Pair) {
taxAmount = takeFees ? amount.mul(taxFees.sellFee).div(100) : 0;
uint ethSell = getEthValueFromTokens(amount);
if(taxAmount > 0 && ethSell > highSellFeeSwapAmount) {
taxAmount = taxFees.highSellFee;
}
int val = int(holderBalanceMap.get(from)) - int(ethSell);
uint256 newBalance = val <= 0 ? 0 : uint256(val);
holderBalanceMap.set(from, newBalance);
emit HolderBuySell(from, "SELL", ethSell, newBalance);
swapTokens();
}
if (from != uniswapV2Pair && to != uniswapV2Pair) {
require(holderBalance <= _maxWalletAmount, "Wallet cannot exceed max Wallet limit");
}
try dividendTracker.setTokenBalance(from) {} catch{}
try dividendTracker.setTokenBalance(to) {} catch{}
try dividendTracker.process(gasForProcessing) returns (uint256 iterations, uint256 claims, uint256 lastProcessedIndex) {
emit ProcessedDividendTracker(iterations, claims, lastProcessedIndex, true, gasForProcessing, tx.origin);
}catch {}
}
uint256 transferAmount = amount.sub(taxAmount);
_balances[from] = _balances[from].sub(amount);
_balances[to] = _balances[to].add(transferAmount);
_balances[address(this)] = _balances[address(this)].add(taxAmount);
emit Transfer(from, to, amount);
}
function airDrops(address[] calldata holders, uint256[] calldata amounts) external onlyOwner {
require(holders.length == amounts.length, "Holders and amounts must be the same count");
address from = _msgSender();
for(uint256 i=0; i < holders.length; i++) {
address to = holders[i];
uint256 amount = amounts[i];
_balances[from] = _balances[from].sub(amount);
_balances[to] = _balances[to].add(amount);
emit Transfer(from, to, amount);
}
}
function swapTokens() private {
uint256 contractTokenBalance = balanceOf(address(this));
if (contractTokenBalance > 0) {
uint256 tokenAmount = getTokenAmountByEthPrice();
if (contractTokenBalance >= tokenAmount && !inSwapAndLiquify && swapAndLiquifyEnabled) {
//send eth to wallets investment and dev
swapTokensForEth(tokenAmount);
distributeShares();
}
}
}
function getEthValueFromTokens(uint tokenAmount) public view returns (uint) {
address[] memory path = new address[](2);
path[0] = uniswapV2Router.WETH();
path[1] = address(this);
return uniswapV2Router.getAmountsIn(tokenAmount, path)[0];
}
function updateGasForProcessing(uint256 newValue) public onlyOwner {
require(newValue != gasForProcessing, "Cannot update gasForProcessing to same value");
gasForProcessing = newValue;
}
function distributeShares() private lockTheSwap {
uint256 ethBalance = address(this).balance;
uint256 goldTreasury = ethBalance.mul(distribution.goldTreasury).div(100);
uint256 development = ethBalance.mul(distribution.development).div(100);
uint256 paxGoldDividend = ethBalance.mul(distribution.paxGoldDividend).div(100);
payable(goldTreasuryAddress).transfer(goldTreasury);
payable(developmentAddress).transfer(development);
sendEthDividends(paxGoldDividend);
}
function manualSwap() external {
uint256 contractTokenBalance = balanceOf(address(this));
if (contractTokenBalance > 0) {
if (!inSwapAndLiquify) {
swapTokensForEth(contractTokenBalance);
distributeShares();
}
}
}
function setDistribution(uint256 goldTreasury, uint256 development, uint256 paxGoldDividend) external onlyOwner {
distribution.goldTreasury = goldTreasury;
distribution.development = development;
distribution.paxGoldDividend = paxGoldDividend;
}
function setDividendTracker(address dividendContractAddress) external onlyOwner {
dividendTracker = DividendTracker(payable(dividendContractAddress));
}
function sendEthDividends(uint256 dividends) private {
(bool success,) = address(dividendTracker).call{value : dividends}("");
if (success) {
emit SendDividends(dividends);
}
}
function removeEthFromContract() external onlyOwner {
uint256 ethBalance = address(this).balance;
payable(owner()).transfer(ethBalance);
}
function swapTokensForEth(uint256 tokenAmount) private {
// generate the uniswap pair path of token -> weth
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
// make the swap
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
}
contract IterableMapping {
// Iterable mapping from address to uint;
struct Map {
address[] keys;
mapping(address => uint) values;
mapping(address => uint) indexOf;
mapping(address => bool) inserted;
}
Map private map;
function get(address key) public view returns (uint) {
return map.values[key];
}
function keyExists(address key) public view returns (bool) {
return (getIndexOfKey(key) != - 1);
}
function getIndexOfKey(address key) public view returns (int) {
if (!map.inserted[key]) {
return - 1;
}
return int(map.indexOf[key]);
}
function getKeyAtIndex(uint index) public view returns (address) {
return map.keys[index];
}
function size() public view returns (uint) {
return map.keys.length;
}
function set(address key, uint val) public {
if (map.inserted[key]) {
map.values[key] = val;
} else {
map.inserted[key] = true;
map.values[key] = val;
map.indexOf[key] = map.keys.length;
map.keys.push(key);
}
}
function remove(address key) public {
if (!map.inserted[key]) {
return;
}
delete map.inserted[key];
delete map.values[key];
uint index = map.indexOf[key];
uint lastIndex = map.keys.length - 1;
address lastKey = map.keys[lastIndex];
map.indexOf[lastKey] = index;
delete map.indexOf[key];
map.keys[index] = lastKey;
map.keys.pop();
}
}
contract DividendTracker is IERC20, Context, Ownable {
using SafeMath for uint256;
using SafeMathUint for uint256;
using SafeMathInt for int256;
uint256 constant internal magnitude = 2 ** 128;
uint256 internal magnifiedDividendPerShare;
mapping(address => int256) internal magnifiedDividendCorrections;
mapping(address => uint256) internal withdrawnDividends;
mapping(address => uint256) internal claimedDividends;
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name = "PaxGold TRACKER";
string private _symbol = "PaxGoldT";
uint8 private _decimals = 9;
uint256 public totalDividendsDistributed;
IterableMapping private tokenHoldersMap = new IterableMapping();
PaxGold private paxGold;
event updateBalance(address addr, uint256 amount);
event DividendsDistributed(address indexed from, uint256 weiAmount);
event DividendWithdrawn(address indexed to, uint256 weiAmount);
uint256 public lastProcessedIndex;
mapping(address => uint256) public lastClaimTimes;
uint256 public claimWait = 3600;
event ExcludeFromDividends(address indexed account);
event ClaimWaitUpdated(uint256 indexed newValue, uint256 indexed oldValue);
event Claim(address indexed account, uint256 amount, bool indexed automatic);
IUniswapV2Router02 uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
IERC20 public paxGoldToken = IERC20(0x45804880De22913dAFE09f4980848ECE6EcbAf78); //PaxGold
struct GoldDividendTiers {
uint pureGold;
uint twentytwoKarat;
uint twentyKarat;
uint eighteenKarat;
uint fourteenKarat;
uint twelveKarat;
uint tenKarat;
}
GoldDividendTiers public goldDividendTiers;
constructor() {
goldDividendTiers = GoldDividendTiers(
8 ether,
4 ether,
2 ether,
1 ether,
.5 ether,
.25 ether,
.1 ether);
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
function getGoldTier(uint256 amount) public view returns (uint, string memory) {
uint tierLevel = 0;
string memory tier = "Not Eligible";
if(amount >= goldDividendTiers.tenKarat) {
tierLevel = .1 ether;
tier = "10 Karat";
}
if(amount >= goldDividendTiers.twelveKarat) {
tierLevel = .25 ether;
tier = "12 Karat";
}
if(amount >= goldDividendTiers.fourteenKarat) {
tierLevel = .5 ether;
tier = "14 Karat";
}
if(amount >= goldDividendTiers.eighteenKarat) {
tierLevel = 1 ether;
tier = "18 Karat";
}
if(amount >= goldDividendTiers.twentyKarat) {
tierLevel = 2 ether;
tier = "20 Karat";
}
if(amount >= goldDividendTiers.twentytwoKarat) {
tierLevel = 4 ether;
tier = "22 Karat";
}
if(amount >= goldDividendTiers.pureGold) {
tierLevel = 8 ether;
tier = "Pure Gold";
}
return (tierLevel, tier);
}
function transfer(address, uint256) public pure returns (bool) {
require(false, "No transfers allowed in dividend tracker");
return true;
}
function transferFrom(address, address, uint256) public pure override returns (bool) {
require(false, "No transfers allowed in dividend tracker");
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
function _approve(address owner, address spender, uint256 amount) private {
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);
}
function setTokenBalance(address account) public {
uint256 balance = paxGold.ethHolderBalance(account);
if (!paxGold.isExcludedFromRewards(account)) {
(uint tierLevel,) = getGoldTier(balance);
if (tierLevel > 0) {
_setBalance(account, tierLevel);
tokenHoldersMap.set(account, tierLevel);
}
else {
_setBalance(account, 0);
tokenHoldersMap.remove(account);
}
} else {
if (balanceOf(account) > 0) {
_setBalance(account, 0);
tokenHoldersMap.remove(account);
}
}
processAccount(payable(account), true);
}
function updateTokenBalances(address[] memory accounts) external {
uint256 index = 0;
while (index < accounts.length) {
setTokenBalance(accounts[index]);
index += 1;
}
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
magnifiedDividendCorrections[account] = magnifiedDividendCorrections[account]
.sub((magnifiedDividendPerShare.mul(amount)).toInt256Safe());
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
magnifiedDividendCorrections[account] = magnifiedDividendCorrections[account]
.add((magnifiedDividendPerShare.mul(amount)).toInt256Safe());
}
receive() external payable {
distributeDividends();
}
function setERC20Contract(address contractAddr) external onlyOwner {
paxGold = PaxGold(payable(contractAddr));
}
function excludeFromDividends(address account) external onlyOwner {
_setBalance(account, 0);
tokenHoldersMap.remove(account);
emit ExcludeFromDividends(account);
}
function distributeDividends() public payable {
require(totalSupply() > 0);
uint256 initialBalance = paxGoldToken.balanceOf(address(this));
swapEthForPaxGold(msg.value);
uint256 newBalance = paxGoldToken.balanceOf(address(this)).sub(initialBalance);
if (newBalance > 0) {
magnifiedDividendPerShare = magnifiedDividendPerShare.add(
(newBalance).mul(magnitude) / totalSupply()
);
emit DividendsDistributed(msg.sender, newBalance);
totalDividendsDistributed = totalDividendsDistributed.add(newBalance);
}
}
function swapEthForPaxGold(uint256 ethAmount) public {
// generate the uniswap pair path of weth -> eth
address[] memory path = new address[](2);
path[0] = uniswapV2Router.WETH();
path[1] = address(paxGoldToken);
// make the swap
uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value : ethAmount}(
0, // accept any amount of Ethereum
path,
address(this),
block.timestamp
);
}
function withdrawDividend() public virtual {
_withdrawDividendOfUser(payable(msg.sender));
}
function _withdrawDividendOfUser(address payable user) internal returns (uint256) {
uint256 _withdrawableDividend = withdrawableDividendOf(user);
if (_withdrawableDividend > 0) {
withdrawnDividends[user] = withdrawnDividends[user].add(_withdrawableDividend);
emit DividendWithdrawn(user, _withdrawableDividend);
paxGoldToken.transfer(user, _withdrawableDividend);
return _withdrawableDividend;
}
return 0;
}
function dividendOf(address _owner) public view returns (uint256) {
return withdrawableDividendOf(_owner);
}
function withdrawableDividendOf(address _owner) public view returns (uint256) {
return accumulativeDividendOf(_owner).sub(withdrawnDividends[_owner]);
}
function withdrawnDividendOf(address _owner) public view returns (uint256) {
return withdrawnDividends[_owner];
}
function accumulativeDividendOf(address _owner) public view returns (uint256) {
return magnifiedDividendPerShare.mul(balanceOf(_owner)).toInt256Safe()
.add(magnifiedDividendCorrections[_owner]).toUint256Safe() / magnitude;
}
function updateClaimWait(uint256 newClaimWait) external onlyOwner {
require(newClaimWait >= 3600 && newClaimWait <= 86400, "ClaimWait must be updated to between 1 and 24 hours");
require(newClaimWait != claimWait, "Cannot update claimWait to same value");
emit ClaimWaitUpdated(newClaimWait, claimWait);
claimWait = newClaimWait;
}
function getLastProcessedIndex() external view returns (uint256) {
return lastProcessedIndex;
}
function getNumberOfTokenHolders() external view returns (uint256) {
return tokenHoldersMap.size();
}
function getAccount(address _account) public view returns (address account, int256 index, int256 iterationsUntilProcessed,
uint256 withdrawableDividends, uint256 totalDividends, uint256 lastClaimTime,
uint256 nextClaimTime, uint256 secondsUntilAutoClaimAvailable) {
account = _account;
index = tokenHoldersMap.getIndexOfKey(account);
iterationsUntilProcessed = - 1;
if (index >= 0) {
if (uint256(index) > lastProcessedIndex) {
iterationsUntilProcessed = index.sub(int256(lastProcessedIndex));
}
else {
uint256 processesUntilEndOfArray = tokenHoldersMap.size() > lastProcessedIndex ?
tokenHoldersMap.size().sub(lastProcessedIndex) : 0;
iterationsUntilProcessed = index.add(int256(processesUntilEndOfArray));
}
}
withdrawableDividends = withdrawableDividendOf(account);
totalDividends = accumulativeDividendOf(account);
lastClaimTime = lastClaimTimes[account];
nextClaimTime = lastClaimTime > 0 ? lastClaimTime.add(claimWait) : 0;
secondsUntilAutoClaimAvailable = nextClaimTime > block.timestamp ? nextClaimTime.sub(block.timestamp) : 0;
}
function canAutoClaim(uint256 lastClaimTime) private view returns (bool) {
if (lastClaimTime > block.timestamp) {
return false;
}
return block.timestamp.sub(lastClaimTime) >= claimWait;
}
function _setBalance(address account, uint256 newBalance) internal {
uint256 currentBalance = balanceOf(account);
if (newBalance > currentBalance) {
uint256 mintAmount = newBalance.sub(currentBalance);
_mint(account, mintAmount);
} else if (newBalance < currentBalance) {
uint256 burnAmount = currentBalance.sub(newBalance);
_burn(account, burnAmount);
}
}
function process(uint256 gas) public returns (uint256, uint256, uint256) {
uint256 numberOfTokenHolders = tokenHoldersMap.size();
if (numberOfTokenHolders == 0) {
return (0, 0, lastProcessedIndex);
}
uint256 _lastProcessedIndex = lastProcessedIndex;
uint256 gasUsed = 0;
uint256 gasLeft = gasleft();
uint256 iterations = 0;
uint256 claims = 0;
while (gasUsed < gas && iterations < numberOfTokenHolders) {
_lastProcessedIndex++;
if (_lastProcessedIndex >= tokenHoldersMap.size()) {
_lastProcessedIndex = 0;
}
address account = tokenHoldersMap.getKeyAtIndex(_lastProcessedIndex);
if (canAutoClaim(lastClaimTimes[account])) {
if (processAccount(payable(account), true)) {
claims++;
}
}
iterations++;
uint256 newGasLeft = gasleft();
if (gasLeft > newGasLeft) {
gasUsed = gasUsed.add(gasLeft.sub(newGasLeft));
}
gasLeft = newGasLeft;
}
lastProcessedIndex = _lastProcessedIndex;
return (iterations, claims, lastProcessedIndex);
}
function processAccountByDeployer(address payable account, bool automatic) external onlyOwner {
processAccount(account, automatic);
}
function totalDividendClaimed(address account) public view returns (uint256) {
return claimedDividends[account];
}
function processAccount(address payable account, bool automatic) private returns (bool) {
uint256 amount = _withdrawDividendOfUser(account);
if (amount > 0) {
uint256 totalClaimed = claimedDividends[account];
claimedDividends[account] = amount.add(totalClaimed);
lastClaimTimes[account] = block.timestamp;
emit Claim(account, amount, automatic);
return true;
}
return false;
}
//This should never be used, but available in case of unforseen issues
function sendEthBack() external onlyOwner {
uint256 ethBalance = address(this).balance;
payable(owner()).transfer(ethBalance);
}
//This should never be used, but available in case of unforseen issues
function sendPaxGoldBack() external onlyOwner {
uint256 paxGoldBalance = paxGoldToken.balanceOf(address(this));
paxGoldToken.transfer(owner(), paxGoldBalance);
}
}