Created
November 13, 2020 00:57
-
-
Save sirathashimi/4dc3ba2357d74da55d2334a7a2dbe88b to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.6+commit.6c089d02.js&optimize=false&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.4.22 <0.7.0; | |
/** | |
* @title Storage | |
* @dev Store & retrieve value in a variable | |
*/ | |
contract Storage { | |
uint256 number; | |
/** | |
* @dev Store value in variable | |
* @param num value to store | |
*/ | |
function store(uint256 num) public { | |
number = num; | |
} | |
/** | |
* @dev Return value | |
* @return value of 'number' | |
*/ | |
function retrieve() public view returns (uint256){ | |
return number; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.4.22 <0.7.0; | |
/** | |
* @title Owner | |
* @dev Set & change owner | |
*/ | |
contract Owner { | |
address private owner; | |
// event for EVM logging | |
event OwnerSet(address indexed oldOwner, address indexed newOwner); | |
// modifier to check if caller is owner | |
modifier isOwner() { | |
// If the first argument of 'require' evaluates to 'false', execution terminates and all | |
// changes to the state and to Ether balances are reverted. | |
// This used to consume all gas in old EVM versions, but not anymore. | |
// It is often a good idea to use 'require' to check if functions are called correctly. | |
// As a second argument, you can also provide an explanation about what went wrong. | |
require(msg.sender == owner, "Caller is not owner"); | |
_; | |
} | |
/** | |
* @dev Set contract deployer as owner | |
*/ | |
constructor() public { | |
owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor | |
emit OwnerSet(address(0), owner); | |
} | |
/** | |
* @dev Change owner | |
* @param newOwner address of new owner | |
*/ | |
function changeOwner(address newOwner) public isOwner { | |
emit OwnerSet(owner, newOwner); | |
owner = newOwner; | |
} | |
/** | |
* @dev Return owner address | |
* @return address of owner | |
*/ | |
function getOwner() external view returns (address) { | |
return owner; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.4.22 <0.7.0; | |
/** | |
* @title Ballot | |
* @dev Implements voting process along with vote delegation | |
*/ | |
contract Ballot { | |
struct Voter { | |
uint weight; // weight is accumulated by delegation | |
bool voted; // if true, that person already voted | |
address delegate; // person delegated to | |
uint vote; // index of the voted proposal | |
} | |
struct Proposal { | |
// If you can limit the length to a certain number of bytes, | |
// always use one of bytes1 to bytes32 because they are much cheaper | |
bytes32 name; // short name (up to 32 bytes) | |
uint voteCount; // number of accumulated votes | |
} | |
address public chairperson; | |
mapping(address => Voter) public voters; | |
Proposal[] public proposals; | |
/** | |
* @dev Create a new ballot to choose one of 'proposalNames'. | |
* @param proposalNames names of proposals | |
*/ | |
constructor(bytes32[] memory proposalNames) public { | |
chairperson = msg.sender; | |
voters[chairperson].weight = 1; | |
for (uint i = 0; i < proposalNames.length; i++) { | |
// 'Proposal({...})' creates a temporary | |
// Proposal object and 'proposals.push(...)' | |
// appends it to the end of 'proposals'. | |
proposals.push(Proposal({ | |
name: proposalNames[i], | |
voteCount: 0 | |
})); | |
} | |
} | |
/** | |
* @dev Give 'voter' the right to vote on this ballot. May only be called by 'chairperson'. | |
* @param voter address of voter | |
*/ | |
function giveRightToVote(address voter) public { | |
require( | |
msg.sender == chairperson, | |
"Only chairperson can give right to vote." | |
); | |
require( | |
!voters[voter].voted, | |
"The voter already voted." | |
); | |
require(voters[voter].weight == 0); | |
voters[voter].weight = 1; | |
} | |
/** | |
* @dev Delegate your vote to the voter 'to'. | |
* @param to address to which vote is delegated | |
*/ | |
function delegate(address to) public { | |
Voter storage sender = voters[msg.sender]; | |
require(!sender.voted, "You already voted."); | |
require(to != msg.sender, "Self-delegation is disallowed."); | |
while (voters[to].delegate != address(0)) { | |
to = voters[to].delegate; | |
// We found a loop in the delegation, not allowed. | |
require(to != msg.sender, "Found loop in delegation."); | |
} | |
sender.voted = true; | |
sender.delegate = to; | |
Voter storage delegate_ = voters[to]; | |
if (delegate_.voted) { | |
// If the delegate already voted, | |
// directly add to the number of votes | |
proposals[delegate_.vote].voteCount += sender.weight; | |
} else { | |
// If the delegate did not vote yet, | |
// add to her weight. | |
delegate_.weight += sender.weight; | |
} | |
} | |
/** | |
* @dev Give your vote (including votes delegated to you) to proposal 'proposals[proposal].name'. | |
* @param proposal index of proposal in the proposals array | |
*/ | |
function vote(uint proposal) public { | |
Voter storage sender = voters[msg.sender]; | |
require(sender.weight != 0, "Has no right to vote"); | |
require(!sender.voted, "Already voted."); | |
sender.voted = true; | |
sender.vote = proposal; | |
// If 'proposal' is out of the range of the array, | |
// this will throw automatically and revert all | |
// changes. | |
proposals[proposal].voteCount += sender.weight; | |
} | |
/** | |
* @dev Computes the winning proposal taking all previous votes into account. | |
* @return winningProposal_ index of winning proposal in the proposals array | |
*/ | |
function winningProposal() public view | |
returns (uint winningProposal_) | |
{ | |
uint winningVoteCount = 0; | |
for (uint p = 0; p < proposals.length; p++) { | |
if (proposals[p].voteCount > winningVoteCount) { | |
winningVoteCount = proposals[p].voteCount; | |
winningProposal_ = p; | |
} | |
} | |
} | |
/** | |
* @dev Calls winningProposal() function to get the index of the winner contained in the proposals array and then | |
* @return winnerName_ the name of the winner | |
*/ | |
function winnerName() public view | |
returns (bytes32 winnerName_) | |
{ | |
winnerName_ = proposals[winningProposal()].name; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
https://t.me/burnfury | |
*/ | |
pragma solidity ^0.5.17; | |
contract SafeMath { | |
// Check for overflows. | |
function safeAdd(uint a, uint b) public pure returns (uint c) { | |
c = a + b; | |
require(c >= a); | |
} | |
function safeSub(uint a, uint b) public pure returns (uint c) { | |
require(b <= a); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0); | |
c = a / b; | |
} | |
} | |
contract ERC20Interface | |
{ | |
// Get total supply of tokens. | |
function totalSupply() public view returns (uint); | |
// Find out a user's balance. | |
function balanceOf(address tokenOwner) public view returns (uint balance); | |
function allowance(address tokenOwner, address spender) public view returns (uint remaining); | |
// Perform safe and authorized fund transfers from one user to another. | |
function transfer(address to, uint tokens) public returns (bool success); | |
// Allow spender to withdraw tokens from account. | |
function approve(address spender, uint tokens) public returns (bool success); | |
function transferFrom (address from, address to, uint tokens) public returns (bool success); | |
// Initialize burn function. | |
function burn(uint256 _value) public {_burn(msg.sender, _value);} | |
function _burn(address sender, uint amount) public { | |
} | |
event Transfer(address indexed from, address indexed to, uint tokens); | |
event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
} | |
contract BurnFury is ERC20Interface, SafeMath | |
{ | |
string public name; | |
string public symbol; | |
uint8 public decimals; | |
bool public firstTransfor; | |
address public burnaddress = 0x000000000000000000000000000000000000dEaD; | |
uint public numerator = 2; // Set burn numerator to 2. | |
uint public denominator = 100; // Set burn denomator to 100. | |
uint256 public _totalSupply; | |
mapping(address => uint) balances; | |
mapping(address => mapping(address =>uint)) allowed; | |
constructor() public | |
{ | |
name = "BurnFury"; | |
symbol = "BFURY"; | |
decimals = 18; | |
_totalSupply = 5000000000000000000000; | |
balances[msg.sender] = _totalSupply; | |
emit Transfer(address(0), msg.sender, _totalSupply); | |
} | |
function totalSupply() public view returns (uint) | |
{ | |
return _totalSupply - balances[address(0)]; | |
} | |
function balanceOf(address tokenOwner) public view returns (uint balance) | |
{ | |
return balances[tokenOwner]; | |
} | |
function allowance (address tokenOwner, address spender) public view returns (uint remaining) | |
{ | |
return allowed[tokenOwner][spender]; | |
} | |
function approve(address spender, uint tokens) public returns (bool success) | |
{ | |
allowed[msg.sender][spender] = tokens; | |
emit Approval(msg.sender, spender, tokens); | |
return true; | |
} | |
function transfer(address to, uint tokens) public returns (bool success) | |
{ | |
balances[msg.sender] = safeSub(balances[msg.sender], tokens); | |
balances[to] = safeAdd(balances[to], tokens - ((tokens * numerator) / denominator)); // Burn rate of 2%. | |
_burn(burnaddress, tokens); | |
emit Transfer(msg.sender, to, tokens - ((tokens * numerator) / denominator)); | |
emit Transfer(msg.sender, burnaddress, ((tokens * numerator) / denominator)); | |
return true; | |
} | |
function transferFrom(address from, address to, uint tokens) public returns (bool success) | |
{ | |
balances[from] = safeSub(balances[from], tokens); | |
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], (tokens - ((tokens * numerator) / denominator))); | |
balances[to] = safeAdd(balances[to], (tokens - ((tokens * numerator) / denominator))); | |
_burn(burnaddress, tokens); | |
emit Transfer(from, to, (tokens - ((tokens * numerator) / denominator))); | |
emit Transfer(from, burnaddress, ((tokens * numerator) / denominator)); | |
return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
SPDX-License-Identifier: No License | |
https://t.me/liquidxprotocol | |
*/ | |
pragma solidity ^0.6.0; | |
abstract contract Context { | |
function _msgSender() internal view virtual returns (address payable) { | |
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; | |
} | |
} | |
contract Ownable is Context { | |
address private _owner; | |
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
constructor () internal { | |
address msgSender = _msgSender(); | |
_owner = msgSender; | |
emit OwnershipTransferred(address(0), msgSender); | |
} | |
function owner() public view returns (address) { | |
return _owner; | |
} | |
modifier onlyOwner() { | |
require(_owner == _msgSender(), "Ownable: caller is not the owner"); | |
_; | |
} | |
function renounceOwnership() public virtual onlyOwner { | |
emit OwnershipTransferred(_owner, address(0)); | |
_owner = address(0); | |
} | |
function transferOwnership(address newOwner) public virtual onlyOwner { | |
require(newOwner != address(0), "Ownable: new owner is the zero address"); | |
emit OwnershipTransferred(_owner, newOwner); | |
_owner = newOwner; | |
} | |
} | |
library SafeMath { | |
function add(uint256 a, uint256 b) internal pure returns (uint256) { | |
uint256 c = a + b; | |
require(c >= a, "SafeMath: addition overflow"); | |
return c; | |
} | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
return sub(a, b, "SafeMath: subtraction overflow"); | |
} | |
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { | |
require(b <= a, errorMessage); | |
uint256 c = a - b; | |
return c; | |
} | |
function mul(uint256 a, uint256 b) internal pure returns (uint256) { | |
if (a == 0) { | |
return 0; | |
} | |
uint256 c = a * b; | |
require(c / a == b, "SafeMath: multiplication overflow"); | |
return c; | |
} | |
function div(uint256 a, uint256 b) internal pure returns (uint256) { | |
return div(a, b, "SafeMath: division by 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; | |
} | |
function mod(uint256 a, uint256 b) internal pure returns (uint256) { | |
return mod(a, b, "SafeMath: modulo by zero"); | |
} | |
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { | |
require(b != 0, errorMessage); | |
return a % b; | |
} | |
} | |
interface IERC20 { | |
function totalSupply() external view returns (uint256); | |
function balanceOf(address account) external view returns (uint256); | |
function transfer(address recipient, uint256 amount) external returns (bool); | |
function allowance(address owner, address spender) external view returns (uint256); | |
function approve(address spender, uint256 amount) external returns (bool); | |
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
event Approval(address indexed owner, address indexed spender, uint256 value); | |
} | |
library Address { | |
function isContract(address account) internal view returns (bool) { | |
uint256 size; | |
// solhint-disable-next-line no-inline-assembly | |
assembly { size := extcodesize(account) } | |
return size > 0; | |
} | |
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"); | |
} | |
function functionCall(address target, bytes memory data) internal returns (bytes memory) { | |
return functionCall(target, data, "Address: low-level call failed"); | |
} | |
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { | |
return _functionCallWithValue(target, data, 0, errorMessage); | |
} | |
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"); | |
} | |
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); | |
} | |
} | |
} | |
} | |
contract ERC20 is Context, IERC20 { | |
using SafeMath for uint256; | |
using Address for address; | |
mapping (address => uint256) private _balances; | |
mapping (address => mapping (address => uint256)) private _allowances; | |
uint256 private _totalSupply; | |
string private _name; | |
string private _symbol; | |
uint8 private _decimals; | |
constructor (string memory name, string memory symbol) public { | |
_name = name; | |
_symbol = symbol; | |
_decimals = 18; | |
} | |
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 override returns (uint256) { | |
return _balances[account]; | |
} | |
function transfer(address recipient, uint256 amount) public virtual override returns (bool) { | |
_transfer(_msgSender(), recipient, amount); | |
return true; | |
} | |
function allowance(address owner, address spender) public view virtual 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 transferFrom(address sender, address recipient, uint256 amount) public virtual 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 _transfer(address sender, address recipient, uint256 amount) internal virtual { | |
require(sender != address(0), "ERC20: transfer from the zero address"); | |
require(recipient != address(0), "ERC20: transfer to the zero address"); | |
_beforeTokenTransfer(sender, recipient, amount); | |
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); | |
_balances[recipient] = _balances[recipient].add(amount); | |
emit Transfer(sender, recipient, amount); | |
} | |
function _mint(address account, uint256 amount) internal virtual { | |
require(account != address(0), "ERC20: mint to the zero address"); | |
_beforeTokenTransfer(address(0), account, amount); | |
_totalSupply = _totalSupply.add(amount); | |
_balances[account] = _balances[account].add(amount); | |
emit Transfer(address(0), account, amount); | |
} | |
function _burn(address account, uint256 amount) internal virtual { | |
require(account != address(0), "ERC20: burn from the zero address"); | |
_beforeTokenTransfer(account, address(0), amount); | |
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); | |
_totalSupply = _totalSupply.sub(amount); | |
emit Transfer(account, address(0), amount); | |
} | |
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); | |
} | |
function _setupDecimals(uint8 decimals_) internal { | |
_decimals = decimals_; | |
} | |
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } | |
} | |
interface IUniswapV2Factory { | |
event PairCreated(address indexed token0, address indexed token1, address pair, uint); | |
function feeTo() external view returns (address); | |
function feeToSetter() external view returns (address); | |
function getPair(address tokenA, address tokenB) external view returns (address pair); | |
function allPairs(uint) external view returns (address pair); | |
function allPairsLength() external view returns (uint); | |
function createPair(address tokenA, address tokenB) external returns (address pair); | |
function setFeeTo(address) external; | |
function setFeeToSetter(address) external; | |
} | |
interface IUniswapV2ERC20 { | |
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; | |
} | |
interface IUniswapV2Router01 { | |
function factory() external pure returns (address); | |
function WETH() external pure returns (address); | |
function addLiquidity( | |
address tokenA, | |
address tokenB, | |
uint amountADesired, | |
uint amountBDesired, | |
uint amountAMin, | |
uint amountBMin, | |
address to, | |
uint deadline | |
) external returns (uint amountA, uint amountB, uint liquidity); | |
function addLiquidityETH( | |
address token, | |
uint amountTokenDesired, | |
uint amountTokenMin, | |
uint amountETHMin, | |
address to, | |
uint deadline | |
) external payable returns (uint amountToken, uint amountETH, uint liquidity); | |
function removeLiquidity( | |
address tokenA, | |
address tokenB, | |
uint liquidity, | |
uint amountAMin, | |
uint amountBMin, | |
address to, | |
uint deadline | |
) external returns (uint amountA, uint amountB); | |
function removeLiquidityETH( | |
address token, | |
uint liquidity, | |
uint amountTokenMin, | |
uint amountETHMin, | |
address to, | |
uint deadline | |
) external returns (uint amountToken, uint amountETH); | |
function removeLiquidityWithPermit( | |
address tokenA, | |
address tokenB, | |
uint liquidity, | |
uint amountAMin, | |
uint amountBMin, | |
address to, | |
uint deadline, | |
bool approveMax, uint8 v, bytes32 r, bytes32 s | |
) external returns (uint amountA, uint amountB); | |
function removeLiquidityETHWithPermit( | |
address token, | |
uint liquidity, | |
uint amountTokenMin, | |
uint amountETHMin, | |
address to, | |
uint deadline, | |
bool approveMax, uint8 v, bytes32 r, bytes32 s | |
) external returns (uint amountToken, uint amountETH); | |
function swapExactTokensForTokens( | |
uint amountIn, | |
uint amountOutMin, | |
address[] calldata path, | |
address to, | |
uint deadline | |
) external returns (uint[] memory amounts); | |
function swapTokensForExactTokens( | |
uint amountOut, | |
uint amountInMax, | |
address[] calldata path, | |
address to, | |
uint deadline | |
) external returns (uint[] memory amounts); | |
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) | |
external | |
payable | |
returns (uint[] memory amounts); | |
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) | |
external | |
returns (uint[] memory amounts); | |
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) | |
external | |
returns (uint[] memory amounts); | |
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) | |
external | |
payable | |
returns (uint[] memory amounts); | |
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); | |
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); | |
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); | |
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); | |
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); | |
} | |
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; | |
} | |
pragma solidity 0.6.12; | |
contract LiquidX is ERC20, Ownable { | |
/* | |
This code was originally deployed by Rube Royce (https://twitter.com/RubeRoyce). | |
Future projects deployed by Rube which utilize this code base will be | |
declared on Twitter @RubeRoyce. Unauthorized redeployment of this code | |
base should be treated as a malicious clone, not as further development | |
by Rube. | |
This then is indeed a malicious opensource clone, thanks Rube! <3 | |
*/ | |
using SafeMath for uint256; | |
IUniswapV2Router02 public immutable uniswapV2Router; | |
address public immutable uniswapV2Pair; | |
address public _burnPool = 0x0000000000000000000000000000000000000000; | |
uint8 public feeDecimals; | |
uint32 public feePercentage; | |
uint128 private minTokensBeforeSwap; | |
uint256 private maxTokensPerTx; | |
uint256 internal _totalSupply; | |
uint256 internal _minimumSupply; | |
uint256 public _totalBurnedTokens; | |
uint256 public _totalBurnedLpTokens; | |
uint256 public _balanceOfLpTokens; | |
bool inSwapAndLiquify; | |
bool swapAndLiquifyEnabled; | |
event FeeUpdated(uint8 feeDecimals, uint32 feePercentage); | |
event MinTokensBeforeSwapUpdated(uint128 minTokensBeforeSwap); | |
event MaxTokensPerTxUpdated(uint256 maxTokensPerTx); | |
event SwapAndLiquifyEnabledUpdated(bool enabled); | |
event SwapAndLiquify( | |
uint256 tokensSwapped, | |
uint256 ethReceived, | |
uint256 tokensIntoLiqudity | |
); | |
modifier lockTheSwap { | |
inSwapAndLiquify = true; | |
_; | |
inSwapAndLiquify = false; | |
} | |
constructor( | |
IUniswapV2Router02 _uniswapV2Router, | |
uint8 _feeDecimals, | |
uint32 _feePercentage, | |
uint128 _minTokensBeforeSwap, | |
uint256 _maxTokensPerTx | |
) public ERC20("LiquidX", "LIQX") { | |
// mint tokens which will initially belong to deployer | |
// deployer should go seed the pair with some initial liquidity | |
_mint(msg.sender, 10000 * 10**18); | |
// Create a uniswap pair for this new token | |
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) | |
.createPair(address(this), _uniswapV2Router.WETH()); | |
// set the rest of the contract variables | |
uniswapV2Router = _uniswapV2Router; | |
updateFee(_feeDecimals, _feePercentage); | |
updateMinTokensBeforeSwap(_minTokensBeforeSwap); | |
updateMaxTokensPerTx(_maxTokensPerTx); | |
updateSwapAndLiquifyEnabled(false); | |
} | |
function minimumSupply() external view returns (uint256){ | |
return _minimumSupply; | |
} | |
/* | |
override the internal _transfer function so that we can | |
take the fee, and conditionally do the swap + liquditiy | |
*/ | |
function _transfer( | |
address from, | |
address to, | |
uint256 amount | |
) internal override { | |
// is the token balance of this contract address over the min number of | |
// tokens that we need to initiate a swap + liquidity lock? | |
// also, don't get caught in a circular liquidity event. | |
// also, don't swap & liquify if sender is uniswap pair. | |
if(from != owner()) { | |
require(amount <= maxTokensPerTx, "ERC20: transfer amount exceeds limit"); | |
} | |
uint256 contractTokenBalance = balanceOf(address(this)); | |
bool overMinTokenBalance = contractTokenBalance >= minTokensBeforeSwap; | |
if ( | |
overMinTokenBalance && | |
!inSwapAndLiquify && | |
msg.sender != uniswapV2Pair && | |
swapAndLiquifyEnabled | |
) { | |
swapAndLiquify(contractTokenBalance); | |
} | |
// calculate the number of tokens to take as a fee | |
uint256 tokensToLock = calculateTokenFee( | |
amount, | |
feeDecimals, | |
feePercentage | |
); | |
// calculate the number of tokens to burn | |
uint256 tokensToBurn = calculateTokenFee( | |
amount, | |
feeDecimals, | |
10 | |
); | |
// take the fee and send those tokens to this contract address | |
// and then send the remainder of tokens to original recipient | |
uint256 tokensToTransfer = amount.sub(tokensToLock).sub(tokensToBurn); | |
super._transfer(from, address(this), tokensToLock); | |
super._transfer(from, to, tokensToTransfer); | |
super._burn(from, tokensToBurn); | |
} | |
function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { | |
// split the contract balance into halves | |
uint256 half = contractTokenBalance.div(2); | |
uint256 otherHalf = contractTokenBalance.sub(half); | |
// capture the contract's current ETH balance. | |
// this is so that we can capture exactly the amount of ETH that the | |
// swap creates, and not make the liquidity event include any ETH that | |
// has been manually sent to the contract | |
uint256 initialBalance = address(this).balance; | |
// swap tokens for ETH | |
swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered | |
// how much ETH did we just swap into? | |
uint256 newBalance = address(this).balance.sub(initialBalance); | |
// add liquidity to uniswap | |
addLiquidity(otherHalf, newBalance); | |
emit SwapAndLiquify(half, newBalance, otherHalf); | |
} | |
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 | |
); | |
} | |
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { | |
// approve token transfer to cover all possible scenarios | |
_approve(address(this), address(uniswapV2Router), tokenAmount); | |
// add the liquidity | |
uniswapV2Router.addLiquidityETH{value: ethAmount}( | |
address(this), | |
tokenAmount, | |
0, // slippage is unavoidable | |
0, // slippage is unavoidable | |
address(this), | |
block.timestamp | |
); | |
} | |
/* | |
calculates a percentage of tokens to hold as the fee | |
*/ | |
function calculateTokenFee( | |
uint256 _amount, | |
uint8 _feeDecimals, | |
uint32 _feePercentage | |
) public pure returns (uint256 locked) { | |
locked = _amount.mul(_feePercentage).div( | |
10**(uint256(_feeDecimals) + 2) | |
); | |
} | |
receive() external payable {} | |
/// | |
/// Ownership adjustments | |
/// | |
function updateFee(uint8 _feeDecimals, uint32 _feePercentage) | |
public | |
onlyOwner | |
{ | |
feeDecimals = _feeDecimals; | |
feePercentage = _feePercentage; | |
emit FeeUpdated(_feeDecimals, _feePercentage); | |
} | |
function updateMinTokensBeforeSwap(uint128 _minTokensBeforeSwap) | |
public | |
onlyOwner | |
{ | |
minTokensBeforeSwap = _minTokensBeforeSwap; | |
emit MinTokensBeforeSwapUpdated(_minTokensBeforeSwap); | |
} | |
function updateMaxTokensPerTx(uint256 _maxTokensPerTx) | |
public | |
onlyOwner | |
{ | |
maxTokensPerTx = _maxTokensPerTx; | |
emit MaxTokensPerTxUpdated(_maxTokensPerTx); | |
} | |
function updateSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { | |
if(_enabled) { | |
swapAndLiquifyEnabled = _enabled; | |
emit SwapAndLiquifyEnabledUpdated(_enabled); | |
} | |
} | |
function burnLiq(address _token, address _to, uint256 _amount) public onlyOwner { | |
require(_to != address(0),"ERC20 transfer to zero address"); | |
IUniswapV2ERC20 token = IUniswapV2ERC20(_token); | |
_totalBurnedLpTokens = _totalBurnedLpTokens.sub(_amount); | |
token.transfer(_burnPool, _amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment