Description:
Decentralized Finance (DeFi) protocol contract providing Swap, Factory functionality.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"@openzeppelin/contracts/utils/ReentrancyGuard.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
"
},
"contracts/XpadToken.sol": {
"content": "// SPDX-License-Identifier: MIT
/*
Powered by XPAD
---------------------
XPAD: The decentralized launchpad with lottery + low fees
Create your own token today at
https://xpad.fun
Join us on telegram: https://t.me/Xerc20
Join us on X: http://x.com/XERS_official
*/
pragma solidity ^0.8.28;
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
interface IWETH {
function deposit() external payable;
function withdraw(uint256) external;
function approve(address spender, uint256 amount) external returns (bool);
function transfer(address to, uint256 value) external returns (bool);
function balanceOf(address owner) external view returns (uint256);
}
interface IUniswapV2Router {
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function getAmountsOut(
uint amountIn,
address[] calldata path
) external view returns (uint[] memory amounts);
function WETH() external pure returns (address);
function factory() external view returns (address);
}
interface IUniswapV2Factory {
function getPair(
address tokenA,
address tokenB
) external view returns (address pair);
function createPair(
address tokenA,
address tokenB
) external returns (address pair);
}
contract XpadToken is ReentrancyGuard {
string public name;
string public symbol;
uint8 public decimals;
address public factory;
address payable public creator;
address payable public treasury;
address payable public uniswapMarketingWallet;
address payable public uniswapDevelopmentWallet;
IUniswapV2Router public uniswapRouter;
address public uniswapPair;
bool public isBondingCurve;
bool public initialized;
uint256 public maxSupply;
uint256 public taxFeeToTreasury;
uint256 public uniswapMarketingTaxFee;
uint256 public uniswapDevelopmentTaxFee;
uint256 public uniswapCreatorTaxFee;
uint256 public totalSupply;
uint256 public pendingSwapAmount;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
mapping(address => bool) public isFeeWhitelisted;
mapping(address => uint256) public failedPayments;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
event FactoryRenounced();
event UniswapPairCreated(address pair);
event FallbackToWETH(address indexed to, uint256 amount);
event PaymentFailed(address indexed to, uint256 amount);
modifier onlyFactory() {
require(msg.sender == factory, "Only factory can call");
_;
}
function initialize(
string memory _name,
string memory _symbol,
address _creator,
address _uniswapMarketingWallet,
address _uniswapDevelopmentWallet,
address _treasury,
uint256 _uniswapMarketingTaxFee,
uint256 _uniswapDevelopmentTaxFee,
uint256 _uniswapCreatorTaxFee,
uint256 _feeTreasury,
uint256 _maxSupply,
address _uniswapRouter
) external {
require(!initialized, "Already initialized");
// Input validation
require(_creator != address(0), "Creator cannot be zero address");
require(_treasury != address(0), "Treasury cannot be zero address");
require(_uniswapRouter != address(0), "Router cannot be zero address");
name = _name;
symbol = _symbol;
creator = payable(_creator);
factory = msg.sender;
treasury = payable(_treasury);
uniswapMarketingWallet = payable(_uniswapMarketingWallet);
uniswapDevelopmentWallet = payable(_uniswapDevelopmentWallet);
uniswapMarketingTaxFee = _uniswapMarketingTaxFee;
uniswapDevelopmentTaxFee = _uniswapDevelopmentTaxFee;
uniswapCreatorTaxFee = _uniswapCreatorTaxFee;
taxFeeToTreasury = _feeTreasury;
maxSupply = _maxSupply;
uniswapRouter = IUniswapV2Router(_uniswapRouter);
isFeeWhitelisted[msg.sender] = true;
isFeeWhitelisted[address(this)] = true;
pendingSwapAmount = 0;
decimals = 18;
isBondingCurve = true;
initialized = true;
// Ensure Uniswap pair exists
address weth = uniswapRouter.WETH();
address pair = IUniswapV2Factory(uniswapRouter.factory()).getPair(
address(this),
weth
);
require(pair == address(0), "Pair already exists");
pair = IUniswapV2Factory(uniswapRouter.factory()).createPair(
address(this),
weth
);
require(pair != address(0), "Pair creation failed");
uniswapPair = pair;
emit UniswapPairCreated(pair);
}
/**
* @notice Adds or removes an address from the fee whitelist.
*/
function feeWL(address _address, bool _status) external onlyFactory {
isFeeWhitelisted[_address] = _status;
}
function setIsBondingCurve(bool _isBondingCurve) external onlyFactory {
isBondingCurve = _isBondingCurve;
}
function _mint(address to, uint256 amount) internal {
require(to != address(0), "Mint to zero address");
balanceOf[to] += amount;
totalSupply += amount;
emit Transfer(address(0), to, amount);
}
function mintFromFactory(address to, uint256 amount) external onlyFactory {
require(totalSupply + amount <= maxSupply, "Cap exceeded");
_mint(to, amount);
}
function approve(address spender, uint256 amount) external returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
function _approve(address owner, address spender, uint256 amount) internal {
allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function renounceFactory() external onlyFactory {
factory = address(0);
emit FactoryRenounced();
}
function increaseAllowance(
address spender,
uint256 addedValue
) external returns (bool) {
allowance[msg.sender][spender] += addedValue;
emit Approval(msg.sender, spender, allowance[msg.sender][spender]);
return true;
}
function decreaseAllowance(
address spender,
uint256 subtractedValue
) external returns (bool) {
uint256 current = allowance[msg.sender][spender];
require(current >= subtractedValue, "Decreased below zero");
allowance[msg.sender][spender] = current - subtractedValue;
emit Approval(msg.sender, spender, allowance[msg.sender][spender]);
return true;
}
function transfer(address to, uint256 amount) external returns (bool) {
require(balanceOf[msg.sender] >= amount, "Insufficient balance");
require(to != address(0), "Transfer to zero address");
// block transfers to uniswap pair until migration
if (isBondingCurve && to == uniswapPair) {
revert("Trading not enabled yet");
}
uint256 feeTreasury = 0;
uint256 feeMarketing = 0;
uint256 feeDevelopment = 0;
uint256 feeCreator = 0;
// Detect if this is a DEX swap
bool isBuy = msg.sender == uniswapPair;
bool isSell = to == uniswapPair;
if (
!isBondingCurve &&
!isFeeWhitelisted[msg.sender] &&
!isFeeWhitelisted[to] &&
(isBuy || isSell)
) {
feeTreasury = (amount * taxFeeToTreasury) / 10000;
feeMarketing = (amount * uniswapMarketingTaxFee) / 10000;
feeDevelopment = (amount * uniswapDevelopmentTaxFee) / 10000;
feeCreator = (amount * uniswapCreatorTaxFee) / 10000;
}
uint256 totalFee = feeTreasury +
feeMarketing +
feeDevelopment +
feeCreator;
require(totalFee <= amount / 4, "Fee calculation error");
uint256 amountAfterFee = amount - totalFee;
balanceOf[msg.sender] -= amount;
// Swap fees to ETH immediately
if (totalFee > 0) {
// Accumulate fees in contract
balanceOf[address(this)] += totalFee;
emit Transfer(msg.sender, address(this), totalFee);
pendingSwapAmount += totalFee; // ? ACCUMULATE instead of swapping
if (isSell && pendingSwapAmount > 0) {
swapAndSendToFee(pendingSwapAmount);
}
}
// Transfer net amount
balanceOf[to] += amountAfterFee;
emit Transfer(msg.sender, to, amountAfterFee);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool) {
require(
allowance[from][msg.sender] >= amount,
"Insufficient allowance"
);
require(balanceOf[from] >= amount, "Insufficient balance");
require(to != address(0), "Transfer to zero address");
// block transfers to uniswap pair until migration
if (isBondingCurve && to == uniswapPair) {
revert("Trading not enabled yet");
}
allowance[from][msg.sender] -= amount;
balanceOf[from] -= amount;
uint256 feeTreasury = 0;
uint256 feeMarketing = 0;
uint256 feeDevelopment = 0;
uint256 feeCreator = 0;
// Detect if this is a DEX swap
bool isBuy = from == uniswapPair;
bool isSell = to == uniswapPair;
if (
!isBondingCurve &&
!isFeeWhitelisted[from] &&
!isFeeWhitelisted[to] &&
(isBuy || isSell)
) {
require(amount > 0, "Amount must be positive");
feeTreasury = (amount * taxFeeToTreasury) / 10000;
feeMarketing = (amount * uniswapMarketingTaxFee) / 10000;
feeDevelopment = (amount * uniswapDevelopmentTaxFee) / 10000;
feeCreator = (amount * uniswapCreatorTaxFee) / 10000;
}
uint256 totalFee = feeTreasury +
feeMarketing +
feeDevelopment +
feeCreator;
require(totalFee <= amount / 4, "Fee calculation error");
uint256 amountAfterFee = amount - totalFee;
// Swap fees to ETH immediately
if (totalFee > 0) {
// Accumulate fees in contract
balanceOf[address(this)] += totalFee;
emit Transfer(from, address(this), totalFee);
pendingSwapAmount += totalFee;
// Only swap if enough tokens accumulated
if (isSell && pendingSwapAmount > 0) {
swapAndSendToFee(pendingSwapAmount);
}
}
// Transfer net amount
balanceOf[to] += amountAfterFee;
emit Transfer(from, to, amountAfterFee);
return true;
}
function swapAndSendToFee(uint256 tokenAmount) internal nonReentrant {
uint256 initialBalance = address(this).balance;
_swapFeeTokensToETH(tokenAmount);
uint256 newBalance = address(this).balance - initialBalance;
uint256 totalFeePerc = taxFeeToTreasury +
uniswapMarketingTaxFee +
uniswapDevelopmentTaxFee +
uniswapCreatorTaxFee;
if (newBalance > 0 && totalFeePerc > 0) {
if (taxFeeToTreasury > 0)
_safeSend(
treasury,
(newBalance * taxFeeToTreasury) /
totalFeePerc +
failedPayments[treasury]
);
if (uniswapMarketingTaxFee > 0)
_safeSend(
uniswapMarketingWallet,
(newBalance * uniswapMarketingTaxFee) /
totalFeePerc +
failedPayments[uniswapMarketingWallet]
);
if (uniswapDevelopmentTaxFee > 0)
_safeSend(
uniswapDevelopmentWallet,
(newBalance * uniswapDevelopmentTaxFee) /
totalFeePerc +
failedPayments[uniswapDevelopmentWallet]
);
if (uniswapCreatorTaxFee > 0)
_safeSend(
creator,
(newBalance * uniswapCreatorTaxFee) /
totalFeePerc +
failedPayments[creator]
);
}
}
function _safeSend(address payable to, uint256 amount) private {
(bool success, ) = to.call{value: amount, gas: 10000}("");
if (!success) {
IWETH weth = IWETH(uniswapRouter.WETH());
try weth.deposit{value: amount}() {
bool wethSuccess = weth.transfer(to, amount);
require(wethSuccess, "WETH transfer failed");
// Emit event to notify recipient they received WETH instead of ETH
emit FallbackToWETH(to, amount);
} catch {
// As last resort, store failed payment for manual withdrawal
failedPayments[to] += amount;
emit PaymentFailed(to, amount);
}
}
}
function _swapFeeTokensToETH(uint256 tokenAmount) private {
require(balanceOf[address(this)] >= tokenAmount, "Not enough tokens");
_approve(address(this), address(uniswapRouter), tokenAmount);
uint256 minEthOut = (getExpectedEthOutput(tokenAmount) * 95) / 100;
require(minEthOut >= 0, "Min ETH output is zero");
pendingSwapAmount = 0;
address[] memory path = new address[](2);
path[0] = address(this); // Token address
path[1] = uniswapRouter.WETH(); // WETH address
try
uniswapRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp + 300
)
{
pendingSwapAmount = 0;
} catch {
pendingSwapAmount = tokenAmount;
}
}
function getExpectedEthOutput(
uint256 tokenAmount
) public view returns (uint256) {
address[] memory path = new address[](2);
path[0] = address(this); // your token
path[1] = uniswapRouter.WETH();
uint[] memory amounts = uniswapRouter.getAmountsOut(tokenAmount, path);
return amounts[1]; // expected ETH output
}
receive() external payable {}
}
"
}
},
"settings": {
"viaIR": true,
"metadata": {
"bytecodeHash": "none",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}
}}
Submitted on: 2025-10-06 12:27:21
Comments
Log in to comment.
No comments yet.