// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)pragmasolidity ^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.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (address) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytescalldata) {
returnmsg.data;
}
}
Contract Source Code
File 2 of 7: IERC20.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)pragmasolidity ^0.8.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (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.
*/functiontransfer(address to, uint256 amount) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets `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.
*/functionapprove(address spender, uint256 amount) externalreturns (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.
*/functiontransferFrom(addressfrom, address to, uint256 amount) externalreturns (bool);
}
// SPDX-License-Identifier: UNLICENSEDpragmasolidity 0.8.18;librarySafeMath{
functionadd(uint256 a, uint256 b) internalpurereturns (uint256) {
return a + b;
}
functionsub(uint256 a, uint256 b) internalpurereturns (uint256) {
return a - b;
}
functionmul(uint256 a, uint256 b) internalpurereturns (uint256) {
return a * b;
}
functiondiv(uint256 a, uint256 b) internalpurereturns (uint256) {
return a / b;
}
functionmod(uint256 a, uint256 b) internalpurereturns (uint256) {
return a % b;
}
functiontryAdd(uint256 a,
uint256 b
) internalpurereturns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
functiontrySub(uint256 a,
uint256 b
) internalpurereturns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
functiontryMul(uint256 a,
uint256 b
) internalpurereturns (bool, uint256) {
unchecked {
if (a ==0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
functiontryDiv(uint256 a,
uint256 b
) internalpurereturns (bool, uint256) {
unchecked {
if (b ==0) return (false, 0);
return (true, a / b);
}
}
functiontryMod(uint256 a,
uint256 b
) internalpurereturns (bool, uint256) {
unchecked {
if (b ==0) return (false, 0);
return (true, a % b);
}
}
functionsub(uint256 a,
uint256 b,
stringmemory errorMessage
) internalpurereturns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
functiondiv(uint256 a,
uint256 b,
stringmemory errorMessage
) internalpurereturns (uint256) {
unchecked {
require(b >0, errorMessage);
return a / b;
}
}
functionmod(uint256 a,
uint256 b,
stringmemory errorMessage
) internalpurereturns (uint256) {
unchecked {
require(b >0, errorMessage);
return a % b;
}
}
}
import"@openzeppelin/contracts/token/ERC20/IERC20.sol";
import"@openzeppelin/contracts/access/Ownable.sol";
import"@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
import"@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
contractOSMOisIERC20, Ownable{
usingSafeMathforuint256;
IUniswapV2Router02 router;
stringprivateconstant _name ="Osmo Bot";
stringprivateconstant _symbol ="OSMO";
mapping(address=>uint256) _balances;
mapping(address=>mapping(address=>uint256)) private _allowances;
mapping(address=>bool) public isFeeExempt;
uint8privateconstant _decimals =18;
uint256private _totalSupply =1_000_000* (10** _decimals);
uint256private init =0;
uint256private startEnd =15;
uint256private buyFee =300;
uint256private sellFee =300;
uint256private startFee =3000;
uint256private transferFee =0;
uint256private denominator =10000;
uint256public swapTimes =0;
uint256private swapCounter =10;
uint256private swapThreshold = (_totalSupply *100) /100000;
uint256private _minTokenAmount = (_totalSupply *1) /100000;
boolprivate tradingOpen =false;
boolprivate swapEnabled =true;
boolprivate swapping;
addresspublic pair;
addressinternalconstant DEAD =0x000000000000000000000000000000000000dEaD;
addresspublic marketing_receiver;
modifierlockTheSwap() {
swapping =true;
_;
swapping =false;
}
constructor() Ownable() {
router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
pair = IUniswapV2Factory(router.factory()).createPair(
address(this),
router.WETH()
);
marketing_receiver =msg.sender;
isFeeExempt[address(this)] =true;
isFeeExempt[marketing_receiver] =true;
isFeeExempt[msg.sender] =true;
_balances[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}
receive() externalpayable{}
functionname() publicpurereturns (stringmemory) {
return _name;
}
functionsymbol() publicpurereturns (stringmemory) {
return _symbol;
}
functiondecimals() publicpurereturns (uint8) {
return _decimals;
}
functiontotalSupply() publicviewoverridereturns (uint256) {
return _totalSupply;
}
functionbalanceOf(address account) publicviewoverridereturns (uint256) {
return _balances[account];
}
functiontransfer(address recipient,
uint256 amount
) publicoverridereturns (bool) {
_transfer(msg.sender, recipient, amount);
returntrue;
}
functionallowance(address owner,
address spender
) publicviewoverridereturns (uint256) {
return _allowances[owner][spender];
}
functionisContract(address addr) internalviewreturns (bool) {
uint size;
assembly {
size :=extcodesize(addr)
}
return size >0;
}
functionsetisExempt(address _address, bool _enabled) externalonlyOwner{
isFeeExempt[_address] = _enabled;
}
functionapprove(address spender,
uint256 amount
) publicoverridereturns (bool) {
_approve(msg.sender, spender, amount);
returntrue;
}
functionpreTxCheck(address sender,
address recipient,
uint256 amount
) internalview{
require(sender !=address(0), "ERC20: transfer from the zero address");
require(recipient !=address(0), "ERC20: transfer to the zero address");
require(
amount >uint256(0),
"Transfer amount must be greater than zero"
);
require(
amount <= balanceOf(sender),
"You are trying to transfer more than your balance"
);
}
function_transfer(address sender,
address recipient,
uint256 amount
) private{
preTxCheck(sender, recipient, amount);
checkTradingAllowed(sender, recipient);
swapbackCounters(sender, recipient);
swapBack(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount);
uint256 amountReceived = shouldTakeFee(sender, recipient)
? takeFee(sender, recipient, amount)
: amount;
_balances[recipient] = _balances[recipient].add(amountReceived);
emit Transfer(sender, recipient, amountReceived);
}
functionsetStructure(uint256 _buy,
uint256 _sell,
uint256 _trans
) externalonlyOwner{
buyFee = _buy;
sellFee = _sell;
transferFee = _trans;
require(
buyFee <= denominator.div(5) &&
sellFee <= denominator.div(8) &&
transferFee <= denominator.div(8),
"buyFee and sellFee cannot be more than 20%"
);
}
functionswapbackCounters(address sender, address recipient) internal{
if (recipient == pair &&!isFeeExempt[sender]) {
swapTimes +=uint256(1);
}
}
functionswapTokensForETH(uint256 tokenAmount) privatelockTheSwap{
address[] memory path =newaddress[](2);
path[0] =address(this);
path[1] = router.WETH();
_approve(address(this), address(router), tokenAmount);
router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
marketing_receiver,
block.timestamp
);
}
functionmax(uint256 a, uint256 b) internalpurereturns (uint256) {
return a > b ? a : b;
}
functionmin(uint256 a, uint256 b) internalpurereturns (uint256) {
return a < b ? a : b;
}
functionshouldSwapBack(address sender,
address recipient,
uint256 amount
) internalviewreturns (bool) {
bool aboveMin = amount >= _minTokenAmount;
bool aboveThreshold = balanceOf(address(this)) >= swapThreshold;
return!swapping &&
swapEnabled &&
aboveMin &&!isFeeExempt[sender] &&
recipient == pair &&
swapTimes >=uint256(swapCounter) &&
aboveThreshold;
}
functionswapBack(address sender,
address recipient,
uint256 amount
) internal{
if (shouldSwapBack(sender, recipient, amount)) {
uint256 bal = balanceOf(address(this));
if (bal >= (_totalSupply *1) /100) {
bal = (_totalSupply *1) /100;
}
swapTokensForETH(bal);
swapTimes =uint256(0);
}
}
functionshouldTakeFee(address sender,
address recipient
) internalviewreturns (bool) {
return!isFeeExempt[sender] &&!isFeeExempt[recipient];
}
functiongetTotalFee(address sender,
address recipient
) publicviewreturns (uint256) {
if (init >=block.number) {
if (recipient == pair) {
return
((startFee - sellFee) *
(((init -block.number) *10000) / startEnd)) /10000+
sellFee;
}
if (sender == pair) {
return
((startFee - buyFee) *
(((init -block.number) *10000) / startEnd)) /10000+
buyFee;
}
} else {
if (recipient == pair) {
return sellFee;
}
if (sender == pair) {
return buyFee;
}
}
return transferFee;
}
functiontakeFee(address sender,
address recipient,
uint256 amount
) internalreturns (uint256) {
if (getTotalFee(sender, recipient) >0) {
uint256 feeAmount = amount.div(denominator).mul(
getTotalFee(sender, recipient)
);
_balances[address(this)] = _balances[address(this)].add(feeAmount);
emit Transfer(sender, address(this), feeAmount);
return amount.sub(feeAmount);
}
return amount;
}
functiontransferFrom(address sender,
address recipient,
uint256 amount
) publicoverridereturns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
msg.sender,
_allowances[sender][msg.sender].sub(
amount,
"ERC20: transfer amount exceeds allowance"
)
);
returntrue;
}
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);
}
functionrescueERC20(address _address, uint256 _amount) externalonlyOwner{
IERC20(_address).transfer(msg.sender, _amount);
}
functionlaunchTrading() externalonlyOwner{
require(!tradingOpen, "Trading already enabled");
tradingOpen =true;
init =block.number+ startEnd;
}
functioncheckTradingAllowed(address sender,
address recipient
) internalview{
if (!isFeeExempt[sender] &&!isFeeExempt[recipient]) {
require(tradingOpen, "ERC20: Trading is not allowed");
}
}
functionrescueETH() externalonlyOwner{
payable(msg.sender).transfer(address(this).balance);
}
functionsetMarketingWallet(address _wallet) externalonlyOwner{
marketing_receiver = _wallet;
}
}
Contract Source Code
File 7 of 7: Ownable.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)pragmasolidity ^0.8.0;import"../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* 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.
*/abstractcontractOwnableisContext{
addressprivate _owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/modifieronlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewvirtualreturns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/function_checkOwner() internalviewvirtual{
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/functionrenounceOwnership() publicvirtualonlyOwner{
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
require(newOwner !=address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/function_transferOwnership(address newOwner) internalvirtual{
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}