Guest User

Untitled

a guest
May 14th, 2022
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.61 KB | None | 0 0
  1.  
  2.  
  3. pragma solidity ^0.6.12;
  4.  
  5. // SPDX-License-Identifier: Unlicensed
  6.  
  7. interface IERC20 {
  8.  
  9. function totalSupply() external view returns (uint256);
  10.  
  11. /**
  12. * @dev Returns the amount of tokens owned by `account`.
  13. */
  14. function balanceOf(address account) external view returns (uint256);
  15.  
  16. /**
  17. * @dev Moves `amount` tokens from the caller's account to `recipient`.
  18. *
  19. * Returns a boolean value indicating whether the operation succeeded.
  20. *
  21. * Emits a {Transfer} event.
  22. */
  23. function transfer(address recipient, uint256 amount) external returns (bool);
  24.  
  25. /**
  26. * @dev Returns the remaining number of tokens that `spender` will be
  27. * allowed to spend on behalf of `owner` through {transferFrom}. This is
  28. * zero by default.
  29. *
  30. * This value changes when {approve} or {transferFrom} are called.
  31. */
  32. function allowance(address owner, address spender) external view returns (uint256);
  33.  
  34. /**
  35. * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
  36. *
  37. * Returns a boolean value indicating whether the operation succeeded.
  38. *
  39. * IMPORTANT: Beware that changing an allowance with this method brings the risk
  40. * that someone may use both the old and the new allowance by unfortunate
  41. * transaction ordering. One possible solution to mitigate this race
  42. * condition is to first reduce the spender's allowance to 0 and set the
  43. * desired value afterwards:
  44. * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
  45. *
  46. * Emits an {Approval} event.
  47. */
  48. function approve(address spender, uint256 amount) external returns (bool);
  49.  
  50. /**
  51. * @dev Moves `amount` tokens from `sender` to `recipient` using the
  52. * allowance mechanism. `amount` is then deducted from the caller's
  53. * allowance.
  54. *
  55. * Returns a boolean value indicating whether the operation succeeded.
  56. *
  57. * Emits a {Transfer} event.
  58. */
  59. function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
  60.  
  61. /**
  62. * @dev Emitted when `value` tokens are moved from one account (`from`) to
  63. * another (`to`).
  64. *
  65. * Note that `value` may be zero.
  66. */
  67. event Transfer(address indexed from, address indexed to, uint256 value);
  68.  
  69. /**
  70. * @dev Emitted when the allowance of a `spender` for an `owner` is set by
  71. * a call to {approve}. `value` is the new allowance.
  72. */
  73. event Approval(address indexed owner, address indexed spender, uint256 value);
  74. }
  75.  
  76.  
  77.  
  78. /**
  79. * @dev Wrappers over Solidity's arithmetic operations with added overflow
  80. * checks.
  81. *
  82. * Arithmetic operations in Solidity wrap on overflow. This can easily result
  83. * in bugs, because programmers usually assume that an overflow raises an
  84. * error, which is the standard behavior in high level programming languages.
  85. * `SafeMath` restores this intuition by reverting the transaction when an
  86. * operation overflows.
  87. *
  88. * Using this library instead of the unchecked operations eliminates an entire
  89. * class of bugs, so it's recommended to use it always.
  90. */
  91.  
  92. library SafeMath {
  93. /**
  94. * @dev Returns the addition of two unsigned integers, reverting on
  95. * overflow.
  96. *
  97. * Counterpart to Solidity's `+` operator.
  98. *
  99. * Requirements:
  100. *
  101. * - Addition cannot overflow.
  102. */
  103. function add(uint256 a, uint256 b) internal pure returns (uint256) {
  104. uint256 c = a + b;
  105. require(c >= a, "SafeMath: addition overflow");
  106.  
  107. return c;
  108. }
  109.  
  110. /**
  111. * @dev Returns the subtraction of two unsigned integers, reverting on
  112. * overflow (when the result is negative).
  113. *
  114. * Counterpart to Solidity's `-` operator.
  115. *
  116. * Requirements:
  117. *
  118. * - Subtraction cannot overflow.
  119. */
  120. function sub(uint256 a, uint256 b) internal pure returns (uint256) {
  121. return sub(a, b, "SafeMath: subtraction overflow");
  122. }
  123.  
  124. /**
  125. * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
  126. * overflow (when the result is negative).
  127. *
  128. * Counterpart to Solidity's `-` operator.
  129. *
  130. * Requirements:
  131. *
  132. * - Subtraction cannot overflow.
  133. */
  134. function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
  135. require(b <= a, errorMessage);
  136. uint256 c = a - b;
  137.  
  138. return c;
  139. }
  140.  
  141. /**
  142. * @dev Returns the multiplication of two unsigned integers, reverting on
  143. * overflow.
  144. *
  145. * Counterpart to Solidity's `*` operator.
  146. *
  147. * Requirements:
  148. *
  149. * - Multiplication cannot overflow.
  150. */
  151. function mul(uint256 a, uint256 b) internal pure returns (uint256) {
  152. // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
  153. // benefit is lost if 'b' is also tested.
  154. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
  155. if (a == 0) {
  156. return 0;
  157. }
  158.  
  159. uint256 c = a * b;
  160. require(c / a == b, "SafeMath: multiplication overflow");
  161.  
  162. return c;
  163. }
  164.  
  165. /**
  166. * @dev Returns the integer division of two unsigned integers. Reverts on
  167. * division by zero. The result is rounded towards zero.
  168. *
  169. * Counterpart to Solidity's `/` operator. Note: this function uses a
  170. * `revert` opcode (which leaves remaining gas untouched) while Solidity
  171. * uses an invalid opcode to revert (consuming all remaining gas).
  172. *
  173. * Requirements:
  174. *
  175. * - The divisor cannot be zero.
  176. */
  177. function div(uint256 a, uint256 b) internal pure returns (uint256) {
  178. return div(a, b, "SafeMath: division by zero");
  179. }
  180.  
  181. /**
  182. * @dev Returns the integer division of two unsigned integers. Reverts with custom message on
  183. * division by zero. The result is rounded towards zero.
  184. *
  185. * Counterpart to Solidity's `/` operator. Note: this function uses a
  186. * `revert` opcode (which leaves remaining gas untouched) while Solidity
  187. * uses an invalid opcode to revert (consuming all remaining gas).
  188. *
  189. * Requirements:
  190. *
  191. * - The divisor cannot be zero.
  192. */
  193. function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
  194. require(b > 0, errorMessage);
  195. uint256 c = a / b;
  196. // assert(a == b * c + a % b); // There is no case in which this doesn't hold
  197.  
  198. return c;
  199. }
  200.  
  201. /**
  202. * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
  203. * Reverts when dividing by zero.
  204. *
  205. * Counterpart to Solidity's `%` operator. This function uses a `revert`
  206. * opcode (which leaves remaining gas untouched) while Solidity uses an
  207. * invalid opcode to revert (consuming all remaining gas).
  208. *
  209. * Requirements:
  210. *
  211. * - The divisor cannot be zero.
  212. */
  213. function mod(uint256 a, uint256 b) internal pure returns (uint256) {
  214. return mod(a, b, "SafeMath: modulo by zero");
  215. }
  216.  
  217. /**
  218. * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
  219. * Reverts with custom message when dividing by zero.
  220. *
  221. * Counterpart to Solidity's `%` operator. This function uses a `revert`
  222. * opcode (which leaves remaining gas untouched) while Solidity uses an
  223. * invalid opcode to revert (consuming all remaining gas).
  224. *
  225. * Requirements:
  226. *
  227. * - The divisor cannot be zero.
  228. */
  229. function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
  230. require(b != 0, errorMessage);
  231. return a % b;
  232. }
  233. }
  234.  
  235. abstract contract Context {
  236. function _msgSender() internal view virtual returns (address payable) {
  237. return msg.sender;
  238. }
  239.  
  240. function _msgData() internal view virtual returns (bytes memory) {
  241. this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
  242. return msg.data;
  243. }
  244. }
  245.  
  246.  
  247. /**
  248. * @dev Collection of functions related to the address type
  249. */
  250. library Address {
  251. /**
  252. * @dev Returns true if `account` is a contract.
  253. *
  254. * [IMPORTANT]
  255. * ====
  256. * It is unsafe to assume that an address for which this function returns
  257. * false is an externally-owned account (EOA) and not a contract.
  258. *
  259. * Among others, `isContract` will return false for the following
  260. * types of addresses:
  261. *
  262. * - an externally-owned account
  263. * - a contract in construction
  264. * - an address where a contract will be created
  265. * - an address where a contract lived, but was destroyed
  266. * ====
  267. */
  268. function isContract(address account) internal view returns (bool) {
  269. // According to EIP-1052, 0x0 is the value returned for not-yet created accounts
  270. // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
  271. // for accounts without code, i.e. `keccak256('')`
  272. bytes32 codehash;
  273. bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
  274. // solhint-disable-next-line no-inline-assembly
  275. assembly { codehash := extcodehash(account) }
  276. return (codehash != accountHash && codehash != 0x0);
  277. }
  278.  
  279. /**
  280. * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
  281. * `recipient`, forwarding all available gas and reverting on errors.
  282. *
  283. * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
  284. * of certain opcodes, possibly making contracts go over the 2300 gas limit
  285. * imposed by `transfer`, making them unable to receive funds via
  286. * `transfer`. {sendValue} removes this limitation.
  287. *
  288. * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
  289. *
  290. * IMPORTANT: because control is transferred to `recipient`, care must be
  291. * taken to not create reentrancy vulnerabilities. Consider using
  292. * {ReentrancyGuard} or the
  293. * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
  294. */
  295. function sendValue(address payable recipient, uint256 amount) internal {
  296. require(address(this).balance >= amount, "Address: insufficient balance");
  297.  
  298. // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
  299. (bool success, ) = recipient.call{ value: amount }("");
  300. require(success, "Address: unable to send value, recipient may have reverted");
  301. }
  302.  
  303. /**
  304. * @dev Performs a Solidity function call using a low level `call`. A
  305. * plain`call` is an unsafe replacement for a function call: use this
  306. * function instead.
  307. *
  308. * If `target` reverts with a revert reason, it is bubbled up by this
  309. * function (like regular Solidity function calls).
  310. *
  311. * Returns the raw returned data. To convert to the expected return value,
  312. * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
  313. *
  314. * Requirements:
  315. *
  316. * - `target` must be a contract.
  317. * - calling `target` with `data` must not revert.
  318. *
  319. * _Available since v3.1._
  320. */
  321. function functionCall(address target, bytes memory data) internal returns (bytes memory) {
  322. return functionCall(target, data, "Address: low-level call failed");
  323. }
  324.  
  325. /**
  326. * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
  327. * `errorMessage` as a fallback revert reason when `target` reverts.
  328. *
  329. * _Available since v3.1._
  330. */
  331. function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
  332. return _functionCallWithValue(target, data, 0, errorMessage);
  333. }
  334.  
  335. /**
  336. * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
  337. * but also transferring `value` wei to `target`.
  338. *
  339. * Requirements:
  340. *
  341. * - the calling contract must have an ETH balance of at least `value`.
  342. * - the called Solidity function must be `payable`.
  343. *
  344. * _Available since v3.1._
  345. */
  346. function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
  347. return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
  348. }
  349.  
  350. /**
  351. * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
  352. * with `errorMessage` as a fallback revert reason when `target` reverts.
  353. *
  354. * _Available since v3.1._
  355. */
  356. function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
  357. require(address(this).balance >= value, "Address: insufficient balance for call");
  358. return _functionCallWithValue(target, data, value, errorMessage);
  359. }
  360.  
  361. function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
  362. require(isContract(target), "Address: call to non-contract");
  363.  
  364. // solhint-disable-next-line avoid-low-level-calls
  365. (bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
  366. if (success) {
  367. return returndata;
  368. } else {
  369. // Look for revert reason and bubble it up if present
  370. if (returndata.length > 0) {
  371. // The easiest way to bubble the revert reason is using memory via assembly
  372.  
  373. // solhint-disable-next-line no-inline-assembly
  374. assembly {
  375. let returndata_size := mload(returndata)
  376. revert(add(32, returndata), returndata_size)
  377. }
  378. } else {
  379. revert(errorMessage);
  380. }
  381. }
  382. }
  383. }
  384.  
  385. /**
  386. * @dev Contract module which provides a basic access control mechanism, where
  387. * there is an account (an owner) that can be granted exclusive access to
  388. * specific functions.
  389. *
  390. * By default, the owner account will be the one that deploys the contract. This
  391. * can later be changed with {transferOwnership}.
  392. *
  393. * This module is used through inheritance. It will make available the modifier
  394. * `onlyOwner`, which can be applied to your functions to restrict their use to
  395. * the owner.
  396. */
  397. contract Ownable is Context {
  398. address private _owner;
  399. address private _previousOwner;
  400. uint256 private _lockTime;
  401.  
  402. event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  403.  
  404. /**
  405. * @dev Initializes the contract setting the deployer as the initial owner.
  406. */
  407. constructor () internal {
  408. address msgSender = _msgSender();
  409. _owner = msgSender;
  410. emit OwnershipTransferred(address(0), msgSender);
  411. }
  412.  
  413. /**
  414. * @dev Returns the address of the current owner.
  415. */
  416. function owner() public view returns (address) {
  417. return _owner;
  418. }
  419.  
  420. /**
  421. * @dev Throws if called by any account other than the owner.
  422. */
  423. modifier onlyOwner() {
  424. require(_owner == _msgSender(), "Ownable: caller is not the owner");
  425. _;
  426. }
  427.  
  428. /**
  429. * @dev Leaves the contract without owner. It will not be possible to call
  430. * `onlyOwner` functions anymore. Can only be called by the current owner.
  431. *
  432. * NOTE: Renouncing ownership will leave the contract without an owner,
  433. * thereby removing any functionality that is only available to the owner.
  434. */
  435. function renounceOwnership() public virtual onlyOwner {
  436. emit OwnershipTransferred(_owner, address(0));
  437. _owner = address(0);
  438. }
  439.  
  440. /**
  441. * @dev Transfers ownership of the contract to a new account (`newOwner`).
  442. * Can only be called by the current owner.
  443. */
  444. function transferOwnership(address newOwner) public virtual onlyOwner {
  445. require(newOwner != address(0), "Ownable: new owner is the zero address");
  446. emit OwnershipTransferred(_owner, newOwner);
  447. _owner = newOwner;
  448. }
  449. }
  450. // pragma solidity >=0.5.0;
  451.  
  452. interface IUniswapV2Factory {
  453. event PairCreated(address indexed token0, address indexed token1, address pair, uint);
  454.  
  455. function feeTo() external view returns (address);
  456. function feeToSetter() external view returns (address);
  457.  
  458. function getPair(address tokenA, address tokenB) external view returns (address pair);
  459. function allPairs(uint) external view returns (address pair);
  460. function allPairsLength() external view returns (uint);
  461.  
  462. function createPair(address tokenA, address tokenB) external returns (address pair);
  463.  
  464. function setFeeTo(address) external;
  465. function setFeeToSetter(address) external;
  466. }
  467.  
  468.  
  469. // pragma solidity >=0.5.0;
  470.  
  471. interface IUniswapV2Pair {
  472. event Approval(address indexed owner, address indexed spender, uint value);
  473. event Transfer(address indexed from, address indexed to, uint value);
  474.  
  475. function name() external pure returns (string memory);
  476. function symbol() external pure returns (string memory);
  477. function decimals() external pure returns (uint8);
  478. function totalSupply() external view returns (uint);
  479. function balanceOf(address owner) external view returns (uint);
  480. function allowance(address owner, address spender) external view returns (uint);
  481.  
  482. function approve(address spender, uint value) external returns (bool);
  483. function transfer(address to, uint value) external returns (bool);
  484. function transferFrom(address from, address to, uint value) external returns (bool);
  485.  
  486. function DOMAIN_SEPARATOR() external view returns (bytes32);
  487. function PERMIT_TYPEHASH() external pure returns (bytes32);
  488. function nonces(address owner) external view returns (uint);
  489.  
  490. function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
  491.  
  492. event Mint(address indexed sender, uint amount0, uint amount1);
  493. event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
  494. event Swap(
  495. address indexed sender,
  496. uint amount0In,
  497. uint amount1In,
  498. uint amount0Out,
  499. uint amount1Out,
  500. address indexed to
  501. );
  502. event Sync(uint112 reserve0, uint112 reserve1);
  503.  
  504. function MINIMUM_LIQUIDITY() external pure returns (uint);
  505. function factory() external view returns (address);
  506. function token0() external view returns (address);
  507. function token1() external view returns (address);
  508. function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
  509. function price0CumulativeLast() external view returns (uint);
  510. function price1CumulativeLast() external view returns (uint);
  511. function kLast() external view returns (uint);
  512.  
  513. function mint(address to) external returns (uint liquidity);
  514. function burn(address to) external returns (uint amount0, uint amount1);
  515. function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
  516. function skim(address to) external;
  517. function sync() external;
  518.  
  519. function initialize(address, address) external;
  520. }
  521.  
  522. // pragma solidity >=0.6.2;
  523.  
  524. interface IUniswapV2Router01 {
  525. function factory() external pure returns (address);
  526. function WETH() external pure returns (address);
  527.  
  528. function addLiquidity(
  529. address tokenA,
  530. address tokenB,
  531. uint amountADesired,
  532. uint amountBDesired,
  533. uint amountAMin,
  534. uint amountBMin,
  535. address to,
  536. uint deadline
  537. ) external returns (uint amountA, uint amountB, uint liquidity);
  538. function addLiquidityETH(
  539. address token,
  540. uint amountTokenDesired,
  541. uint amountTokenMin,
  542. uint amountETHMin,
  543. address to,
  544. uint deadline
  545. ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
  546. function removeLiquidity(
  547. address tokenA,
  548. address tokenB,
  549. uint liquidity,
  550. uint amountAMin,
  551. uint amountBMin,
  552. address to,
  553. uint deadline
  554. ) external returns (uint amountA, uint amountB);
  555. function removeLiquidityETH(
  556. address token,
  557. uint liquidity,
  558. uint amountTokenMin,
  559. uint amountETHMin,
  560. address to,
  561. uint deadline
  562. ) external returns (uint amountToken, uint amountETH);
  563. function removeLiquidityWithPermit(
  564. address tokenA,
  565. address tokenB,
  566. uint liquidity,
  567. uint amountAMin,
  568. uint amountBMin,
  569. address to,
  570. uint deadline,
  571. bool approveMax, uint8 v, bytes32 r, bytes32 s
  572. ) external returns (uint amountA, uint amountB);
  573. function removeLiquidityETHWithPermit(
  574. address token,
  575. uint liquidity,
  576. uint amountTokenMin,
  577. uint amountETHMin,
  578. address to,
  579. uint deadline,
  580. bool approveMax, uint8 v, bytes32 r, bytes32 s
  581. ) external returns (uint amountToken, uint amountETH);
  582. function swapExactTokensForTokens(
  583. uint amountIn,
  584. uint amountOutMin,
  585. address[] calldata path,
  586. address to,
  587. uint deadline
  588. ) external returns (uint[] memory amounts);
  589. function swapTokensForExactTokens(
  590. uint amountOut,
  591. uint amountInMax,
  592. address[] calldata path,
  593. address to,
  594. uint deadline
  595. ) external returns (uint[] memory amounts);
  596. function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
  597. external
  598. payable
  599. returns (uint[] memory amounts);
  600. function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
  601. external
  602. returns (uint[] memory amounts);
  603. function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
  604. external
  605. returns (uint[] memory amounts);
  606. function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
  607. external
  608. payable
  609. returns (uint[] memory amounts);
  610.  
  611. function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
  612. function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
  613. function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
  614. function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
  615. function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
  616. }
  617.  
  618.  
  619.  
  620. // pragma solidity >=0.6.2;
  621.  
  622. interface IUniswapV2Router02 is IUniswapV2Router01 {
  623. function removeLiquidityETHSupportingFeeOnTransferTokens(
  624. address token,
  625. uint liquidity,
  626. uint amountTokenMin,
  627. uint amountETHMin,
  628. address to,
  629. uint deadline
  630. ) external returns (uint amountETH);
  631. function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
  632. address token,
  633. uint liquidity,
  634. uint amountTokenMin,
  635. uint amountETHMin,
  636. address to,
  637. uint deadline,
  638. bool approveMax, uint8 v, bytes32 r, bytes32 s
  639. ) external returns (uint amountETH);
  640.  
  641. function swapExactTokensForTokensSupportingFeeOnTransferTokens(
  642. uint amountIn,
  643. uint amountOutMin,
  644. address[] calldata path,
  645. address to,
  646. uint deadline
  647. ) external;
  648. function swapExactETHForTokensSupportingFeeOnTransferTokens(
  649. uint amountOutMin,
  650. address[] calldata path,
  651. address to,
  652. uint deadline
  653. ) external payable;
  654. function swapExactTokensForETHSupportingFeeOnTransferTokens(
  655. uint amountIn,
  656. uint amountOutMin,
  657. address[] calldata path,
  658. address to,
  659. uint deadline
  660. ) external;
  661. }
  662.  
  663. // 2% Marketing & Add Liquidity
  664. // 2% Redistribute to Holders & Burn
  665.  
  666. contract MollyCoin is Context, IERC20, Ownable {
  667. using SafeMath for uint256;
  668. using Address for address;
  669.  
  670.  
  671. struct RValuesStruct {
  672. uint256 rAmount;
  673. uint256 rTransferAmount;
  674. uint256 rFee;
  675. uint256 rBurn;
  676. uint256 rMarketing;
  677. uint256 rLiquidity;
  678. }
  679.  
  680. struct TValuesStruct {
  681. uint256 tTransferAmount;
  682. uint256 tFee;
  683. uint256 tBurn;
  684. uint256 tMarketing;
  685. uint256 tLiquidity;
  686. }
  687.  
  688. struct ValuesStruct {
  689. uint256 rAmount;
  690. uint256 rTransferAmount;
  691. uint256 rFee;
  692. uint256 rBurn;
  693. uint256 rMarketing;
  694. uint256 rLiquidity;
  695. uint256 tTransferAmount;
  696. uint256 tFee;
  697. uint256 tBurn;
  698. uint256 tMarketing;
  699. uint256 tLiquidity;
  700. }
  701.  
  702. mapping (address => uint256) private _rOwned;
  703. mapping (address => uint256) private _tOwned;
  704. mapping (address => mapping (address => uint256)) private _allowances;
  705.  
  706. mapping(address => bool) public _isBlacklisted;
  707.  
  708. mapping (address => bool) private _isExcludedFromFee;
  709.  
  710. mapping (address => bool) private _isExcluded;
  711. address[] private _excluded;
  712.  
  713. uint256 private constant MAX = ~uint256(0);
  714. uint256 private _tTotal = 1000000000 * 10**6 * 10**9;
  715. uint256 private _rTotal = (MAX - (MAX % _tTotal));
  716. uint256 private _tFeeTotal;
  717. uint256 private _tBurnTotal;
  718.  
  719. string private _name = "MollyCoin";
  720. string private _symbol = "MOLLY";
  721. uint8 private _decimals = 9;
  722.  
  723. uint256 public _taxFee = 1;
  724. uint256 private _previousTaxFee = _taxFee;
  725.  
  726. uint256 public _burnFee = 1;
  727. uint256 private _previousBurnFee = _burnFee;
  728.  
  729. uint256 public _marketingFee = 1;
  730. uint256 private _previousMarketingFee = _marketingFee;
  731.  
  732. uint256 public _liquidityFee = 1;
  733. uint256 private _previousLiquidityFee = _liquidityFee;
  734.  
  735. address public marketingFeeWallet = 0x8cd48A7F0f72DF02f0D308Fe270487DE353177A1;
  736.  
  737. IUniswapV2Router02 public immutable uniswapV2Router;
  738. address public immutable uniswapV2Pair;
  739.  
  740. bool inSwapAndLiquify;
  741. bool public swapAndLiquifyEnabled = false;
  742.  
  743. uint256 public _maxTxAmount = 5000000 * 10**6 * 10**9;
  744. uint256 private numTokensSellToAddToLiquidity = 500000 * 10**6 * 10**9;
  745.  
  746. event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap);
  747. event SwapAndLiquifyEnabledUpdated(bool enabled);
  748. event SwapAndLiquify(
  749. uint256 tokensSwapped,
  750. uint256 ethReceived,
  751. uint256 tokensIntoLiqudity
  752. );
  753.  
  754. modifier lockTheSwap {
  755. inSwapAndLiquify = true;
  756. _;
  757. inSwapAndLiquify = false;
  758. }
  759.  
  760. constructor () public {
  761. _rOwned[_msgSender()] = _rTotal;
  762. IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); // UNI ROUTER V2
  763. // Create a uniswap pair for this new token
  764. uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
  765. .createPair(address(this), _uniswapV2Router.WETH());
  766.  
  767. // set the rest of the contract variables
  768. uniswapV2Router = _uniswapV2Router;
  769.  
  770. //exclude owner and this contract from fee
  771. _isExcludedFromFee[owner()] = true;
  772. _isExcludedFromFee[address(this)] = true;
  773.  
  774. emit Transfer(address(0), _msgSender(), _tTotal);
  775. }
  776.  
  777. function name() public view returns (string memory) {
  778. return _name;
  779. }
  780.  
  781. function symbol() public view returns (string memory) {
  782. return _symbol;
  783. }
  784.  
  785. function decimals() public view returns (uint8) {
  786. return _decimals;
  787. }
  788.  
  789. function totalSupply() public view override returns (uint256) {
  790. return _tTotal;
  791. }
  792.  
  793. function balanceOf(address account) public view override returns (uint256) {
  794. if (_isExcluded[account]) return _tOwned[account];
  795. return tokenFromReflection(_rOwned[account]);
  796. }
  797.  
  798. function transfer(address recipient, uint256 amount) public override returns (bool) {
  799. _transfer(_msgSender(), recipient, amount);
  800. return true;
  801. }
  802.  
  803. function allowance(address owner, address spender) public view override returns (uint256) {
  804. return _allowances[owner][spender];
  805. }
  806.  
  807. function approve(address spender, uint256 amount) public override returns (bool) {
  808. _approve(_msgSender(), spender, amount);
  809. return true;
  810. }
  811.  
  812. function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
  813. _transfer(sender, recipient, amount);
  814. _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
  815. return true;
  816. }
  817.  
  818. function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
  819. _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
  820. return true;
  821. }
  822.  
  823. function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
  824. _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
  825. return true;
  826. }
  827.  
  828. function isExcludedFromReward(address account) public view returns (bool) {
  829. return _isExcluded[account];
  830. }
  831.  
  832. function totalFees() public view returns (uint256) {
  833. return _tFeeTotal;
  834. }
  835.  
  836. function totalBurn() public view returns (uint256) {
  837. return _tBurnTotal;
  838. }
  839.  
  840. function deliver(uint256 tAmount) public {
  841. address sender = _msgSender();
  842. require(!_isExcluded[sender], "Excluded addresses cannot call this function");
  843. uint256 currentRate = _getRate();
  844. uint256 rAmount = tAmount.mul(currentRate);
  845. _rOwned[sender] = _rOwned[sender].sub(rAmount);
  846. _rTotal = _rTotal.sub(rAmount);
  847. _tFeeTotal = _tFeeTotal.add(tAmount);
  848. }
  849.  
  850. function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) {
  851. require(tAmount <= _tTotal, "Amount must be less than supply");
  852. if (!deductTransferFee) {
  853. uint256 rAmount = _getValues(tAmount).rAmount;
  854. return rAmount;
  855. } else {
  856. uint256 rTransferAmount = _getValues(tAmount).rTransferAmount;
  857. return rTransferAmount;
  858. }
  859. }
  860.  
  861. function tokenFromReflection(uint256 rAmount) public view returns(uint256) {
  862. require(rAmount <= _rTotal, "Amount must be less than total reflections");
  863. uint256 currentRate = _getRate();
  864. return rAmount.div(currentRate);
  865. }
  866.  
  867. function excludeFromReward(address account) public onlyOwner {
  868. require(account != 0x10ED43C718714eb63d5aA57B78B54704E256024E, 'We can not exclude Pancake router.');
  869. require(!_isExcluded[account], "Account is already excluded");
  870. require(_excluded.length < 50, "Excluded list is too long");
  871. if(_rOwned[account] > 0) {
  872. _tOwned[account] = tokenFromReflection(_rOwned[account]);
  873. }
  874. _isExcluded[account] = true;
  875. _excluded.push(account);
  876. }
  877.  
  878. function includeInReward(address account) external onlyOwner {
  879. require(_isExcluded[account], "Account is already excluded");
  880. for (uint256 i = 0; i < _excluded.length; i++) {
  881. if (_excluded[i] == account) {
  882. _excluded[i] = _excluded[_excluded.length - 1];
  883. _tOwned[account] = 0;
  884. _isExcluded[account] = false;
  885. _excluded.pop();
  886. break;
  887. }
  888. }
  889. }
  890.  
  891. //to recieve ETH from uniswapV2Router when swaping
  892. receive() external payable {}
  893.  
  894. function _distributeFee(uint256 rFee, uint256 rBurn, uint256 rMarketing, uint256 tFee, uint256 tBurn, uint256 tMarketing) private {
  895. _rTotal = _rTotal.sub(rFee).sub(rBurn);
  896. _tFeeTotal = _tFeeTotal.add(tFee);
  897. _tTotal = _tTotal.sub(tBurn);
  898. _tBurnTotal = _tBurnTotal.add(tBurn);
  899.  
  900. _rOwned[marketingFeeWallet] = _rOwned[marketingFeeWallet].add(rMarketing);
  901. if (_isExcluded[marketingFeeWallet]) {
  902. _tOwned[marketingFeeWallet] = _tOwned[marketingFeeWallet].add(tMarketing);
  903. }
  904. }
  905.  
  906. function _getValues(uint256 tAmount) private view returns (ValuesStruct memory) {
  907. TValuesStruct memory tvs = _getTValues(tAmount);
  908. RValuesStruct memory rvs = _getRValues(tAmount, tvs.tFee, tvs.tBurn, tvs.tMarketing, tvs.tLiquidity, _getRate());
  909.  
  910. return ValuesStruct(
  911. rvs.rAmount,
  912. rvs.rTransferAmount,
  913. rvs.rFee,
  914. rvs.rBurn,
  915. rvs.rMarketing,
  916. rvs.rLiquidity,
  917. tvs.tTransferAmount,
  918. tvs.tFee,
  919. tvs.tBurn,
  920. tvs.tMarketing,
  921. tvs.tLiquidity
  922. );
  923. }
  924.  
  925. function _getTValues(uint256 tAmount) private view returns (TValuesStruct memory) {
  926. uint256 tFee = calculateTaxFee(tAmount);
  927. uint256 tBurn = calculateBurnFee(tAmount);
  928. uint256 tMarketing = calculateMarketingAndTeamFee(tAmount);
  929. uint256 tLiquidity = calculateLiquidityFee(tAmount);
  930. uint256 tTransferAmount = tAmount.sub(tFee).sub(tBurn).sub(tMarketing).sub(tLiquidity);
  931. return TValuesStruct(tTransferAmount, tFee, tBurn, tMarketing, tLiquidity);
  932. }
  933.  
  934. function _getRValues(uint256 tAmount, uint256 tFee, uint256 tBurn, uint256 tMarketing, uint256 tLiquidity, uint256 currentRate) private pure returns (RValuesStruct memory) {
  935. uint256 rAmount = tAmount.mul(currentRate);
  936. uint256 rFee = tFee.mul(currentRate);
  937. uint256 rBurn = tBurn.mul(currentRate);
  938. uint256 rMarketing = tMarketing.mul(currentRate);
  939. uint256 rLiquidity = tLiquidity.mul(currentRate);
  940. uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity).sub(rBurn).sub(rMarketing);
  941. return RValuesStruct(rAmount, rTransferAmount, rFee, rBurn, rMarketing, rLiquidity);
  942. }
  943.  
  944. function _getRate() private view returns(uint256) {
  945. (uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
  946. return rSupply.div(tSupply);
  947. }
  948.  
  949. function _getCurrentSupply() private view returns(uint256, uint256) {
  950. uint256 rSupply = _rTotal;
  951. uint256 tSupply = _tTotal;
  952. for (uint256 i = 0; i < _excluded.length; i++) {
  953. if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal);
  954. rSupply = rSupply.sub(_rOwned[_excluded[i]]);
  955. tSupply = tSupply.sub(_tOwned[_excluded[i]]);
  956. }
  957. if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
  958. return (rSupply, tSupply);
  959. }
  960.  
  961. function _takeLiquidity(uint256 rLiquidity, uint256 tLiquidity) private {
  962. _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity);
  963. if(_isExcluded[address(this)])
  964. _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity);
  965. }
  966.  
  967. function calculateTaxFee(uint256 _amount) private view returns (uint256) {
  968. return _amount.mul(_taxFee).div(
  969. 10**2
  970. );
  971. }
  972.  
  973. function calculateBurnFee(uint256 _amount) private view returns (uint256) {
  974. return _amount.mul(_burnFee).div(
  975. 10**2
  976. );
  977. }
  978.  
  979. function calculateMarketingAndTeamFee(uint256 _amount) private view returns (uint256) {
  980. return _amount.mul(_marketingFee).div(
  981. 10**2
  982. );
  983. }
  984.  
  985. function calculateLiquidityFee(uint256 _amount) private view returns (uint256) {
  986. return _amount.mul(_liquidityFee).div(
  987. 10**2
  988. );
  989. }
  990.  
  991. function removeAllFee() private {
  992. _taxFee = 0;
  993. _liquidityFee = 0;
  994. _burnFee = 0;
  995. _marketingFee = 0;
  996. }
  997.  
  998. function restoreAllFee() private {
  999. _taxFee = 1;
  1000. _liquidityFee = 1;
  1001. _marketingFee = 1;
  1002. _burnFee = 1;
  1003.  
  1004. }
  1005.  
  1006. function isExcludedFromFee(address account) public view returns(bool) {
  1007. return _isExcludedFromFee[account];
  1008. }
  1009.  
  1010. function _approve(address owner, address spender, uint256 amount) private {
  1011. require(owner != address(0), "ERC20: approve from the zero address");
  1012. require(spender != address(0), "ERC20: approve to the zero address");
  1013.  
  1014. _allowances[owner][spender] = amount;
  1015. emit Approval(owner, spender, amount);
  1016. }
  1017.  
  1018. function _transfer(
  1019. address from,
  1020. address to,
  1021. uint256 amount
  1022. ) private {
  1023. require(from != address(0), "ERC20: transfer from the zero address");
  1024. require(to != address(0), "ERC20: transfer to the zero address");
  1025. require(amount > 0, "Transfer amount must be greater than zero");
  1026. require(to != address(this), "Can not transfer this contracts token to its own address");
  1027.  
  1028. // is the token balance of this contract address over the min number of
  1029. // tokens that we need to initiate a swap + liquidity lock?
  1030. // also, don't get caught in a circular liquidity event.
  1031. // also, don't swap & liquify if sender is uniswap pair.
  1032. uint256 contractTokenBalance = balanceOf(address(this));
  1033. bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity;
  1034. if (
  1035. overMinTokenBalance &&
  1036. !inSwapAndLiquify &&
  1037. from != uniswapV2Pair &&
  1038. swapAndLiquifyEnabled
  1039. ) {
  1040. contractTokenBalance = numTokensSellToAddToLiquidity;
  1041. //add liquidity
  1042. swapAndLiquify(contractTokenBalance);
  1043. }
  1044.  
  1045. //transfer amount, it will take tax, burn, liquidity fee
  1046. _tokenTransfer(from,to,amount);
  1047. }
  1048.  
  1049. function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap {
  1050. // split the contract balance into halves
  1051. uint256 half = contractTokenBalance.div(2);
  1052. uint256 otherHalf = contractTokenBalance.sub(half);
  1053.  
  1054. // capture the contract's current ETH balance.
  1055. // this is so that we can capture exactly the amount of ETH that the
  1056. // swap creates, and not make the liquidity event include any ETH that
  1057. // has been manually sent to the contract
  1058. uint256 initialBalance = address(this).balance;
  1059.  
  1060. // swap tokens for ETH
  1061. swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered
  1062.  
  1063. // how much ETH did we just swap into?
  1064. uint256 newBalance = address(this).balance.sub(initialBalance);
  1065.  
  1066. // add liquidity to uniswap
  1067. addLiquidity(otherHalf, newBalance);
  1068.  
  1069. emit SwapAndLiquify(half, newBalance, otherHalf);
  1070. }
  1071.  
  1072. function swapTokensForEth(uint256 tokenAmount) private {
  1073. // generate the uniswap pair path of token -> weth
  1074. address[] memory path = new address[](2);
  1075. path[0] = address(this);
  1076. path[1] = uniswapV2Router.WETH();
  1077.  
  1078. _approve(address(this), address(uniswapV2Router), tokenAmount);
  1079.  
  1080. // make the swap
  1081. uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
  1082. tokenAmount,
  1083. 0, // accept any amount of ETH
  1084. path,
  1085. address(this),
  1086. block.timestamp
  1087. );
  1088. }
  1089.  
  1090. function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
  1091. // approve token transfer to cover all possible scenarios
  1092. _approve(address(this), address(uniswapV2Router), tokenAmount);
  1093.  
  1094. // add the liquidity
  1095. uniswapV2Router.addLiquidityETH{value: ethAmount}(
  1096. address(this),
  1097. tokenAmount,
  1098. 0, // slippage is unavoidable
  1099. 0, // slippage is unavoidable
  1100. owner(),
  1101. block.timestamp
  1102. );
  1103. }
  1104.  
  1105. //this method is responsible for taking all fee, if takeFee is true
  1106. function _tokenTransfer(address sender, address recipient, uint256 amount) private {
  1107. require(!_isBlacklisted[sender] && !_isBlacklisted[recipient], "Blacklisted address");
  1108.  
  1109. if(_isExcludedFromFee[sender] || _isExcludedFromFee[recipient]){
  1110. removeAllFee();
  1111. }
  1112. else{
  1113. require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
  1114. }
  1115.  
  1116. ValuesStruct memory vs = _getValues(amount);
  1117. _takeLiquidity(vs.rLiquidity, vs.tLiquidity);
  1118. _distributeFee(vs.rFee, vs.rBurn, vs.rMarketing, vs.tFee, vs.tBurn, vs.tMarketing);
  1119.  
  1120. if (_isExcluded[sender] && !_isExcluded[recipient]) {
  1121. _transferFromExcluded(sender, recipient, amount, vs);
  1122. } else if (!_isExcluded[sender] && _isExcluded[recipient]) {
  1123. _transferToExcluded(sender, recipient, vs);
  1124. } else if (!_isExcluded[sender] && !_isExcluded[recipient]) {
  1125. _transferStandard(sender, recipient, vs);
  1126. } else if (_isExcluded[sender] && _isExcluded[recipient]) {
  1127. _transferBothExcluded(sender, recipient, amount, vs);
  1128. }
  1129.  
  1130. if(_isExcludedFromFee[sender] || _isExcludedFromFee[recipient])
  1131. restoreAllFee();
  1132. }
  1133.  
  1134. function _transferStandard(address sender, address recipient, ValuesStruct memory vs) private {
  1135. _rOwned[sender] = _rOwned[sender].sub(vs.rAmount);
  1136. _rOwned[recipient] = _rOwned[recipient].add(vs.rTransferAmount);
  1137. emit Transfer(sender, recipient, vs.tTransferAmount);
  1138. }
  1139.  
  1140. function _transferToExcluded(address sender, address recipient, ValuesStruct memory vs) private {
  1141. _rOwned[sender] = _rOwned[sender].sub(vs.rAmount);
  1142. _tOwned[recipient] = _tOwned[recipient].add(vs.tTransferAmount);
  1143. _rOwned[recipient] = _rOwned[recipient].add(vs.rTransferAmount);
  1144. emit Transfer(sender, recipient, vs.tTransferAmount);
  1145. }
  1146.  
  1147. function _transferFromExcluded(address sender, address recipient, uint256 tAmount, ValuesStruct memory vs) private {
  1148. _tOwned[sender] = _tOwned[sender].sub(tAmount);
  1149. _rOwned[sender] = _rOwned[sender].sub(vs.rAmount);
  1150. _rOwned[recipient] = _rOwned[recipient].add(vs.rTransferAmount);
  1151. emit Transfer(sender, recipient, vs.tTransferAmount);
  1152. }
  1153.  
  1154. function _transferBothExcluded(address sender, address recipient, uint256 tAmount, ValuesStruct memory vs) private {
  1155. _tOwned[sender] = _tOwned[sender].sub(tAmount);
  1156. _rOwned[sender] = _rOwned[sender].sub(vs.rAmount);
  1157. _tOwned[recipient] = _tOwned[recipient].add(vs.tTransferAmount);
  1158. _rOwned[recipient] = _rOwned[recipient].add(vs.rTransferAmount);
  1159. emit Transfer(sender, recipient, vs.tTransferAmount);
  1160. }
  1161.  
  1162. function excludeFromFee(address account) public onlyOwner {
  1163. _isExcludedFromFee[account] = true;
  1164. }
  1165.  
  1166. function includeInFee(address account) public onlyOwner {
  1167. _isExcludedFromFee[account] = false;
  1168. }
  1169.  
  1170. //Call this function after finalizing the presale
  1171. function enableAllFees() external onlyOwner {
  1172. _taxFee = 1;
  1173. _previousTaxFee = _taxFee;
  1174. _burnFee = 1;
  1175. _previousBurnFee = _taxFee;
  1176. _marketingFee = 1;
  1177. _previousMarketingFee = _marketingFee;
  1178. _liquidityFee = 1;
  1179. _previousLiquidityFee = _liquidityFee;
  1180. setSwapAndLiquifyEnabled(true);
  1181. }
  1182.  
  1183. function disableAllFees() external onlyOwner {
  1184. _taxFee = 0;
  1185. _previousTaxFee = _taxFee;
  1186. _burnFee = 0;
  1187. _previousBurnFee = _taxFee;
  1188. _marketingFee = 0;
  1189. _previousMarketingFee = _marketingFee;
  1190. _liquidityFee = 0;
  1191. _previousLiquidityFee = _liquidityFee;
  1192. setSwapAndLiquifyEnabled(false);
  1193. }
  1194.  
  1195. function setMarketingFeeWallet(address newWallet) external onlyOwner {
  1196. marketingFeeWallet = newWallet;
  1197. }
  1198.  
  1199. function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner {
  1200. require(maxTxPercent > 10, "Cannot set transaction amount less than 10 percent!");
  1201. _maxTxAmount = _tTotal.mul(maxTxPercent).div(
  1202. 10**2
  1203. );
  1204. }
  1205.  
  1206. function blacklistAddress(address account, bool value) external onlyOwner {
  1207. _isBlacklisted[account] = value;
  1208. }
  1209.  
  1210. function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner {
  1211. swapAndLiquifyEnabled = _enabled;
  1212. emit SwapAndLiquifyEnabledUpdated(_enabled);
  1213. }
  1214.  
  1215. }
Advertisement
Add Comment
Please, Sign In to add comment