Advertisement
wolfofcrypto10x

KINDER SOURCE CODE

Apr 23rd, 2022
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 102.24 KB | None | 0 0
  1. Tib74, [4/22/2022 6:56 PM]
  2. /**
  3. *Submitted for verification at BscScan.com on 2021-11-21
  4. */
  5.  
  6. // Dependency file: @openzeppelin/contracts/token/ERC20/IERC20.sol
  7.  
  8. // SPDX-License-Identifier: MIT
  9.  
  10. // pragma solidity ^0.8.0;
  11.  
  12. /**
  13. * @dev Interface of the ERC20 standard as defined in the EIP.
  14. */
  15. interface IERC20 {
  16. /**
  17. * @dev Returns the amount of tokens in existence.
  18. */
  19. function totalSupply() external view returns (uint256);
  20.  
  21. /**
  22. * @dev Returns the amount of tokens owned by account.
  23. */
  24. function balanceOf(address account) external view returns (uint256);
  25.  
  26. /**
  27. * @dev Moves amount tokens from the caller's account to recipient.
  28. *
  29. * Returns a boolean value indicating whether the operation succeeded.
  30. *
  31. * Emits a {Transfer} event.
  32. */
  33. function transfer(address recipient, uint256 amount) external returns (bool);
  34.  
  35. /**
  36. * @dev Returns the remaining number of tokens that spender will be
  37. * allowed to spend on behalf of owner through {transferFrom}. This is
  38. * zero by default.
  39. *
  40. * This value changes when {approve} or {transferFrom} are called.
  41. */
  42. function allowance(address owner, address spender) external view returns (uint256);
  43.  
  44. /**
  45. * @dev Sets amount as the allowance of spender over the caller's tokens.
  46. *
  47. * Returns a boolean value indicating whether the operation succeeded.
  48. *
  49. * IMPORTANT: Beware that changing an allowance with this method brings the risk
  50. * that someone may use both the old and the new allowance by unfortunate
  51. * transaction ordering. One possible solution to mitigate this race
  52. * condition is to first reduce the spender's allowance to 0 and set the
  53. * desired value afterwards:
  54. * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
  55. *
  56. * Emits an {Approval} event.
  57. */
  58. function approve(address spender, uint256 amount) external returns (bool);
  59.  
  60. /**
  61. * @dev Moves amount tokens from sender to recipient using the
  62. * allowance mechanism. amount is then deducted from the caller's
  63. * allowance.
  64. *
  65. * Returns a boolean value indicating whether the operation succeeded.
  66. *
  67. * Emits a {Transfer} event.
  68. */
  69. function transferFrom(
  70. address sender,
  71. address recipient,
  72. uint256 amount
  73. ) external returns (bool);
  74.  
  75. /**
  76. * @dev Emitted when value tokens are moved from one account (`from`) to
  77. * another (`to`).
  78. *
  79. * Note that value may be zero.
  80. */
  81. event Transfer(address indexed from, address indexed to, uint256 value);
  82.  
  83. /**
  84. * @dev Emitted when the allowance of a spender for an owner is set by
  85. * a call to {approve}. value is the new allowance.
  86. */
  87. event Approval(address indexed owner, address indexed spender, uint256 value);
  88. }
  89.  
  90.  
  91. // Dependency file: @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
  92.  
  93.  
  94. // pragma solidity ^0.8.0;
  95.  
  96. // import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
  97.  
  98. /**
  99. * @dev Interface for the optional metadata functions from the ERC20 standard.
  100. *
  101. * _Available since v4.1._
  102. */
  103. interface IERC20Metadata is IERC20 {
  104. /**
  105. * @dev Returns the name of the token.
  106. */
  107. function name() external view returns (string memory);
  108.  
  109. /**
  110. * @dev Returns the symbol of the token.
  111. */
  112. function symbol() external view returns (string memory);
  113.  
  114. /**
  115. * @dev Returns the decimals places of the token.
  116. */
  117. function decimals() external view returns (uint8);
  118. }
  119.  
  120.  
  121. // Dependency file: @openzeppelin/contracts/utils/Context.sol
  122.  
  123.  
  124. // pragma solidity ^0.8.0;
  125.  
  126. /**
  127. * @dev Provides information about the current execution context, including the
  128. * sender of the transaction and its data. While these are generally available
  129. * via msg.sender and msg.data, they should not be accessed in such a direct
  130. * manner, since when dealing with meta-transactions the account sending and
  131. * paying for execution may not be the actual sender (as far as an application
  132. * is concerned).
  133. *
  134.  
  135. Tib74, [4/22/2022 6:56 PM]
  136. * This contract is only required for intermediate, library-like contracts.
  137. */
  138. abstract contract Context {
  139. function _msgSender() internal view virtual returns (address) {
  140. return msg.sender;
  141. }
  142.  
  143. function _msgData() internal view virtual returns (bytes calldata) {
  144. return msg.data;
  145. }
  146. }
  147.  
  148.  
  149. // Dependency file: @openzeppelin/contracts/token/ERC20/ERC20.sol
  150.  
  151.  
  152. // pragma solidity ^0.8.0;
  153.  
  154. // import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
  155. // import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
  156. // import "@openzeppelin/contracts/utils/Context.sol";
  157.  
  158. /**
  159. * @dev Implementation of the {IERC20} interface.
  160. *
  161. * This implementation is agnostic to the way tokens are created. This means
  162. * that a supply mechanism has to be added in a derived contract using {_mint}.
  163. * For a generic mechanism see {ERC20PresetMinterPauser}.
  164. *
  165. * TIP: For a detailed writeup see our guide
  166. * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
  167. * to implement supply mechanisms].
  168. *
  169. * We have followed general OpenZeppelin Contracts guidelines: functions revert
  170. * instead returning false on failure. This behavior is nonetheless
  171. * conventional and does not conflict with the expectations of ERC20
  172. * applications.
  173. *
  174. * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
  175. * This allows applications to reconstruct the allowance for all accounts just
  176. * by listening to said events. Other implementations of the EIP may not emit
  177. * these events, as it isn't required by the specification.
  178. *
  179. * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
  180. * functions have been added to mitigate the well-known issues around setting
  181. * allowances. See {IERC20-approve}.
  182. */
  183. contract ERC20 is Context, IERC20, IERC20Metadata {
  184. mapping(address => uint256) private _balances;
  185.  
  186. mapping(address => mapping(address => uint256)) private _allowances;
  187.  
  188. uint256 private _totalSupply;
  189.  
  190. string private _name;
  191. string private _symbol;
  192.  
  193. /**
  194. * @dev Sets the values for {name} and {symbol}.
  195. *
  196. * The default value of {decimals} is 18. To select a different value for
  197. * {decimals} you should overload it.
  198. *
  199. * All two of these values are immutable: they can only be set once during
  200. * construction.
  201. */
  202. constructor(string memory name_, string memory symbol_) {
  203. _name = name_;
  204. _symbol = symbol_;
  205. }
  206.  
  207. /**
  208. * @dev Returns the name of the token.
  209. */
  210. function name() public view virtual override returns (string memory) {
  211. return _name;
  212. }
  213.  
  214. /**
  215. * @dev Returns the symbol of the token, usually a shorter version of the
  216. * name.
  217. */
  218. function symbol() public view virtual override returns (string memory) {
  219. return _symbol;
  220. }
  221.  
  222. /**
  223. * @dev Returns the number of decimals used to get its user representation.
  224. * For example, if decimals equals 2, a balance of 505 tokens should
  225. * be displayed to a user as 5.05 (`505 / 10 ** 2`).
  226. *
  227. * Tokens usually opt for a value of 18, imitating the relationship between
  228. * Ether and Wei. This is the value {ERC20} uses, unless this function is
  229. * overridden;
  230. *
  231. * NOTE: This information is only used for _display_ purposes: it in
  232. * no way affects any of the arithmetic of the contract, including
  233. * {IERC20-balanceOf} and {IERC20-transfer}.
  234. */
  235. function decimals() public view virtual override returns (uint8) {
  236. return 18;
  237. }
  238.  
  239. /**
  240. * @dev See {IERC20-totalSupply}.
  241. */
  242. function totalSupply() public view virtual override returns (uint256) {
  243. return _totalSupply;
  244. }
  245.  
  246. /**
  247. * @dev See {IERC20-balanceOf}.
  248. */
  249. function balanceOf(address account) public view virtual override returns (uint256) {
  250. return _balances[account];
  251. }
  252.  
  253. /**
  254. * @dev See {IERC20-transfer}.
  255. *
  256. * Requirements:
  257. *
  258. * - recipient cannot be the zero address.
  259. * - the caller must have a balance of at least amount.
  260.  
  261. Tib74, [4/22/2022 6:56 PM]
  262. */
  263. function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
  264. _transfer(_msgSender(), recipient, amount);
  265. return true;
  266. }
  267.  
  268. /**
  269. * @dev See {IERC20-allowance}.
  270. */
  271. function allowance(address owner, address spender) public view virtual override returns (uint256) {
  272. return _allowances[owner][spender];
  273. }
  274.  
  275. /**
  276. * @dev See {IERC20-approve}.
  277. *
  278. * Requirements:
  279. *
  280. * - spender cannot be the zero address.
  281. */
  282. function approve(address spender, uint256 amount) public virtual override returns (bool) {
  283. _approve(_msgSender(), spender, amount);
  284. return true;
  285. }
  286.  
  287. /**
  288. * @dev See {IERC20-transferFrom}.
  289. *
  290. * Emits an {Approval} event indicating the updated allowance. This is not
  291. * required by the EIP. See the note at the beginning of {ERC20}.
  292. *
  293. * Requirements:
  294. *
  295. * - sender and recipient cannot be the zero address.
  296. * - sender must have a balance of at least amount.
  297. * - the caller must have allowance for ``sender``'s tokens of at least
  298. * amount.
  299. */
  300. function transferFrom(
  301. address sender,
  302. address recipient,
  303. uint256 amount
  304. ) public virtual override returns (bool) {
  305. _transfer(sender, recipient, amount);
  306.  
  307. uint256 currentAllowance = _allowances[sender][_msgSender()];
  308. require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
  309. unchecked {
  310. _approve(sender, _msgSender(), currentAllowance - amount);
  311. }
  312.  
  313. return true;
  314. }
  315.  
  316. /**
  317. * @dev Atomically increases the allowance granted to spender by the caller.
  318. *
  319. * This is an alternative to {approve} that can be used as a mitigation for
  320. * problems described in {IERC20-approve}.
  321. *
  322. * Emits an {Approval} event indicating the updated allowance.
  323. *
  324. * Requirements:
  325. *
  326. * - spender cannot be the zero address.
  327. */
  328. function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
  329. _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
  330. return true;
  331. }
  332.  
  333. /**
  334. * @dev Atomically decreases the allowance granted to spender by the caller.
  335. *
  336. * This is an alternative to {approve} that can be used as a mitigation for
  337. * problems described in {IERC20-approve}.
  338. *
  339. * Emits an {Approval} event indicating the updated allowance.
  340. *
  341. * Requirements:
  342. *
  343. * - spender cannot be the zero address.
  344. * - spender must have allowance for the caller of at least
  345. * subtractedValue.
  346. */
  347. function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
  348. uint256 currentAllowance = _allowances[_msgSender()][spender];
  349. require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
  350. unchecked {
  351. _approve(_msgSender(), spender, currentAllowance - subtractedValue);
  352. }
  353.  
  354. return true;
  355. }
  356.  
  357. /**
  358. * @dev Moves amount of tokens from sender to recipient.
  359. *
  360. * This internal function is equivalent to {transfer}, and can be used to
  361. * e.g. implement automatic token fees, slashing mechanisms, etc.
  362. *
  363. * Emits a {Transfer} event.
  364. *
  365. * Requirements:
  366. *
  367. * - sender cannot be the zero address.
  368. * - recipient cannot be the zero address.
  369. * - sender must have a balance of at least amount.
  370. */
  371. function _transfer(
  372. address sender,
  373. address recipient,
  374. uint256 amount
  375. ) internal virtual {
  376. require(sender != address(0), "ERC20: transfer from the zero address");
  377. require(recipient != address(0), "ERC20: transfer to the zero address");
  378.  
  379. _beforeTokenTransfer(sender, recipient, amount);
  380.  
  381. uint256 senderBalance = _balances[sender];
  382. require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
  383. unchecked {
  384.  
  385. Tib74, [4/22/2022 6:56 PM]
  386. _balances[sender] = senderBalance - amount;
  387. }
  388. _balances[recipient] += amount;
  389.  
  390. emit Transfer(sender, recipient, amount);
  391.  
  392. _afterTokenTransfer(sender, recipient, amount);
  393. }
  394.  
  395. /** @dev Creates amount tokens and assigns them to account, increasing
  396. * the total supply.
  397. *
  398. * Emits a {Transfer} event with from set to the zero address.
  399. *
  400. * Requirements:
  401. *
  402. * - account cannot be the zero address.
  403. */
  404. function _mint(address account, uint256 amount) internal virtual {
  405. require(account != address(0), "ERC20: mint to the zero address");
  406.  
  407. _beforeTokenTransfer(address(0), account, amount);
  408.  
  409. _totalSupply += amount;
  410. _balances[account] += amount;
  411. emit Transfer(address(0), account, amount);
  412.  
  413. _afterTokenTransfer(address(0), account, amount);
  414. }
  415.  
  416. /**
  417. * @dev Destroys amount tokens from account, reducing the
  418. * total supply.
  419. *
  420. * Emits a {Transfer} event with to set to the zero address.
  421. *
  422. * Requirements:
  423. *
  424. * - account cannot be the zero address.
  425. * - account must have at least amount tokens.
  426. */
  427. function _burn(address account, uint256 amount) internal virtual {
  428. require(account != address(0), "ERC20: burn from the zero address");
  429.  
  430. _beforeTokenTransfer(account, address(0), amount);
  431.  
  432. uint256 accountBalance = _balances[account];
  433. require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
  434. unchecked {
  435. _balances[account] = accountBalance - amount;
  436. }
  437. _totalSupply -= amount;
  438.  
  439. emit Transfer(account, address(0), amount);
  440.  
  441. _afterTokenTransfer(account, address(0), amount);
  442. }
  443.  
  444. /**
  445. * @dev Sets amount as the allowance of spender over the owner s tokens.
  446. *
  447. * This internal function is equivalent to approve, and can be used to
  448. * e.g. set automatic allowances for certain subsystems, etc.
  449. *
  450. * Emits an {Approval} event.
  451. *
  452. * Requirements:
  453. *
  454. * - owner cannot be the zero address.
  455. * - spender cannot be the zero address.
  456. */
  457. function _approve(
  458. address owner,
  459. address spender,
  460. uint256 amount
  461. ) internal virtual {
  462. require(owner != address(0), "ERC20: approve from the zero address");
  463. require(spender != address(0), "ERC20: approve to the zero address");
  464.  
  465. _allowances[owner][spender] = amount;
  466. emit Approval(owner, spender, amount);
  467. }
  468.  
  469. /**
  470. * @dev Hook that is called before any transfer of tokens. This includes
  471. * minting and burning.
  472. *
  473. * Calling conditions:
  474. *
  475. * - when from and to are both non-zero, amount of ``from``'s tokens
  476. * will be transferred to to.
  477. * - when from is zero, amount tokens will be minted for to.
  478. * - when to is zero, amount of ``from``'s tokens will be burned.
  479. * - from and to are never both zero.
  480. *
  481. * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
  482. */
  483. function _beforeTokenTransfer(
  484. address from,
  485. address to,
  486. uint256 amount
  487. ) internal virtual {}
  488.  
  489. /**
  490. * @dev Hook that is called after any transfer of tokens. This includes
  491. * minting and burning.
  492. *
  493. * Calling conditions:
  494. *
  495. * - when from and to are both non-zero, amount of ``from``'s tokens
  496. * has been transferred to to.
  497. * - when from is zero, amount tokens have been minted for to.
  498. * - when to is zero, amount of ``from``'s tokens have been burned.
  499. * - from and to are never both zero.
  500. *
  501. * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
  502. */
  503. function _afterTokenTransfer(
  504. address from,
  505. address to,
  506. uint256 amount
  507. ) internal virtual {}
  508. }
  509.  
  510.  
  511. // Dependency file: @openzeppelin/contracts/access/Ownable.sol
  512.  
  513.  
  514. // pragma solidity ^0.8.0;
  515.  
  516. // import "@openzeppelin/contracts/utils/Context.sol";
  517.  
  518. /**
  519.  
  520. Tib74, [4/22/2022 6:56 PM]
  521. * @dev Contract module which provides a basic access control mechanism, where
  522. * there is an account (an owner) that can be granted exclusive access to
  523. * specific functions.
  524. *
  525. * By default, the owner account will be the one that deploys the contract. This
  526. * can later be changed with {transferOwnership}.
  527. *
  528. * This module is used through inheritance. It will make available the modifier
  529. * onlyOwner, which can be applied to your functions to restrict their use to
  530. * the owner.
  531. */
  532. abstract contract Ownable is Context {
  533. address private _owner;
  534.  
  535. event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  536.  
  537. /**
  538. * @dev Initializes the contract setting the deployer as the initial owner.
  539. */
  540. constructor() {
  541. _setOwner(_msgSender());
  542. }
  543.  
  544. /**
  545. * @dev Returns the address of the current owner.
  546. */
  547. function owner() public view virtual returns (address) {
  548. return _owner;
  549. }
  550.  
  551. /**
  552. * @dev Throws if called by any account other than the owner.
  553. */
  554. modifier onlyOwner() {
  555. require(owner() == _msgSender(), "Ownable: caller is not the owner");
  556. _;
  557. }
  558.  
  559. /**
  560. * @dev Leaves the contract without owner. It will not be possible to call
  561. * onlyOwner functions anymore. Can only be called by the current owner.
  562. *
  563. * NOTE: Renouncing ownership will leave the contract without an owner,
  564. * thereby removing any functionality that is only available to the owner.
  565. */
  566. function renounceOwnership() public virtual onlyOwner {
  567. _setOwner(address(0));
  568. }
  569.  
  570. /**
  571. * @dev Transfers ownership of the contract to a new account (`newOwner`).
  572. * Can only be called by the current owner.
  573. */
  574. function transferOwnership(address newOwner) public virtual onlyOwner {
  575. require(newOwner != address(0), "Ownable: new owner is the zero address");
  576. _setOwner(newOwner);
  577. }
  578.  
  579. function _setOwner(address newOwner) private {
  580. address oldOwner = _owner;
  581. _owner = newOwner;
  582. emit OwnershipTransferred(oldOwner, newOwner);
  583. }
  584. }
  585.  
  586.  
  587. // Dependency file: @openzeppelin/contracts/utils/math/SafeMath.sol
  588.  
  589.  
  590. // pragma solidity ^0.8.0;
  591.  
  592. // CAUTION
  593. // This version of SafeMath should only be used with Solidity 0.8 or later,
  594. // because it relies on the compiler's built in overflow checks.
  595.  
  596. /**
  597. * @dev Wrappers over Solidity's arithmetic operations.
  598. *
  599. * NOTE: SafeMath is no longer needed starting with Solidity 0.8. The compiler
  600. * now has built in overflow checking.
  601. */
  602. library SafeMath {
  603. /**
  604. * @dev Returns the addition of two unsigned integers, with an overflow flag.
  605. *
  606. * _Available since v3.4._
  607. */
  608. function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
  609. unchecked {
  610. uint256 c = a + b;
  611. if (c < a) return (false, 0);
  612. return (true, c);
  613. }
  614. }
  615.  
  616. /**
  617. * @dev Returns the substraction of two unsigned integers, with an overflow flag.
  618. *
  619. * _Available since v3.4._
  620. */
  621. function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
  622. unchecked {
  623. if (b > a) return (false, 0);
  624. return (true, a - b);
  625. }
  626. }
  627.  
  628. /**
  629. * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
  630. *
  631. * _Available since v3.4._
  632. */
  633. function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
  634. unchecked {
  635. // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
  636. // benefit is lost if 'b' is also tested.
  637. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
  638. if (a == 0) return (true, 0);
  639. uint256 c = a * b;
  640. if (c / a != b) return (false, 0);
  641. return (true, c);
  642. }
  643. }
  644.  
  645. /**
  646. * @dev Returns the division of two unsigned integers, with a division by zero flag.
  647. *
  648. * _Available since v3.4._
  649. */
  650.  
  651. Tib74, [4/22/2022 6:56 PM]
  652. function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
  653. unchecked {
  654. if (b == 0) return (false, 0);
  655. return (true, a / b);
  656. }
  657. }
  658.  
  659. /**
  660. * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
  661. *
  662. * _Available since v3.4._
  663. */
  664. function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
  665. unchecked {
  666. if (b == 0) return (false, 0);
  667. return (true, a % b);
  668. }
  669. }
  670.  
  671. /**
  672. * @dev Returns the addition of two unsigned integers, reverting on
  673. * overflow.
  674. *
  675. * Counterpart to Solidity's + operator.
  676. *
  677. * Requirements:
  678. *
  679. * - Addition cannot overflow.
  680. */
  681. function add(uint256 a, uint256 b) internal pure returns (uint256) {
  682. return a + b;
  683. }
  684.  
  685. /**
  686. * @dev Returns the subtraction of two unsigned integers, reverting on
  687. * overflow (when the result is negative).
  688. *
  689. * Counterpart to Solidity's - operator.
  690. *
  691. * Requirements:
  692. *
  693. * - Subtraction cannot overflow.
  694. */
  695. function sub(uint256 a, uint256 b) internal pure returns (uint256) {
  696. return a - b;
  697. }
  698.  
  699. /**
  700. * @dev Returns the multiplication of two unsigned integers, reverting on
  701. * overflow.
  702. *
  703. * Counterpart to Solidity's * operator.
  704. *
  705. * Requirements:
  706. *
  707. * - Multiplication cannot overflow.
  708. */
  709. function mul(uint256 a, uint256 b) internal pure returns (uint256) {
  710. return a * b;
  711. }
  712.  
  713. /**
  714. * @dev Returns the integer division of two unsigned integers, reverting on
  715. * division by zero. The result is rounded towards zero.
  716. *
  717. * Counterpart to Solidity's / operator.
  718. *
  719. * Requirements:
  720. *
  721. * - The divisor cannot be zero.
  722. */
  723. function div(uint256 a, uint256 b) internal pure returns (uint256) {
  724. return a / b;
  725. }
  726.  
  727. /**
  728. * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
  729. * reverting when dividing by zero.
  730. *
  731. * Counterpart to Solidity's % operator. This function uses a revert
  732. * opcode (which leaves remaining gas untouched) while Solidity uses an
  733. * invalid opcode to revert (consuming all remaining gas).
  734. *
  735. * Requirements:
  736. *
  737. * - The divisor cannot be zero.
  738. */
  739. function mod(uint256 a, uint256 b) internal pure returns (uint256) {
  740. return a % b;
  741. }
  742.  
  743. /**
  744. * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
  745. * overflow (when the result is negative).
  746. *
  747. * CAUTION: This function is deprecated because it requires allocating memory for the error
  748. * message unnecessarily. For custom revert reasons use {trySub}.
  749. *
  750. * Counterpart to Solidity's - operator.
  751. *
  752. * Requirements:
  753. *
  754. * - Subtraction cannot overflow.
  755. */
  756. function sub(
  757. uint256 a,
  758. uint256 b,
  759. string memory errorMessage
  760. ) internal pure returns (uint256) {
  761. unchecked {
  762. require(b <= a, errorMessage);
  763. return a - b;
  764. }
  765. }
  766.  
  767. /**
  768. * @dev Returns the integer division of two unsigned integers, reverting with custom message on
  769. * division by zero. The result is rounded towards zero.
  770. *
  771. * Counterpart to Solidity's / operator. Note: this function uses a
  772. * revert opcode (which leaves remaining gas untouched) while Solidity
  773. * uses an invalid opcode to revert (consuming all remaining gas).
  774. *
  775. * Requirements:
  776. *
  777. * - The divisor cannot be zero.
  778. */
  779. function div(
  780. uint256 a,
  781. uint256 b,
  782. string memory errorMessage
  783. ) internal pure returns (uint256) {
  784. unchecked {
  785. require(b > 0, errorMessage);
  786. return a / b;
  787. }
  788. }
  789.  
  790. /**
  791. * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
  792. * reverting with custom message when dividing by zero.
  793. *
  794.  
  795. Tib74, [4/22/2022 6:56 PM]
  796. * CAUTION: This function is deprecated because it requires allocating memory for the error
  797. * message unnecessarily. For custom revert reasons use {tryMod}.
  798. *
  799. * Counterpart to Solidity's % operator. This function uses a revert
  800. * opcode (which leaves remaining gas untouched) while Solidity uses an
  801. * invalid opcode to revert (consuming all remaining gas).
  802. *
  803. * Requirements:
  804. *
  805. * - The divisor cannot be zero.
  806. */
  807. function mod(
  808. uint256 a,
  809. uint256 b,
  810. string memory errorMessage
  811. ) internal pure returns (uint256) {
  812. unchecked {
  813. require(b > 0, errorMessage);
  814. return a % b;
  815. }
  816. }
  817. }
  818.  
  819.  
  820. // Dependency file: @openzeppelin/contracts/proxy/Clones.sol
  821.  
  822.  
  823. // pragma solidity ^0.8.0;
  824.  
  825. /**
  826. * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
  827. * deploying minimal proxy contracts, also known as "clones".
  828. *
  829. * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
  830. * > a minimal bytecode implementation that delegates all calls to a known, fixed address.
  831. *
  832. * The library includes functions to deploy a proxy using either create (traditional deployment) or create2
  833. * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
  834. * deterministic method.
  835. *
  836. * _Available since v3.4._
  837. */
  838. library Clones {
  839. /**
  840. * @dev Deploys and returns the address of a clone that mimics the behaviour of implementation.
  841. *
  842. * This function uses the create opcode, which should never revert.
  843. */
  844. function clone(address implementation) internal returns (address instance) {
  845. assembly {
  846. let ptr := mload(0x40)
  847. mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
  848. mstore(add(ptr, 0x14), shl(0x60, implementation))
  849. mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
  850. instance := create(0, ptr, 0x37)
  851. }
  852. require(instance != address(0), "ERC1167: create failed");
  853. }
  854.  
  855. /**
  856. * @dev Deploys and returns the address of a clone that mimics the behaviour of implementation.
  857. *
  858. * This function uses the create2 opcode and a salt to deterministically deploy
  859. * the clone. Using the same implementation and salt multiple time will revert, since
  860. * the clones cannot be deployed twice at the same address.
  861. */
  862. function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
  863. assembly {
  864. let ptr := mload(0x40)
  865. mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
  866. mstore(add(ptr, 0x14), shl(0x60, implementation))
  867. mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
  868. instance := create2(0, ptr, 0x37, salt)
  869. }
  870. require(instance != address(0), "ERC1167: create2 failed");
  871. }
  872.  
  873. /**
  874. * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
  875. */
  876. function predictDeterministicAddress(
  877. address implementation,
  878. bytes32 salt,
  879. address deployer
  880. ) internal pure returns (address predicted) {
  881. assembly {
  882. let ptr := mload(0x40)
  883. mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
  884. mstore(add(ptr, 0x14), shl(0x60, implementation))
  885. mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)
  886. mstore(add(ptr, 0x38), shl(0x60, deployer))
  887. mstore(add(ptr, 0x4c), salt)
  888. mstore(add(ptr, 0x6c), keccak256(ptr, 0x37))
  889. predicted := keccak256(add(ptr, 0x37), 0x55)
  890. }
  891. }
  892.  
  893. /**
  894. * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
  895. */
  896. function predictDeterministicAddress(address implementation, bytes32 salt)
  897. internal
  898.  
  899. Tib74, [4/22/2022 6:56 PM]
  900. view
  901. returns (address predicted)
  902. {
  903. return predictDeterministicAddress(implementation, salt, address(this));
  904. }
  905. }
  906.  
  907.  
  908. // Dependency file: contracts/interfaces/IUniswapV2Factory.sol
  909.  
  910. // pragma solidity >=0.5.0;
  911.  
  912. interface IUniswapV2Factory {
  913. event PairCreated(
  914. address indexed token0,
  915. address indexed token1,
  916. address pair,
  917. uint256
  918. );
  919.  
  920. function feeTo() external view returns (address);
  921.  
  922. function feeToSetter() external view returns (address);
  923.  
  924. function getPair(address tokenA, address tokenB)
  925. external
  926. view
  927. returns (address pair);
  928.  
  929. function allPairs(uint256) external view returns (address pair);
  930.  
  931. function allPairsLength() external view returns (uint256);
  932.  
  933. function createPair(address tokenA, address tokenB)
  934. external
  935. returns (address pair);
  936.  
  937. function setFeeTo(address) external;
  938.  
  939. function setFeeToSetter(address) external;
  940. }
  941.  
  942.  
  943. // Dependency file: contracts/interfaces/IUniswapV2Router02.sol
  944.  
  945. // pragma solidity >=0.6.2;
  946.  
  947. interface IUniswapV2Router01 {
  948. function factory() external pure returns (address);
  949.  
  950. function WETH() external pure returns (address);
  951.  
  952. function addLiquidity(
  953. address tokenA,
  954. address tokenB,
  955. uint256 amountADesired,
  956. uint256 amountBDesired,
  957. uint256 amountAMin,
  958. uint256 amountBMin,
  959. address to,
  960. uint256 deadline
  961. )
  962. external
  963. returns (
  964. uint256 amountA,
  965. uint256 amountB,
  966. uint256 liquidity
  967. );
  968.  
  969. function addLiquidityETH(
  970. address token,
  971. uint256 amountTokenDesired,
  972. uint256 amountTokenMin,
  973. uint256 amountETHMin,
  974. address to,
  975. uint256 deadline
  976. )
  977. external
  978. payable
  979. returns (
  980. uint256 amountToken,
  981. uint256 amountETH,
  982. uint256 liquidity
  983. );
  984.  
  985. function removeLiquidity(
  986. address tokenA,
  987. address tokenB,
  988. uint256 liquidity,
  989. uint256 amountAMin,
  990. uint256 amountBMin,
  991. address to,
  992. uint256 deadline
  993. ) external returns (uint256 amountA, uint256 amountB);
  994.  
  995. function removeLiquidityETH(
  996. address token,
  997. uint256 liquidity,
  998. uint256 amountTokenMin,
  999. uint256 amountETHMin,
  1000. address to,
  1001. uint256 deadline
  1002. ) external returns (uint256 amountToken, uint256 amountETH);
  1003.  
  1004. function removeLiquidityWithPermit(
  1005. address tokenA,
  1006. address tokenB,
  1007. uint256 liquidity,
  1008. uint256 amountAMin,
  1009. uint256 amountBMin,
  1010. address to,
  1011. uint256 deadline,
  1012. bool approveMax,
  1013. uint8 v,
  1014. bytes32 r,
  1015. bytes32 s
  1016. ) external returns (uint256 amountA, uint256 amountB);
  1017.  
  1018. function removeLiquidityETHWithPermit(
  1019. address token,
  1020. uint256 liquidity,
  1021. uint256 amountTokenMin,
  1022. uint256 amountETHMin,
  1023. address to,
  1024. uint256 deadline,
  1025. bool approveMax,
  1026. uint8 v,
  1027. bytes32 r,
  1028. bytes32 s
  1029. ) external returns (uint256 amountToken, uint256 amountETH);
  1030.  
  1031. function swapExactTokensForTokens(
  1032. uint256 amountIn,
  1033. uint256 amountOutMin,
  1034. address[] calldata path,
  1035. address to,
  1036. uint256 deadline
  1037. ) external returns (uint256[] memory amounts);
  1038.  
  1039. function swapTokensForExactTokens(
  1040. uint256 amountOut,
  1041. uint256 amountInMax,
  1042. address[] calldata path,
  1043. address to,
  1044. uint256 deadline
  1045. ) external returns (uint256[] memory amounts);
  1046.  
  1047. function swapExactETHForTokens(
  1048. uint256 amountOutMin,
  1049. address[] calldata path,
  1050. address to,
  1051. uint256 deadline
  1052. ) external payable returns (uint256[] memory amounts);
  1053.  
  1054. function swapTokensForExactETH(
  1055. uint256 amountOut,
  1056. uint256 amountInMax,
  1057. address[] calldata path,
  1058. address to,
  1059. uint256 deadline
  1060. ) external returns (uint256[] memory amounts);
  1061.  
  1062. function swapExactTokensForETH(
  1063.  
  1064. Tib74, [4/22/2022 6:56 PM]
  1065. uint256 amountIn,
  1066. uint256 amountOutMin,
  1067. address[] calldata path,
  1068. address to,
  1069. uint256 deadline
  1070. ) external returns (uint256[] memory amounts);
  1071.  
  1072. function swapETHForExactTokens(
  1073. uint256 amountOut,
  1074. address[] calldata path,
  1075. address to,
  1076. uint256 deadline
  1077. ) external payable returns (uint256[] memory amounts);
  1078.  
  1079. function quote(
  1080. uint256 amountA,
  1081. uint256 reserveA,
  1082. uint256 reserveB
  1083. ) external pure returns (uint256 amountB);
  1084.  
  1085. function getAmountOut(
  1086. uint256 amountIn,
  1087. uint256 reserveIn,
  1088. uint256 reserveOut
  1089. ) external pure returns (uint256 amountOut);
  1090.  
  1091. function getAmountIn(
  1092. uint256 amountOut,
  1093. uint256 reserveIn,
  1094. uint256 reserveOut
  1095. ) external pure returns (uint256 amountIn);
  1096.  
  1097. function getAmountsOut(uint256 amountIn, address[] calldata path)
  1098. external
  1099. view
  1100. returns (uint256[] memory amounts);
  1101.  
  1102. function getAmountsIn(uint256 amountOut, address[] calldata path)
  1103. external
  1104. view
  1105. returns (uint256[] memory amounts);
  1106. }
  1107.  
  1108. interface IUniswapV2Router02 is IUniswapV2Router01 {
  1109. function removeLiquidityETHSupportingFeeOnTransferTokens(
  1110. address token,
  1111. uint256 liquidity,
  1112. uint256 amountTokenMin,
  1113. uint256 amountETHMin,
  1114. address to,
  1115. uint256 deadline
  1116. ) external returns (uint256 amountETH);
  1117.  
  1118. function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
  1119. address token,
  1120. uint256 liquidity,
  1121. uint256 amountTokenMin,
  1122. uint256 amountETHMin,
  1123. address to,
  1124. uint256 deadline,
  1125. bool approveMax,
  1126. uint8 v,
  1127. bytes32 r,
  1128. bytes32 s
  1129. ) external returns (uint256 amountETH);
  1130.  
  1131. function swapExactTokensForTokensSupportingFeeOnTransferTokens(
  1132. uint256 amountIn,
  1133. uint256 amountOutMin,
  1134. address[] calldata path,
  1135. address to,
  1136. uint256 deadline
  1137. ) external;
  1138.  
  1139. function swapExactETHForTokensSupportingFeeOnTransferTokens(
  1140. uint256 amountOutMin,
  1141. address[] calldata path,
  1142. address to,
  1143. uint256 deadline
  1144. ) external payable;
  1145.  
  1146. function swapExactTokensForETHSupportingFeeOnTransferTokens(
  1147. uint256 amountIn,
  1148. uint256 amountOutMin,
  1149. address[] calldata path,
  1150. address to,
  1151. uint256 deadline
  1152. ) external;
  1153. }
  1154.  
  1155.  
  1156. // Dependency file: @openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol
  1157.  
  1158.  
  1159. // pragma solidity ^0.8.0;
  1160.  
  1161. /**
  1162. * @dev Interface of the ERC20 standard as defined in the EIP.
  1163. */
  1164. interface IERC20Upgradeable {
  1165. /**
  1166. * @dev Returns the amount of tokens in existence.
  1167. */
  1168. function totalSupply() external view returns (uint256);
  1169.  
  1170. /**
  1171. * @dev Returns the amount of tokens owned by account.
  1172. */
  1173. function balanceOf(address account) external view returns (uint256);
  1174.  
  1175. /**
  1176. * @dev Moves amount tokens from the caller's account to recipient.
  1177. *
  1178. * Returns a boolean value indicating whether the operation succeeded.
  1179. *
  1180. * Emits a {Transfer} event.
  1181. */
  1182. function transfer(address recipient, uint256 amount) external returns (bool);
  1183.  
  1184. /**
  1185. * @dev Returns the remaining number of tokens that spender will be
  1186. * allowed to spend on behalf of owner through {transferFrom}. This is
  1187. * zero by default.
  1188. *
  1189. * This value changes when {approve} or {transferFrom} are called.
  1190. */
  1191. function allowance(address owner, address spender) external view returns (uint256);
  1192.  
  1193. /**
  1194. * @dev Sets amount as the allowance of spender over the caller's tokens.
  1195. *
  1196. * Returns a boolean value indicating whether the operation succeeded.
  1197. *
  1198. * IMPORTANT: Beware that changing an allowance with this method brings the risk
  1199. * that someone may use both the old and the new allowance by unfortunate
  1200. * transaction ordering. One possible solution to mitigate this race
  1201. * condition is to first reduce the spender's allowance to 0 and set the
  1202.  
  1203. Tib74, [4/22/2022 6:56 PM]
  1204. * desired value afterwards:
  1205. * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
  1206. *
  1207. * Emits an {Approval} event.
  1208. */
  1209. function approve(address spender, uint256 amount) external returns (bool);
  1210.  
  1211. /**
  1212. * @dev Moves amount tokens from sender to recipient using the
  1213. * allowance mechanism. amount is then deducted from the caller's
  1214. * allowance.
  1215. *
  1216. * Returns a boolean value indicating whether the operation succeeded.
  1217. *
  1218. * Emits a {Transfer} event.
  1219. */
  1220. function transferFrom(
  1221. address sender,
  1222. address recipient,
  1223. uint256 amount
  1224. ) external returns (bool);
  1225.  
  1226. /**
  1227. * @dev Emitted when value tokens are moved from one account (`from`) to
  1228. * another (`to`).
  1229. *
  1230. * Note that value may be zero.
  1231. */
  1232. event Transfer(address indexed from, address indexed to, uint256 value);
  1233.  
  1234. /**
  1235. * @dev Emitted when the allowance of a spender for an owner is set by
  1236. * a call to {approve}. value is the new allowance.
  1237. */
  1238. event Approval(address indexed owner, address indexed spender, uint256 value);
  1239. }
  1240.  
  1241.  
  1242. // Dependency file: @openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol
  1243.  
  1244.  
  1245. // pragma solidity ^0.8.0;
  1246.  
  1247. // import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
  1248.  
  1249. /**
  1250. * @dev Interface for the optional metadata functions from the ERC20 standard.
  1251. *
  1252. * _Available since v4.1._
  1253. */
  1254. interface IERC20MetadataUpgradeable is IERC20Upgradeable {
  1255. /**
  1256. * @dev Returns the name of the token.
  1257. */
  1258. function name() external view returns (string memory);
  1259.  
  1260. /**
  1261. * @dev Returns the symbol of the token.
  1262. */
  1263. function symbol() external view returns (string memory);
  1264.  
  1265. /**
  1266. * @dev Returns the decimals places of the token.
  1267. */
  1268. function decimals() external view returns (uint8);
  1269. }
  1270.  
  1271.  
  1272. // Dependency file: @openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
  1273.  
  1274.  
  1275. // pragma solidity ^0.8.0;
  1276.  
  1277. /**
  1278. * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
  1279. * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
  1280. * external initializer function, usually called initialize. It then becomes necessary to protect this initializer
  1281. * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
  1282. *
  1283. * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
  1284. * possible by providing the encoded function call as the _data argument to {ERC1967Proxy-constructor}.
  1285. *
  1286. * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
  1287. * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
  1288. */
  1289. abstract contract Initializable {
  1290. /**
  1291. * @dev Indicates that the contract has been initialized.
  1292. */
  1293. bool private _initialized;
  1294.  
  1295. /**
  1296. * @dev Indicates that the contract is in the process of being initialized.
  1297. */
  1298. bool private _initializing;
  1299.  
  1300. /**
  1301. * @dev Modifier to protect an initializer function from being invoked twice.
  1302. */
  1303. modifier initializer() {
  1304. require(_initializing || !_initialized, "Initializable: contract is already initialized");
  1305.  
  1306. bool isTopLevelCall = !_initializing;
  1307. if (isTopLevelCall) {
  1308. _initializing = true;
  1309. _initialized = true;
  1310. }
  1311.  
  1312. _;
  1313.  
  1314. if (isTopLevelCall) {
  1315. _initializing = false;
  1316. }
  1317. }
  1318. }
  1319.  
  1320.  
  1321. // Dependency file: @openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
  1322.  
  1323.  
  1324. // pragma solidity ^0.8.0;
  1325. // import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
  1326.  
  1327. /**
  1328. * @dev Provides information about the current execution context, including the
  1329. * sender of the transaction and its data. While these are generally available
  1330. * via msg.sender and msg.
  1331.  
  1332. Tib74, [4/22/2022 6:56 PM]
  1333. data, they should not be accessed in such a direct
  1334. * manner, since when dealing with meta-transactions the account sending and
  1335. * paying for execution may not be the actual sender (as far as an application
  1336. * is concerned).
  1337. *
  1338. * This contract is only required for intermediate, library-like contracts.
  1339. */
  1340. abstract contract ContextUpgradeable is Initializable {
  1341. function __Context_init() internal initializer {
  1342. __Context_init_unchained();
  1343. }
  1344.  
  1345. function __Context_init_unchained() internal initializer {
  1346. }
  1347. function _msgSender() internal view virtual returns (address) {
  1348. return msg.sender;
  1349. }
  1350.  
  1351. function _msgData() internal view virtual returns (bytes calldata) {
  1352. return msg.data;
  1353. }
  1354. uint256[50] private __gap;
  1355. }
  1356.  
  1357.  
  1358. // Dependency file: @openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol
  1359.  
  1360.  
  1361. // pragma solidity ^0.8.0;
  1362.  
  1363. // import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
  1364. // import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
  1365. // import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol";
  1366. // import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
  1367.  
  1368. /**
  1369. * @dev Implementation of the {IERC20} interface.
  1370. *
  1371. * This implementation is agnostic to the way tokens are created. This means
  1372. * that a supply mechanism has to be added in a derived contract using {_mint}.
  1373. * For a generic mechanism see {ERC20PresetMinterPauser}.
  1374. *
  1375. * TIP: For a detailed writeup see our guide
  1376. * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
  1377. * to implement supply mechanisms].
  1378. *
  1379. * We have followed general OpenZeppelin Contracts guidelines: functions revert
  1380. * instead returning false on failure. This behavior is nonetheless
  1381. * conventional and does not conflict with the expectations of ERC20
  1382. * applications.
  1383. *
  1384. * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
  1385. * This allows applications to reconstruct the allowance for all accounts just
  1386. * by listening to said events. Other implementations of the EIP may not emit
  1387. * these events, as it isn't required by the specification.
  1388. *
  1389. * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
  1390. * functions have been added to mitigate the well-known issues around setting
  1391. * allowances. See {IERC20-approve}.
  1392. */
  1393. contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {
  1394. mapping(address => uint256) private _balances;
  1395.  
  1396. mapping(address => mapping(address => uint256)) private _allowances;
  1397.  
  1398. uint256 private _totalSupply;
  1399.  
  1400. string private _name;
  1401. string private _symbol;
  1402.  
  1403. /**
  1404. * @dev Sets the values for {name} and {symbol}.
  1405. *
  1406. * The default value of {decimals} is 18. To select a different value for
  1407. * {decimals} you should overload it.
  1408. *
  1409. * All two of these values are immutable: they can only be set once during
  1410. * construction.
  1411. */
  1412. function __ERC20_init(string memory name_, string memory symbol_) internal initializer {
  1413. __Context_init_unchained();
  1414. __ERC20_init_unchained(name_, symbol_);
  1415. }
  1416.  
  1417. function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer {
  1418. _name = name_;
  1419. _symbol = symbol_;
  1420. }
  1421.  
  1422. /**
  1423. * @dev Returns the name of the token.
  1424. */
  1425. function name() public view virtual override returns (string memory) {
  1426. return _name;
  1427. }
  1428.  
  1429. /**
  1430. * @dev Returns the symbol of the token, usually a shorter version of the
  1431. * name.
  1432. */
  1433. function symbol() public view virtual override returns (string memory) {
  1434. return _symbol;
  1435. }
  1436.  
  1437. /**
  1438. * @dev Returns the number of decimals used to get its user representation.
  1439. * For example, if decimals equals 2, a balance of 505 tokens should
  1440. * be displayed to a user as 5.05 (`505 / 10 ** 2`).
  1441. *
  1442. * Tokens usually opt for a value of 18, imitating the relationship between
  1443. * Ether and Wei.
  1444.  
  1445. Tib74, [4/22/2022 6:56 PM]
  1446. This is the value {ERC20} uses, unless this function is
  1447. * overridden;
  1448. *
  1449. * NOTE: This information is only used for _display_ purposes: it in
  1450. * no way affects any of the arithmetic of the contract, including
  1451. * {IERC20-balanceOf} and {IERC20-transfer}.
  1452. */
  1453. function decimals() public view virtual override returns (uint8) {
  1454. return 18;
  1455. }
  1456.  
  1457. /**
  1458. * @dev See {IERC20-totalSupply}.
  1459. */
  1460. function totalSupply() public view virtual override returns (uint256) {
  1461. return _totalSupply;
  1462. }
  1463.  
  1464. /**
  1465. * @dev See {IERC20-balanceOf}.
  1466. */
  1467. function balanceOf(address account) public view virtual override returns (uint256) {
  1468. return _balances[account];
  1469. }
  1470.  
  1471. /**
  1472. * @dev See {IERC20-transfer}.
  1473. *
  1474. * Requirements:
  1475. *
  1476. * - recipient cannot be the zero address.
  1477. * - the caller must have a balance of at least amount.
  1478. */
  1479. function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
  1480. _transfer(_msgSender(), recipient, amount);
  1481. return true;
  1482. }
  1483.  
  1484. /**
  1485. * @dev See {IERC20-allowance}.
  1486. */
  1487. function allowance(address owner, address spender) public view virtual override returns (uint256) {
  1488. return _allowances[owner][spender];
  1489. }
  1490.  
  1491. /**
  1492. * @dev See {IERC20-approve}.
  1493. *
  1494. * Requirements:
  1495. *
  1496. * - spender cannot be the zero address.
  1497. */
  1498. function approve(address spender, uint256 amount) public virtual override returns (bool) {
  1499. _approve(_msgSender(), spender, amount);
  1500. return true;
  1501. }
  1502.  
  1503. /**
  1504. * @dev See {IERC20-transferFrom}.
  1505. *
  1506. * Emits an {Approval} event indicating the updated allowance. This is not
  1507. * required by the EIP. See the note at the beginning of {ERC20}.
  1508. *
  1509. * Requirements:
  1510. *
  1511. * - sender and recipient cannot be the zero address.
  1512. * - sender must have a balance of at least amount.
  1513. * - the caller must have allowance for ``sender``'s tokens of at least
  1514. * amount.
  1515. */
  1516. function transferFrom(
  1517. address sender,
  1518. address recipient,
  1519. uint256 amount
  1520. ) public virtual override returns (bool) {
  1521. _transfer(sender, recipient, amount);
  1522.  
  1523. uint256 currentAllowance = _allowances[sender][_msgSender()];
  1524. require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
  1525. unchecked {
  1526. _approve(sender, _msgSender(), currentAllowance - amount);
  1527. }
  1528.  
  1529. return true;
  1530. }
  1531.  
  1532. /**
  1533. * @dev Atomically increases the allowance granted to spender by the caller.
  1534. *
  1535. * This is an alternative to {approve} that can be used as a mitigation for
  1536. * problems described in {IERC20-approve}.
  1537. *
  1538. * Emits an {Approval} event indicating the updated allowance.
  1539. *
  1540. * Requirements:
  1541. *
  1542. * - spender cannot be the zero address.
  1543. */
  1544. function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
  1545. _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
  1546. return true;
  1547. }
  1548.  
  1549. /**
  1550. * @dev Atomically decreases the allowance granted to spender by the caller.
  1551. *
  1552. * This is an alternative to {approve} that can be used as a mitigation for
  1553. * problems described in {IERC20-approve}.
  1554. *
  1555. * Emits an {Approval} event indicating the updated allowance.
  1556. *
  1557. * Requirements:
  1558. *
  1559. * - spender cannot be the zero address.
  1560. * - spender must have allowance for the caller of at least
  1561. * subtractedValue.
  1562. */
  1563. function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
  1564. uint256 currentAllowance = _allowances[_msgSender()][spender];
  1565. require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
  1566. unchecked {
  1567. _approve(_msgSender(), spender, currentAllowance - subtractedValue);
  1568. }
  1569.  
  1570. return true;
  1571. }
  1572.  
  1573. /**
  1574.  
  1575. Tib74, [4/22/2022 6:56 PM]
  1576. * @dev Moves amount of tokens from sender to recipient.
  1577. *
  1578. * This internal function is equivalent to {transfer}, and can be used to
  1579. * e.g. implement automatic token fees, slashing mechanisms, etc.
  1580. *
  1581. * Emits a {Transfer} event.
  1582. *
  1583. * Requirements:
  1584. *
  1585. * - sender cannot be the zero address.
  1586. * - recipient cannot be the zero address.
  1587. * - sender must have a balance of at least amount.
  1588. */
  1589. function _transfer(
  1590. address sender,
  1591. address recipient,
  1592. uint256 amount
  1593. ) internal virtual {
  1594. require(sender != address(0), "ERC20: transfer from the zero address");
  1595. require(recipient != address(0), "ERC20: transfer to the zero address");
  1596.  
  1597. _beforeTokenTransfer(sender, recipient, amount);
  1598.  
  1599. uint256 senderBalance = _balances[sender];
  1600. require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
  1601. unchecked {
  1602. _balances[sender] = senderBalance - amount;
  1603. }
  1604. _balances[recipient] += amount;
  1605.  
  1606. emit Transfer(sender, recipient, amount);
  1607.  
  1608. _afterTokenTransfer(sender, recipient, amount);
  1609. }
  1610.  
  1611. /** @dev Creates amount tokens and assigns them to account, increasing
  1612. * the total supply.
  1613. *
  1614. * Emits a {Transfer} event with from set to the zero address.
  1615. *
  1616. * Requirements:
  1617. *
  1618. * - account cannot be the zero address.
  1619. */
  1620. function _mint(address account, uint256 amount) internal virtual {
  1621. require(account != address(0), "ERC20: mint to the zero address");
  1622.  
  1623. _beforeTokenTransfer(address(0), account, amount);
  1624.  
  1625. _totalSupply += amount;
  1626. _balances[account] += amount;
  1627. emit Transfer(address(0), account, amount);
  1628.  
  1629. _afterTokenTransfer(address(0), account, amount);
  1630. }
  1631.  
  1632. /**
  1633. * @dev Destroys amount tokens from account, reducing the
  1634. * total supply.
  1635. *
  1636. * Emits a {Transfer} event with to set to the zero address.
  1637. *
  1638. * Requirements:
  1639. *
  1640. * - account cannot be the zero address.
  1641. * - account must have at least amount tokens.
  1642. */
  1643. function _burn(address account, uint256 amount) internal virtual {
  1644. require(account != address(0), "ERC20: burn from the zero address");
  1645.  
  1646. _beforeTokenTransfer(account, address(0), amount);
  1647.  
  1648. uint256 accountBalance = _balances[account];
  1649. require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
  1650. unchecked {
  1651. _balances[account] = accountBalance - amount;
  1652. }
  1653. _totalSupply -= amount;
  1654.  
  1655. emit Transfer(account, address(0), amount);
  1656.  
  1657. _afterTokenTransfer(account, address(0), amount);
  1658. }
  1659.  
  1660. /**
  1661. * @dev Sets amount as the allowance of spender over the owner s tokens.
  1662. *
  1663. * This internal function is equivalent to approve, and can be used to
  1664. * e.g. set automatic allowances for certain subsystems, etc.
  1665. *
  1666. * Emits an {Approval} event.
  1667. *
  1668. * Requirements:
  1669. *
  1670. * - owner cannot be the zero address.
  1671. * - spender cannot be the zero address.
  1672. */
  1673. function _approve(
  1674. address owner,
  1675. address spender,
  1676. uint256 amount
  1677. ) internal virtual {
  1678. require(owner != address(0), "ERC20: approve from the zero address");
  1679. require(spender != address(0), "ERC20: approve to the zero address");
  1680.  
  1681. _allowances[owner][spender] = amount;
  1682. emit Approval(owner, spender, amount);
  1683. }
  1684.  
  1685. /**
  1686. * @dev Hook that is called before any transfer of tokens. This includes
  1687. * minting and burning.
  1688. *
  1689. * Calling conditions:
  1690. *
  1691. * - when from and to are both non-zero, amount of ``from``'s tokens
  1692. * will be transferred to to.
  1693. * - when from is zero, amount tokens will be minted for to.
  1694. * - when to is zero, amount of ``from``'s tokens will be burned.
  1695. * - from and to are never both zero.
  1696. *
  1697. * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
  1698. */
  1699. function _beforeTokenTransfer(
  1700.  
  1701. Tib74, [4/22/2022 6:56 PM]
  1702. address from,
  1703. address to,
  1704. uint256 amount
  1705. ) internal virtual {}
  1706.  
  1707. /**
  1708. * @dev Hook that is called after any transfer of tokens. This includes
  1709. * minting and burning.
  1710. *
  1711. * Calling conditions:
  1712. *
  1713. * - when from and to are both non-zero, amount of ``from``'s tokens
  1714. * has been transferred to to.
  1715. * - when from is zero, amount tokens have been minted for to.
  1716. * - when to is zero, amount of ``from``'s tokens have been burned.
  1717. * - from and to are never both zero.
  1718. *
  1719. * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
  1720. */
  1721. function _afterTokenTransfer(
  1722. address from,
  1723. address to,
  1724. uint256 amount
  1725. ) internal virtual {}
  1726. uint256[45] private __gap;
  1727. }
  1728.  
  1729.  
  1730. // Dependency file: @openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol
  1731.  
  1732.  
  1733. // pragma solidity ^0.8.0;
  1734.  
  1735. // import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol";
  1736. // import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
  1737.  
  1738. /**
  1739. * @dev Contract module which provides a basic access control mechanism, where
  1740. * there is an account (an owner) that can be granted exclusive access to
  1741. * specific functions.
  1742. *
  1743. * By default, the owner account will be the one that deploys the contract. This
  1744. * can later be changed with {transferOwnership}.
  1745. *
  1746. * This module is used through inheritance. It will make available the modifier
  1747. * onlyOwner, which can be applied to your functions to restrict their use to
  1748. * the owner.
  1749. */
  1750. abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
  1751. address private _owner;
  1752.  
  1753. event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  1754.  
  1755. /**
  1756. * @dev Initializes the contract setting the deployer as the initial owner.
  1757. */
  1758. function __Ownable_init() internal initializer {
  1759. __Context_init_unchained();
  1760. __Ownable_init_unchained();
  1761. }
  1762.  
  1763. function __Ownable_init_unchained() internal initializer {
  1764. _setOwner(_msgSender());
  1765. }
  1766.  
  1767. /**
  1768. * @dev Returns the address of the current owner.
  1769. */
  1770. function owner() public view virtual returns (address) {
  1771. return _owner;
  1772. }
  1773.  
  1774. /**
  1775. * @dev Throws if called by any account other than the owner.
  1776. */
  1777. modifier onlyOwner() {
  1778. require(owner() == _msgSender(), "Ownable: caller is not the owner");
  1779. _;
  1780. }
  1781.  
  1782. /**
  1783. * @dev Leaves the contract without owner. It will not be possible to call
  1784. * onlyOwner functions anymore. Can only be called by the current owner.
  1785. *
  1786. * NOTE: Renouncing ownership will leave the contract without an owner,
  1787. * thereby removing any functionality that is only available to the owner.
  1788. */
  1789. function renounceOwnership() public virtual onlyOwner {
  1790. _setOwner(address(0));
  1791. }
  1792.  
  1793. /**
  1794. * @dev Transfers ownership of the contract to a new account (`newOwner`).
  1795. * Can only be called by the current owner.
  1796. */
  1797. function transferOwnership(address newOwner) public virtual onlyOwner {
  1798. require(newOwner != address(0), "Ownable: new owner is the zero address");
  1799. _setOwner(newOwner);
  1800. }
  1801.  
  1802. function _setOwner(address newOwner) private {
  1803. address oldOwner = _owner;
  1804. _owner = newOwner;
  1805. emit OwnershipTransferred(oldOwner, newOwner);
  1806. }
  1807. uint256[49] private __gap;
  1808. }
  1809.  
  1810.  
  1811. // Dependency file: contracts/interfaces/IUniswapV2Pair.sol
  1812.  
  1813. // pragma solidity >=0.5.0;
  1814.  
  1815. interface IUniswapV2Pair {
  1816. event Approval(address indexed owner, address indexed spender, uint value);
  1817. event Transfer(address indexed from, address indexed to, uint value);
  1818.  
  1819. function name() external pure returns (string memory);
  1820. function symbol() external pure returns (string memory);
  1821. function decimals() external pure returns (uint8);
  1822. function totalSupply() external view returns (uint);
  1823. function balanceOf(address owner) external view returns (uint);
  1824.  
  1825. Tib74, [4/22/2022 6:56 PM]
  1826. function allowance(address owner, address spender) external view returns (uint);
  1827.  
  1828. function approve(address spender, uint value) external returns (bool);
  1829. function transfer(address to, uint value) external returns (bool);
  1830. function transferFrom(address from, address to, uint value) external returns (bool);
  1831.  
  1832. function DOMAIN_SEPARATOR() external view returns (bytes32);
  1833. function PERMIT_TYPEHASH() external pure returns (bytes32);
  1834. function nonces(address owner) external view returns (uint);
  1835.  
  1836. function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
  1837.  
  1838. event Mint(address indexed sender, uint amount0, uint amount1);
  1839. event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
  1840. event Swap(
  1841. address indexed sender,
  1842. uint amount0In,
  1843. uint amount1In,
  1844. uint amount0Out,
  1845. uint amount1Out,
  1846. address indexed to
  1847. );
  1848. event Sync(uint112 reserve0, uint112 reserve1);
  1849.  
  1850. function MINIMUM_LIQUIDITY() external pure returns (uint);
  1851. function factory() external view returns (address);
  1852. function token0() external view returns (address);
  1853. function token1() external view returns (address);
  1854. function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
  1855. function price0CumulativeLast() external view returns (uint);
  1856. function price1CumulativeLast() external view returns (uint);
  1857. function kLast() external view returns (uint);
  1858.  
  1859. function mint(address to) external returns (uint liquidity);
  1860. function burn(address to) external returns (uint amount0, uint amount1);
  1861. function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
  1862. function skim(address to) external;
  1863. function sync() external;
  1864.  
  1865. function initialize(address, address) external;
  1866. }
  1867.  
  1868. // Dependency file: contracts/libs/SafeMathInt.sol
  1869.  
  1870. // pragma solidity =0.8.4;
  1871.  
  1872. /**
  1873. * @title SafeMathInt
  1874. * @dev Math operations for int256 with overflow safety checks.
  1875. */
  1876. library SafeMathInt {
  1877. int256 private constant MIN_INT256 = int256(1) << 255;
  1878. int256 private constant MAX_INT256 = ~(int256(1) << 255);
  1879.  
  1880. /**
  1881. * @dev Multiplies two int256 variables and fails on overflow.
  1882. */
  1883. function mul(int256 a, int256 b) internal pure returns (int256) {
  1884. int256 c = a * b;
  1885.  
  1886. // Detect overflow when multiplying MIN_INT256 with -1
  1887. require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256));
  1888. require((b == 0) || (c / b == a));
  1889. return c;
  1890. }
  1891.  
  1892. /**
  1893. * @dev Division of two int256 variables and fails on overflow.
  1894. */
  1895. function div(int256 a, int256 b) internal pure returns (int256) {
  1896. // Prevent overflow when dividing MIN_INT256 by -1
  1897. require(b != -1 || a != MIN_INT256);
  1898.  
  1899. // Solidity already throws when dividing by 0.
  1900. return a / b;
  1901. }
  1902.  
  1903. /**
  1904. * @dev Subtracts two int256 variables and fails on overflow.
  1905. */
  1906. function sub(int256 a, int256 b) internal pure returns (int256) {
  1907. int256 c = a - b;
  1908. require((b >= 0 && c <= a) || (b < 0 && c > a));
  1909. return c;
  1910. }
  1911.  
  1912. /**
  1913. * @dev Adds two int256 variables and fails on overflow.
  1914. */
  1915. function add(int256 a, int256 b) internal pure returns (int256) {
  1916. int256 c = a + b;
  1917. require((b >= 0 && c >= a) || (b < 0 && c < a));
  1918. return c;
  1919. }
  1920.  
  1921. /**
  1922. * @dev Converts to absolute value, and fails on overflow.
  1923. */
  1924. function abs(int256 a) internal pure returns (int256) {
  1925. require(a != MIN_INT256);
  1926. return a < 0 ? -a : a;
  1927. }
  1928.  
  1929. function toUint256Safe(int256 a) internal pure returns (uint256) {
  1930. require(a >= 0);
  1931. return uint256(a);
  1932. }
  1933. }
  1934.  
  1935.  
  1936. // Dependency file: contracts/libs/SafeMathUint.sol
  1937.  
  1938. // pragma solidity =0.8.4;
  1939.  
  1940. /**
  1941. * @title SafeMathUint
  1942. * @dev Math operations with safety checks that revert on error
  1943. */
  1944. library SafeMathUint {
  1945. function toInt256Safe(uint256 a) internal pure returns (int256) {
  1946.  
  1947. Tib74, [4/22/2022 6:56 PM]
  1948. int256 b = int256(a);
  1949. require(b >= 0);
  1950. return b;
  1951. }
  1952. }
  1953.  
  1954.  
  1955. // Dependency file: contracts/baby/IterableMapping.sol
  1956.  
  1957. // pragma solidity =0.8.4;
  1958.  
  1959. library IterableMapping {
  1960. // Iterable mapping from address to uint;
  1961. struct Map {
  1962. address[] keys;
  1963. mapping(address => uint256) values;
  1964. mapping(address => uint256) indexOf;
  1965. mapping(address => bool) inserted;
  1966. }
  1967.  
  1968. function get(Map storage map, address key) public view returns (uint256) {
  1969. return map.values[key];
  1970. }
  1971.  
  1972. function getIndexOfKey(Map storage map, address key)
  1973. public
  1974. view
  1975. returns (int256)
  1976. {
  1977. if (!map.inserted[key]) {
  1978. return -1;
  1979. }
  1980. return int256(map.indexOf[key]);
  1981. }
  1982.  
  1983. function getKeyAtIndex(Map storage map, uint256 index)
  1984. public
  1985. view
  1986. returns (address)
  1987. {
  1988. return map.keys[index];
  1989. }
  1990.  
  1991. function size(Map storage map) public view returns (uint256) {
  1992. return map.keys.length;
  1993. }
  1994.  
  1995. function set(
  1996. Map storage map,
  1997. address key,
  1998. uint256 val
  1999. ) public {
  2000. if (map.inserted[key]) {
  2001. map.values[key] = val;
  2002. } else {
  2003. map.inserted[key] = true;
  2004. map.values[key] = val;
  2005. map.indexOf[key] = map.keys.length;
  2006. map.keys.push(key);
  2007. }
  2008. }
  2009.  
  2010. function remove(Map storage map, address key) public {
  2011. if (!map.inserted[key]) {
  2012. return;
  2013. }
  2014.  
  2015. delete map.inserted[key];
  2016. delete map.values[key];
  2017.  
  2018. uint256 index = map.indexOf[key];
  2019. uint256 lastIndex = map.keys.length - 1;
  2020. address lastKey = map.keys[lastIndex];
  2021.  
  2022. map.indexOf[lastKey] = index;
  2023. delete map.indexOf[key];
  2024.  
  2025. map.keys[index] = lastKey;
  2026. map.keys.pop();
  2027. }
  2028. }
  2029.  
  2030.  
  2031. // Dependency file: contracts/baby/BabyTokenDividendTracker.sol
  2032.  
  2033. // pragma solidity =0.8.4;
  2034.  
  2035. // import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
  2036. // import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
  2037. // import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
  2038. // import "@openzeppelin/contracts/access/Ownable.sol";
  2039. // import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
  2040. // import "@openzeppelin/contracts/utils/math/SafeMath.sol";
  2041. // import "contracts/interfaces/IUniswapV2Factory.sol";
  2042. // import "contracts/interfaces/IUniswapV2Router02.sol";
  2043. // import "contracts/interfaces/IUniswapV2Pair.sol";
  2044. // import "contracts/libs/SafeMathInt.sol";
  2045. // import "contracts/libs/SafeMathUint.sol";
  2046. // import "contracts/baby/IterableMapping.sol";
  2047.  
  2048. /// @title Dividend-Paying Token Interface
  2049. /// @author Roger Wu (https://github.com/roger-wu)
  2050. /// @dev An interface for a dividend-paying token contract.
  2051. interface DividendPayingTokenInterface {
  2052. /// @notice View the amount of dividend in wei that an address can withdraw.
  2053. /// @param _owner The address of a token holder.
  2054. /// @return The amount of dividend in wei that _owner can withdraw.
  2055. function dividendOf(address _owner) external view returns (uint256);
  2056.  
  2057. /// @notice Withdraws the ether distributed to the sender.
  2058. /// @dev SHOULD transfer dividendOf(msg.sender) wei to msg.sender, and dividendOf(msg.sender) SHOULD be 0 after the transfer.
  2059. /// MUST emit a DividendWithdrawn event if the amount of ether transferred is greater than 0.
  2060. function withdrawDividend() external;
  2061.  
  2062. /// @dev This event MUST emit when ether is distributed to token holders.
  2063. /// @param from The address which sends ether to this contract.
  2064. /// @param weiAmount The amount of distributed ether in wei.
  2065. event DividendsDistributed(address indexed from, uint256 weiAmount);
  2066.  
  2067. /// @dev This event MUST emit when an address withdraws their dividend.
  2068. /// @param to The address which withdraws ether from this contract.
  2069. /// @param weiAmount The amount of withdrawn ether in wei.
  2070. event DividendWithdrawn(address indexed to, uint256 weiAmount);
  2071. }
  2072.  
  2073. /// @title Dividend-Paying Token Optional Interface
  2074.  
  2075. Tib74, [4/22/2022 6:56 PM]
  2076. /// @author Roger Wu (https://github.com/roger-wu)
  2077. /// @dev OPTIONAL functions for a dividend-paying token contract.
  2078. interface DividendPayingTokenOptionalInterface {
  2079. /// @notice View the amount of dividend in wei that an address can withdraw.
  2080. /// @param _owner The address of a token holder.
  2081. /// @return The amount of dividend in wei that _owner can withdraw.
  2082. function withdrawableDividendOf(address _owner)
  2083. external
  2084. view
  2085. returns (uint256);
  2086.  
  2087. /// @notice View the amount of dividend in wei that an address has withdrawn.
  2088. /// @param _owner The address of a token holder.
  2089. /// @return The amount of dividend in wei that _owner has withdrawn.
  2090. function withdrawnDividendOf(address _owner)
  2091. external
  2092. view
  2093. returns (uint256);
  2094.  
  2095. /// @notice View the amount of dividend in wei that an address has earned in total.
  2096. /// @dev accumulativeDividendOf(_owner) = withdrawableDividendOf(_owner) + withdrawnDividendOf(_owner)
  2097. /// @param _owner The address of a token holder.
  2098. /// @return The amount of dividend in wei that _owner has earned in total.
  2099. function accumulativeDividendOf(address _owner)
  2100. external
  2101. view
  2102. returns (uint256);
  2103. }
  2104.  
  2105. /// @title Dividend-Paying Token
  2106. /// @author Roger Wu (https://github.com/roger-wu)
  2107. /// @dev A mintable ERC20 token that allows anyone to pay and distribute ether
  2108. /// to token holders as dividends and allows token holders to withdraw their dividends.
  2109. /// Reference: the source code of PoWH3D: https://etherscan.io/address/0xB3775fB83F7D12A36E0475aBdD1FCA35c091efBe#code
  2110. contract DividendPayingToken is
  2111. ERC20Upgradeable,
  2112. OwnableUpgradeable,
  2113. DividendPayingTokenInterface,
  2114. DividendPayingTokenOptionalInterface
  2115. {
  2116. using SafeMath for uint256;
  2117. using SafeMathUint for uint256;
  2118. using SafeMathInt for int256;
  2119.  
  2120. address public rewardToken;
  2121.  
  2122. // With magnitude, we can properly distribute dividends even if the amount of received ether is small.
  2123. // For more discussion about choosing the value of magnitude,
  2124. // see https://github.com/ethereum/EIPs/issues/1726#issuecomment-472352728
  2125. uint256 internal constant magnitude = 2**128;
  2126.  
  2127. uint256 internal magnifiedDividendPerShare;
  2128.  
  2129. // About dividendCorrection:
  2130. // If the token balance of a _user is never changed, the dividend of _user can be computed with:
  2131. // dividendOf(_user) = dividendPerShare * balanceOf(_user).
  2132. // When balanceOf(_user) is changed (via minting/burning/transferring tokens),
  2133. // dividendOf(_user) should not be changed,
  2134. // but the computed value of dividendPerShare * balanceOf(_user) is changed.
  2135. // To keep the dividendOf(_user) unchanged, we add a correction term:
  2136. // dividendOf(_user) = dividendPerShare * balanceOf(_user) + dividendCorrectionOf(_user),
  2137. // where dividendCorrectionOf(_user) is updated whenever balanceOf(_user) is changed:
  2138. // dividendCorrectionOf(_user) = dividendPerShare * (old balanceOf(_user)) - (new balanceOf(_user)).
  2139. // So now dividendOf(_user) returns the same value before and after balanceOf(_user) is changed.
  2140. mapping(address => int256) internal magnifiedDividendCorrections;
  2141. mapping(address => uint256) internal withdrawnDividends;
  2142.  
  2143. uint256 public totalDividendsDistributed;
  2144.  
  2145. function __DividendPayingToken_init(
  2146. address _rewardToken,
  2147. string memory _name,
  2148. string memory _symbol
  2149. ) internal initializer {
  2150. __Ownable_init();
  2151. __ERC20_init(_name, _symbol);
  2152. rewardToken = _rewardToken;
  2153. }
  2154.  
  2155. function distributeCAKEDividends(uint256 amount) public onlyOwner {
  2156. require(totalSupply() > 0);
  2157.  
  2158. if (amount > 0) {
  2159. magnifiedDividendPerShare = magnifiedDividendPerShare.add(
  2160. (amount).mul(magnitude) / totalSupply()
  2161. );
  2162. emit DividendsDistributed(msg.sender, amount);
  2163.  
  2164. totalDividendsDistributed = totalDividendsDistributed.add(amount);
  2165. }
  2166. }
  2167.  
  2168. /// @notice Withdraws the ether distributed to the sender.
  2169.  
  2170. Tib74, [4/22/2022 6:56 PM]
  2171. /// @dev It emits a DividendWithdrawn event if the amount of withdrawn ether is greater than 0.
  2172. function withdrawDividend() public virtual override {
  2173. _withdrawDividendOfUser(payable(msg.sender));
  2174. }
  2175.  
  2176. /// @notice Withdraws the ether distributed to the sender.
  2177. /// @dev It emits a DividendWithdrawn event if the amount of withdrawn ether is greater than 0.
  2178. function _withdrawDividendOfUser(address payable user)
  2179. internal
  2180. returns (uint256)
  2181. {
  2182. uint256 _withdrawableDividend = withdrawableDividendOf(user);
  2183. if (_withdrawableDividend > 0) {
  2184. withdrawnDividends[user] = withdrawnDividends[user].add(
  2185. _withdrawableDividend
  2186. );
  2187. emit DividendWithdrawn(user, _withdrawableDividend);
  2188. bool success = IERC20(rewardToken).transfer(
  2189. user,
  2190. _withdrawableDividend
  2191. );
  2192.  
  2193. if (!success) {
  2194. withdrawnDividends[user] = withdrawnDividends[user].sub(
  2195. _withdrawableDividend
  2196. );
  2197. return 0;
  2198. }
  2199.  
  2200. return _withdrawableDividend;
  2201. }
  2202.  
  2203. return 0;
  2204. }
  2205.  
  2206. /// @notice View the amount of dividend in wei that an address can withdraw.
  2207. /// @param _owner The address of a token holder.
  2208. /// @return The amount of dividend in wei that _owner can withdraw.
  2209. function dividendOf(address _owner) public view override returns (uint256) {
  2210. return withdrawableDividendOf(_owner);
  2211. }
  2212.  
  2213. /// @notice View the amount of dividend in wei that an address can withdraw.
  2214. /// @param _owner The address of a token holder.
  2215. /// @return The amount of dividend in wei that _owner can withdraw.
  2216. function withdrawableDividendOf(address _owner)
  2217. public
  2218. view
  2219. override
  2220. returns (uint256)
  2221. {
  2222. return accumulativeDividendOf(_owner).sub(withdrawnDividends[_owner]);
  2223. }
  2224.  
  2225. /// @notice View the amount of dividend in wei that an address has withdrawn.
  2226. /// @param _owner The address of a token holder.
  2227. /// @return The amount of dividend in wei that _owner has withdrawn.
  2228. function withdrawnDividendOf(address _owner)
  2229. public
  2230. view
  2231. override
  2232. returns (uint256)
  2233. {
  2234. return withdrawnDividends[_owner];
  2235. }
  2236.  
  2237. /// @notice View the amount of dividend in wei that an address has earned in total.
  2238. /// @dev accumulativeDividendOf(_owner) = withdrawableDividendOf(_owner) + withdrawnDividendOf(_owner)
  2239. /// = (magnifiedDividendPerShare * balanceOf(_owner) + magnifiedDividendCorrections[_owner]) / magnitude
  2240. /// @param _owner The address of a token holder.
  2241. /// @return The amount of dividend in wei that _owner has earned in total.
  2242. function accumulativeDividendOf(address _owner)
  2243. public
  2244. view
  2245. override
  2246. returns (uint256)
  2247. {
  2248. return
  2249. magnifiedDividendPerShare
  2250. .mul(balanceOf(_owner))
  2251. .toInt256Safe()
  2252. .add(magnifiedDividendCorrections[_owner])
  2253. .toUint256Safe() / magnitude;
  2254. }
  2255.  
  2256. /// @dev Internal function that transfer tokens from one address to another.
  2257. /// Update magnifiedDividendCorrections to keep dividends unchanged.
  2258. /// @param from The address to transfer from.
  2259. /// @param to The address to transfer to.
  2260. /// @param value The amount to be transferred.
  2261. function _transfer(
  2262. address from,
  2263. address to,
  2264. uint256 value
  2265. ) internal virtual override {
  2266. require(false);
  2267.  
  2268. int256 _magCorrection = magnifiedDividendPerShare
  2269. .mul(value)
  2270. .toInt256Safe();
  2271. magnifiedDividendCorrections[from] = magnifiedDividendCorrections[from]
  2272. .add(_magCorrection);
  2273. magnifiedDividendCorrections[to] = magnifiedDividendCorrections[to].sub(
  2274. _magCorrection
  2275. );
  2276. }
  2277.  
  2278. /// @dev Internal function that mints tokens to an account.
  2279. /// Update magnifiedDividendCorrections to keep dividends unchanged.
  2280.  
  2281. Tib74, [4/22/2022 6:56 PM]
  2282. /// @param account The account that will receive the created tokens.
  2283. /// @param value The amount that will be created.
  2284. function _mint(address account, uint256 value) internal override {
  2285. super._mint(account, value);
  2286.  
  2287. magnifiedDividendCorrections[account] = magnifiedDividendCorrections[
  2288. account
  2289. ].sub((magnifiedDividendPerShare.mul(value)).toInt256Safe());
  2290. }
  2291.  
  2292. /// @dev Internal function that burns an amount of the token of a given account.
  2293. /// Update magnifiedDividendCorrections to keep dividends unchanged.
  2294. /// @param account The account whose tokens will be burnt.
  2295. /// @param value The amount that will be burnt.
  2296. function _burn(address account, uint256 value) internal override {
  2297. super._burn(account, value);
  2298.  
  2299. magnifiedDividendCorrections[account] = magnifiedDividendCorrections[
  2300. account
  2301. ].add((magnifiedDividendPerShare.mul(value)).toInt256Safe());
  2302. }
  2303.  
  2304. function _setBalance(address account, uint256 newBalance) internal {
  2305. uint256 currentBalance = balanceOf(account);
  2306.  
  2307. if (newBalance > currentBalance) {
  2308. uint256 mintAmount = newBalance.sub(currentBalance);
  2309. _mint(account, mintAmount);
  2310. } else if (newBalance < currentBalance) {
  2311. uint256 burnAmount = currentBalance.sub(newBalance);
  2312. _burn(account, burnAmount);
  2313. }
  2314. }
  2315. }
  2316.  
  2317. contract BABYTOKENDividendTracker is OwnableUpgradeable, DividendPayingToken {
  2318. using SafeMath for uint256;
  2319. using SafeMathInt for int256;
  2320. using IterableMapping for IterableMapping.Map;
  2321.  
  2322. IterableMapping.Map private tokenHoldersMap;
  2323. uint256 public lastProcessedIndex;
  2324.  
  2325. mapping(address => bool) public excludedFromDividends;
  2326.  
  2327. mapping(address => uint256) public lastClaimTimes;
  2328.  
  2329. uint256 public claimWait;
  2330. uint256 public minimumTokenBalanceForDividends;
  2331.  
  2332. event ExcludeFromDividends(address indexed account);
  2333. event ClaimWaitUpdated(uint256 indexed newValue, uint256 indexed oldValue);
  2334.  
  2335. event Claim(
  2336. address indexed account,
  2337. uint256 amount,
  2338. bool indexed automatic
  2339. );
  2340.  
  2341. function initialize(
  2342. address rewardToken_,
  2343. uint256 minimumTokenBalanceForDividends_
  2344. ) external initializer {
  2345. DividendPayingToken.__DividendPayingToken_init(
  2346. rewardToken_,
  2347. "DIVIDEND_TRACKER",
  2348. "DIVIDEND_TRACKER"
  2349. );
  2350. claimWait = 3600;
  2351. minimumTokenBalanceForDividends = minimumTokenBalanceForDividends_;
  2352. }
  2353.  
  2354. function _transfer(
  2355. address,
  2356. address,
  2357. uint256
  2358. ) internal pure override {
  2359. require(false, "Dividend_Tracker: No transfers allowed");
  2360. }
  2361.  
  2362. function withdrawDividend() public pure override {
  2363. require(
  2364. false,
  2365. "Dividend_Tracker: withdrawDividend disabled. Use the 'claim' function on the main BABYTOKEN contract."
  2366. );
  2367. }
  2368.  
  2369. function excludeFromDividends(address account) external onlyOwner {
  2370. require(!excludedFromDividends[account]);
  2371. excludedFromDividends[account] = true;
  2372.  
  2373. _setBalance(account, 0);
  2374. tokenHoldersMap.remove(account);
  2375.  
  2376. emit ExcludeFromDividends(account);
  2377. }
  2378.  
  2379. function isExcludedFromDividends(address account)
  2380. public
  2381. view
  2382. returns (bool)
  2383. {
  2384. return excludedFromDividends[account];
  2385. }
  2386.  
  2387. function updateClaimWait(uint256 newClaimWait) external onlyOwner {
  2388. require(
  2389. newClaimWait >= 3600 && newClaimWait <= 86400,
  2390. "Dividend_Tracker: claimWait must be updated to between 1 and 24 hours"
  2391. );
  2392. require(
  2393. newClaimWait != claimWait,
  2394. "Dividend_Tracker: Cannot update claimWait to same value"
  2395. );
  2396. emit ClaimWaitUpdated(newClaimWait, claimWait);
  2397. claimWait = newClaimWait;
  2398. }
  2399.  
  2400. function updateMinimumTokenBalanceForDividends(uint256 amount)
  2401. external
  2402. onlyOwner
  2403. {
  2404. minimumTokenBalanceForDividends = amount;
  2405. }
  2406.  
  2407. Tib74, [4/22/2022 6:56 PM]
  2408. function getLastProcessedIndex() external view returns (uint256) {
  2409. return lastProcessedIndex;
  2410. }
  2411.  
  2412. function getNumberOfTokenHolders() external view returns (uint256) {
  2413. return tokenHoldersMap.keys.length;
  2414. }
  2415.  
  2416. function getAccount(address _account)
  2417. public
  2418. view
  2419. returns (
  2420. address account,
  2421. int256 index,
  2422. int256 iterationsUntilProcessed,
  2423. uint256 withdrawableDividends,
  2424. uint256 totalDividends,
  2425. uint256 lastClaimTime,
  2426. uint256 nextClaimTime,
  2427. uint256 secondsUntilAutoClaimAvailable
  2428. )
  2429. {
  2430. account = _account;
  2431.  
  2432. index = tokenHoldersMap.getIndexOfKey(account);
  2433.  
  2434. iterationsUntilProcessed = -1;
  2435.  
  2436. if (index >= 0) {
  2437. if (uint256(index) > lastProcessedIndex) {
  2438. iterationsUntilProcessed = index.sub(
  2439. int256(lastProcessedIndex)
  2440. );
  2441. } else {
  2442. uint256 processesUntilEndOfArray = tokenHoldersMap.keys.length >
  2443. lastProcessedIndex
  2444. ? tokenHoldersMap.keys.length.sub(lastProcessedIndex)
  2445. : 0;
  2446.  
  2447. iterationsUntilProcessed = index.add(
  2448. int256(processesUntilEndOfArray)
  2449. );
  2450. }
  2451. }
  2452.  
  2453. withdrawableDividends = withdrawableDividendOf(account);
  2454. totalDividends = accumulativeDividendOf(account);
  2455.  
  2456. lastClaimTime = lastClaimTimes[account];
  2457.  
  2458. nextClaimTime = lastClaimTime > 0 ? lastClaimTime.add(claimWait) : 0;
  2459.  
  2460. secondsUntilAutoClaimAvailable = nextClaimTime > block.timestamp
  2461. ? nextClaimTime.sub(block.timestamp)
  2462. : 0;
  2463. }
  2464.  
  2465. function getAccountAtIndex(uint256 index)
  2466. public
  2467. view
  2468. returns (
  2469. address,
  2470. int256,
  2471. int256,
  2472. uint256,
  2473. uint256,
  2474. uint256,
  2475. uint256,
  2476. uint256
  2477. )
  2478. {
  2479. if (index >= tokenHoldersMap.size()) {
  2480. return (address(0), -1, -1, 0, 0, 0, 0, 0);
  2481. }
  2482.  
  2483. address account = tokenHoldersMap.getKeyAtIndex(index);
  2484.  
  2485. return getAccount(account);
  2486. }
  2487.  
  2488. function canAutoClaim(uint256 lastClaimTime) private view returns (bool) {
  2489. if (lastClaimTime > block.timestamp) {
  2490. return false;
  2491. }
  2492.  
  2493. return block.timestamp.sub(lastClaimTime) >= claimWait;
  2494. }
  2495.  
  2496. function setBalance(address payable account, uint256 newBalance)
  2497. external
  2498. onlyOwner
  2499. {
  2500. if (excludedFromDividends[account]) {
  2501. return;
  2502. }
  2503. if (newBalance >= minimumTokenBalanceForDividends) {
  2504. _setBalance(account, newBalance);
  2505. tokenHoldersMap.set(account, newBalance);
  2506. } else {
  2507. _setBalance(account, 0);
  2508. tokenHoldersMap.remove(account);
  2509. }
  2510. processAccount(account, true);
  2511. }
  2512.  
  2513. function process(uint256 gas)
  2514. public
  2515. returns (
  2516. uint256,
  2517. uint256,
  2518. uint256
  2519. )
  2520. {
  2521. uint256 numberOfTokenHolders = tokenHoldersMap.keys.length;
  2522.  
  2523. if (numberOfTokenHolders == 0) {
  2524. return (0, 0, lastProcessedIndex);
  2525. }
  2526.  
  2527. uint256 _lastProcessedIndex = lastProcessedIndex;
  2528.  
  2529. uint256 gasUsed = 0;
  2530.  
  2531. uint256 gasLeft = gasleft();
  2532.  
  2533. uint256 iterations = 0;
  2534. uint256 claims = 0;
  2535.  
  2536. while (gasUsed < gas && iterations < numberOfTokenHolders) {
  2537. _lastProcessedIndex++;
  2538.  
  2539. if (_lastProcessedIndex >= tokenHoldersMap.keys.length) {
  2540. _lastProcessedIndex = 0;
  2541. }
  2542.  
  2543. address account = tokenHoldersMap.keys[_lastProcessedIndex];
  2544.  
  2545. if (canAutoClaim(lastClaimTimes[account])) {
  2546. if (processAccount(payable(account), true)) {
  2547. claims++;
  2548. }
  2549. }
  2550.  
  2551. iterations++;
  2552.  
  2553. uint256 newGasLeft = gasleft();
  2554.  
  2555. if (gasLeft > newGasLeft) {
  2556.  
  2557.  
  2558. gasUsed = gasUsed.add(gasLeft.sub(newGasLeft));
  2559. }
  2560.  
  2561. gasLeft = newGasLeft;
  2562. }
  2563.  
  2564. lastProcessedIndex = _lastProcessedIndex;
  2565.  
  2566. return (iterations, claims, lastProcessedIndex);
  2567. }
  2568.  
  2569. function processAccount(address payable account, bool automatic)
  2570. public
  2571. onlyOwner
  2572. returns (bool)
  2573. {
  2574. uint256 amount = _withdrawDividendOfUser(account);
  2575.  
  2576. if (amount > 0) {
  2577. lastClaimTimes[account] = block.timestamp;
  2578. emit Claim(account, amount, automatic);
  2579. return true;
  2580. }
  2581.  
  2582. return false;
  2583. }
  2584. }
  2585.  
  2586.  
  2587. // Dependency file: contracts/BaseToken.sol
  2588.  
  2589. // pragma solidity =0.8.4;
  2590.  
  2591. enum TokenType {
  2592. standard,
  2593. antiBotStandard,
  2594. liquidityGenerator,
  2595. antiBotLiquidityGenerator,
  2596. baby,
  2597. antiBotBaby,
  2598. buybackBaby,
  2599. antiBotBuybackBaby
  2600. }
  2601.  
  2602. abstract contract BaseToken {
  2603. event TokenCreated(
  2604. address indexed owner,
  2605. address indexed token,
  2606. TokenType tokenType,
  2607. uint256 version
  2608. );
  2609. }
  2610.  
  2611.  
  2612. // Root file: contracts/baby/BabyToken.sol
  2613.  
  2614. pragma solidity =0.8.4;
  2615.  
  2616. // import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
  2617. // import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
  2618. // import "@openzeppelin/contracts/access/Ownable.sol";
  2619. // import "@openzeppelin/contracts/utils/math/SafeMath.sol";
  2620. // import "@openzeppelin/contracts/proxy/Clones.sol";
  2621. // import "contracts/interfaces/IUniswapV2Factory.sol";
  2622. // import "contracts/interfaces/IUniswapV2Router02.sol";
  2623. // import "contracts/baby/BabyTokenDividendTracker.sol";
  2624. // import "contracts/BaseToken.sol";
  2625.  
  2626. contract BABYTOKEN is ERC20, Ownable, BaseToken {
  2627. using SafeMath for uint256;
  2628.  
  2629. uint256 public constant VERSION = 1;
  2630.  
  2631. IUniswapV2Router02 public uniswapV2Router;
  2632. address public uniswapV2Pair;
  2633.  
  2634. bool private swapping;
  2635.  
  2636. BABYTOKENDividendTracker public dividendTracker;
  2637.  
  2638. address public rewardToken;
  2639.  
  2640. uint256 public swapTokensAtAmount;
  2641.  
  2642. uint256 public tokenRewardsFee;
  2643. uint256 public liquidityFee;
  2644. uint256 public marketingFee;
  2645. uint256 public totalFees;
  2646.  
  2647. address public _marketingWalletAddress;
  2648.  
  2649. uint256 public gasForProcessing;
  2650.  
  2651. // exlcude from fees and max transaction amount
  2652. mapping(address => bool) private _isExcludedFromFees;
  2653.  
  2654. // store addresses that a automatic market maker pairs. Any transfer *to* these addresses
  2655. // could be subject to a maximum transfer amount
  2656. mapping(address => bool) public automatedMarketMakerPairs;
  2657.  
  2658. event UpdateDividendTracker(
  2659. address indexed newAddress,
  2660. address indexed oldAddress
  2661. );
  2662.  
  2663. event UpdateUniswapV2Router(
  2664. address indexed newAddress,
  2665. address indexed oldAddress
  2666. );
  2667.  
  2668. event ExcludeFromFees(address indexed account, bool isExcluded);
  2669. event ExcludeMultipleAccountsFromFees(address[] accounts, bool isExcluded);
  2670.  
  2671. event SetAutomatedMarketMakerPair(address indexed pair, bool indexed value);
  2672.  
  2673. event LiquidityWalletUpdated(
  2674. address indexed newLiquidityWallet,
  2675. address indexed oldLiquidityWallet
  2676. );
  2677.  
  2678. event GasForProcessingUpdated(
  2679. uint256 indexed newValue,
  2680. uint256 indexed oldValue
  2681. );
  2682.  
  2683. event SwapAndLiquify(
  2684. uint256 tokensSwapped,
  2685. uint256 ethReceived,
  2686. uint256 tokensIntoLiqudity
  2687. );
  2688.  
  2689. event SendDividends(uint256 tokensSwapped, uint256 amount);
  2690.  
  2691. event ProcessedDividendTracker(
  2692. uint256 iterations,
  2693. uint256 claims,
  2694. uint256 lastProcessedIndex,
  2695. bool indexed automatic,
  2696. uint256 gas,
  2697. address indexed processor
  2698. );
  2699.  
  2700. constructor(
  2701. string memory name_,
  2702. string memory symbol_,
  2703. uint256 totalSupply_,
  2704. address[4] memory addrs, // reward, router, marketing wallet, dividendTracker
  2705. uint256[3] memory feeSettings, // rewards, liquidity, marketing
  2706. uint256 minimumTokenBalanceForDividends_,
  2707. address serviceFeeReceiver_,
  2708. uint256 serviceFee_
  2709. ) payable ERC20(name_, symbol_) {
  2710. rewardToken = addrs[0];
  2711.  
  2712. Tib74, [4/22/2022 7:01 PM]
  2713. _marketingWalletAddress = addrs[2];
  2714. require(
  2715. msg.sender != _marketingWalletAddress,
  2716. "Owner and marketing wallet cannot be the same"
  2717. );
  2718.  
  2719. tokenRewardsFee = feeSettings[0];
  2720. liquidityFee = feeSettings[1];
  2721. marketingFee = feeSettings[2];
  2722. totalFees = tokenRewardsFee.add(liquidityFee).add(marketingFee);
  2723. require(totalFees <= 25, "Total fee is over 25%");
  2724. swapTokensAtAmount = totalSupply_.mul(2).div(10**6); // 0.002%
  2725.  
  2726. // use by default 300,000 gas to process auto-claiming dividends
  2727. gasForProcessing = 300000;
  2728.  
  2729. dividendTracker = BABYTOKENDividendTracker(
  2730. payable(Clones.clone(addrs[3]))
  2731. );
  2732. dividendTracker.initialize(
  2733. rewardToken,
  2734. minimumTokenBalanceForDividends_
  2735. );
  2736.  
  2737. IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(addrs[1]);
  2738. // Create a uniswap pair for this new token
  2739. address _uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
  2740. .createPair(address(this), _uniswapV2Router.WETH());
  2741. uniswapV2Router = _uniswapV2Router;
  2742. uniswapV2Pair = _uniswapV2Pair;
  2743. _setAutomatedMarketMakerPair(_uniswapV2Pair, true);
  2744.  
  2745. // exclude from receiving dividends
  2746. dividendTracker.excludeFromDividends(address(dividendTracker));
  2747. dividendTracker.excludeFromDividends(address(this));
  2748. dividendTracker.excludeFromDividends(owner());
  2749. dividendTracker.excludeFromDividends(address(0xdead));
  2750. dividendTracker.excludeFromDividends(address(_uniswapV2Router));
  2751. // exclude from paying fees or having max transaction amount
  2752. excludeFromFees(owner(), true);
  2753. excludeFromFees(_marketingWalletAddress, true);
  2754. excludeFromFees(address(this), true);
  2755. /*
  2756. _mint is an internal function in ERC20.sol that is only called here,
  2757. and CANNOT be called ever again
  2758. */
  2759. _mint(owner(), totalSupply_);
  2760.  
  2761. emit TokenCreated(owner(), address(this), TokenType.baby, VERSION);
  2762.  
  2763. payable(serviceFeeReceiver_).transfer(serviceFee_);
  2764. }
  2765.  
  2766. receive() external payable {}
  2767.  
  2768. function setSwapTokensAtAmount(uint256 amount) external onlyOwner {
  2769. swapTokensAtAmount = amount;
  2770. }
  2771.  
  2772. function updateDividendTracker(address newAddress) public onlyOwner {
  2773. require(
  2774. newAddress != address(dividendTracker),
  2775. "BABYTOKEN: The dividend tracker already has that address"
  2776. );
  2777.  
  2778. BABYTOKENDividendTracker newDividendTracker = BABYTOKENDividendTracker(
  2779. payable(newAddress)
  2780. );
  2781.  
  2782. require(
  2783. newDividendTracker.owner() == address(this),
  2784. "BABYTOKEN: The new dividend tracker must be owned by the BABYTOKEN token contract"
  2785. );
  2786.  
  2787. newDividendTracker.excludeFromDividends(address(newDividendTracker));
  2788. newDividendTracker.excludeFromDividends(address(this));
  2789. newDividendTracker.excludeFromDividends(owner());
  2790. newDividendTracker.excludeFromDividends(address(uniswapV2Router));
  2791.  
  2792. emit UpdateDividendTracker(newAddress, address(dividendTracker));
  2793.  
  2794. dividendTracker = newDividendTracker;
  2795. }
  2796.  
  2797. function updateUniswapV2Router(address newAddress) public onlyOwner {
  2798. require(
  2799. newAddress != address(uniswapV2Router),
  2800. "BABYTOKEN: The router already has that address"
  2801. );
  2802. emit UpdateUniswapV2Router(newAddress, address(uniswapV2Router));
  2803. uniswapV2Router = IUniswapV2Router02(newAddress);
  2804. address _uniswapV2Pair = IUniswapV2Factory(uniswapV2Router.factory())
  2805. .createPair(address(this), uniswapV2Router.WETH());
  2806. uniswapV2Pair = _uniswapV2Pair;
  2807. }
  2808.  
  2809. function excludeFromFees(address account, bool excluded) public onlyOwner {
  2810. require(
  2811. _isExcludedFromFees[account] != excluded,
  2812. "BABYTOKEN: Account is already the value of 'excluded'"
  2813. );
  2814. _isExcludedFromFees[account] = excluded;
  2815.  
  2816. Tib74, [4/22/2022 7:01 PM]
  2817. emit ExcludeFromFees(account, excluded);
  2818. }
  2819.  
  2820. function excludeMultipleAccountsFromFees(
  2821. address[] calldata accounts,
  2822. bool excluded
  2823. ) public onlyOwner {
  2824. for (uint256 i = 0; i < accounts.length; i++) {
  2825. _isExcludedFromFees[accounts[i]] = excluded;
  2826. }
  2827.  
  2828. emit ExcludeMultipleAccountsFromFees(accounts, excluded);
  2829. }
  2830.  
  2831. function setMarketingWallet(address payable wallet) external onlyOwner {
  2832. _marketingWalletAddress = wallet;
  2833. }
  2834.  
  2835. function setTokenRewardsFee(uint256 value) external onlyOwner {
  2836. tokenRewardsFee = value;
  2837. totalFees = tokenRewardsFee.add(liquidityFee).add(marketingFee);
  2838. require(totalFees <= 25, "Total fee is over 25%");
  2839. }
  2840.  
  2841. function setLiquiditFee(uint256 value) external onlyOwner {
  2842. liquidityFee = value;
  2843. totalFees = tokenRewardsFee.add(liquidityFee).add(marketingFee);
  2844. require(totalFees <= 25, "Total fee is over 25%");
  2845. }
  2846.  
  2847. function setMarketingFee(uint256 value) external onlyOwner {
  2848. marketingFee = value;
  2849. totalFees = tokenRewardsFee.add(liquidityFee).add(marketingFee);
  2850. require(totalFees <= 25, "Total fee is over 25%");
  2851. }
  2852.  
  2853. function setAutomatedMarketMakerPair(address pair, bool value)
  2854. public
  2855. onlyOwner
  2856. {
  2857. require(
  2858. pair != uniswapV2Pair,
  2859. "BABYTOKEN: The PancakeSwap pair cannot be removed from automatedMarketMakerPairs"
  2860. );
  2861.  
  2862. _setAutomatedMarketMakerPair(pair, value);
  2863. }
  2864.  
  2865. function _setAutomatedMarketMakerPair(address pair, bool value) private {
  2866. require(
  2867. automatedMarketMakerPairs[pair] != value,
  2868. "BABYTOKEN: Automated market maker pair is already set to that value"
  2869. );
  2870. automatedMarketMakerPairs[pair] = value;
  2871.  
  2872. if (value) {
  2873. dividendTracker.excludeFromDividends(pair);
  2874. }
  2875.  
  2876. emit SetAutomatedMarketMakerPair(pair, value);
  2877. }
  2878.  
  2879. function updateGasForProcessing(uint256 newValue) public onlyOwner {
  2880. require(
  2881. newValue >= 200000 && newValue <= 500000,
  2882. "BABYTOKEN: gasForProcessing must be between 200,000 and 500,000"
  2883. );
  2884. require(
  2885. newValue != gasForProcessing,
  2886. "BABYTOKEN: Cannot update gasForProcessing to same value"
  2887. );
  2888. emit GasForProcessingUpdated(newValue, gasForProcessing);
  2889. gasForProcessing = newValue;
  2890. }
  2891.  
  2892. function updateClaimWait(uint256 claimWait) external onlyOwner {
  2893. dividendTracker.updateClaimWait(claimWait);
  2894. }
  2895.  
  2896. function getClaimWait() external view returns (uint256) {
  2897. return dividendTracker.claimWait();
  2898. }
  2899.  
  2900. function updateMinimumTokenBalanceForDividends(uint256 amount)
  2901. external
  2902. onlyOwner
  2903. {
  2904. dividendTracker.updateMinimumTokenBalanceForDividends(amount);
  2905. }
  2906.  
  2907. function getMinimumTokenBalanceForDividends()
  2908. external
  2909. view
  2910. returns (uint256)
  2911. {
  2912. return dividendTracker.minimumTokenBalanceForDividends();
  2913. }
  2914.  
  2915. function getTotalDividendsDistributed() external view returns (uint256) {
  2916. return dividendTracker.totalDividendsDistributed();
  2917. }
  2918.  
  2919. function isExcludedFromFees(address account) public view returns (bool) {
  2920. return _isExcludedFromFees[account];
  2921. }
  2922.  
  2923. function withdrawableDividendOf(address account)
  2924. public
  2925. view
  2926. returns (uint256)
  2927. {
  2928. return dividendTracker.withdrawableDividendOf(account);
  2929. }
  2930.  
  2931. function dividendTokenBalanceOf(address account)
  2932. public
  2933. view
  2934. returns (uint256)
  2935. {
  2936. return dividendTracker.balanceOf(account);
  2937. }
  2938.  
  2939. function excludeFromDividends(address account) external onlyOwner {
  2940. dividendTracker.excludeFromDividends(account);
  2941. }
  2942.  
  2943. function isExcludedFromDividends(address account)
  2944. public
  2945. view
  2946. returns (bool)
  2947. {
  2948. return dividendTracker.isExcludedFromDividends(account);
  2949. }
  2950.  
  2951. function getAccountDividendsInfo(address account)
  2952. external
  2953.  
  2954. Tib74, [4/22/2022 7:01 PM]
  2955. view
  2956. returns (
  2957. address,
  2958. int256,
  2959. int256,
  2960. uint256,
  2961. uint256,
  2962. uint256,
  2963. uint256,
  2964. uint256
  2965. )
  2966. {
  2967. return dividendTracker.getAccount(account);
  2968. }
  2969.  
  2970. function getAccountDividendsInfoAtIndex(uint256 index)
  2971. external
  2972. view
  2973. returns (
  2974. address,
  2975. int256,
  2976. int256,
  2977. uint256,
  2978. uint256,
  2979. uint256,
  2980. uint256,
  2981. uint256
  2982. )
  2983. {
  2984. return dividendTracker.getAccountAtIndex(index);
  2985. }
  2986.  
  2987. function processDividendTracker(uint256 gas) external {
  2988. (
  2989. uint256 iterations,
  2990. uint256 claims,
  2991. uint256 lastProcessedIndex
  2992. ) = dividendTracker.process(gas);
  2993. emit ProcessedDividendTracker(
  2994. iterations,
  2995. claims,
  2996. lastProcessedIndex,
  2997. false,
  2998. gas,
  2999. tx.origin
  3000. );
  3001. }
  3002.  
  3003. function claim() external {
  3004. dividendTracker.processAccount(payable(msg.sender), false);
  3005. }
  3006.  
  3007. function getLastProcessedIndex() external view returns (uint256) {
  3008. return dividendTracker.getLastProcessedIndex();
  3009. }
  3010.  
  3011. function getNumberOfDividendTokenHolders() external view returns (uint256) {
  3012. return dividendTracker.getNumberOfTokenHolders();
  3013. }
  3014.  
  3015. function _transfer(
  3016. address from,
  3017. address to,
  3018. uint256 amount
  3019. ) internal override {
  3020. require(from != address(0), "ERC20: transfer from the zero address");
  3021. require(to != address(0), "ERC20: transfer to the zero address");
  3022.  
  3023. if (amount == 0) {
  3024. super._transfer(from, to, 0);
  3025. return;
  3026. }
  3027.  
  3028. uint256 contractTokenBalance = balanceOf(address(this));
  3029.  
  3030. bool canSwap = contractTokenBalance >= swapTokensAtAmount;
  3031.  
  3032. if (
  3033. canSwap &&
  3034. !swapping &&
  3035. !automatedMarketMakerPairs[from] &&
  3036. from != owner() &&
  3037. to != owner()
  3038. ) {
  3039. swapping = true;
  3040.  
  3041. uint256 marketingTokens = contractTokenBalance
  3042. .mul(marketingFee)
  3043. .div(totalFees);
  3044. swapAndSendToFee(marketingTokens);
  3045.  
  3046. uint256 swapTokens = contractTokenBalance.mul(liquidityFee).div(
  3047. totalFees
  3048. );
  3049. swapAndLiquify(swapTokens);
  3050.  
  3051. uint256 sellTokens = balanceOf(address(this));
  3052. swapAndSendDividends(sellTokens);
  3053.  
  3054. swapping = false;
  3055. }
  3056.  
  3057. bool takeFee = !swapping;
  3058.  
  3059. // if any account belongs to _isExcludedFromFee account then remove the fee
  3060. if (_isExcludedFromFees[from] || _isExcludedFromFees[to]) {
  3061. takeFee = false;
  3062. }
  3063.  
  3064. if (takeFee) {
  3065. uint256 fees = amount.mul(totalFees).div(100);
  3066. if (automatedMarketMakerPairs[to]) {
  3067. fees += amount.mul(1).div(100);
  3068. }
  3069. amount = amount.sub(fees);
  3070.  
  3071. super._transfer(from, address(this), fees);
  3072. }
  3073.  
  3074. super._transfer(from, to, amount);
  3075.  
  3076. try
  3077. dividendTracker.setBalance(payable(from), balanceOf(from))
  3078. {} catch {}
  3079. try dividendTracker.setBalance(payable(to), balanceOf(to)) {} catch {}
  3080.  
  3081. if (!swapping) {
  3082. uint256 gas = gasForProcessing;
  3083.  
  3084. try dividendTracker.process(gas) returns (
  3085. uint256 iterations,
  3086. uint256 claims,
  3087. uint256 lastProcessedIndex
  3088. ) {
  3089. emit ProcessedDividendTracker(
  3090. iterations,
  3091. claims,
  3092. lastProcessedIndex,
  3093. true,
  3094. gas,
  3095. tx.origin
  3096. );
  3097. } catch {}
  3098. }
  3099. }
  3100.  
  3101. function swapAndSendToFee(uint256 tokens) private {
  3102. uint256 initialCAKEBalance = IERC20(rewardToken).balanceOf(
  3103. address(this)
  3104. );
  3105.  
  3106. swapTokensForCake(tokens);
  3107.  
  3108. Tib74, [4/22/2022 7:01 PM]
  3109. uint256 newBalance = (IERC20(rewardToken).balanceOf(address(this))).sub(
  3110. initialCAKEBalance
  3111. );
  3112. IERC20(rewardToken).transfer(_marketingWalletAddress, newBalance);
  3113. }
  3114.  
  3115. function swapAndLiquify(uint256 tokens) private {
  3116. // split the contract balance into halves
  3117. uint256 half = tokens.div(2);
  3118. uint256 otherHalf = tokens.sub(half);
  3119.  
  3120. // capture the contract's current ETH balance.
  3121. // this is so that we can capture exactly the amount of ETH that the
  3122. // swap creates, and not make the liquidity event include any ETH that
  3123. // has been manually sent to the contract
  3124. uint256 initialBalance = address(this).balance;
  3125.  
  3126. // swap tokens for ETH
  3127. swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered
  3128.  
  3129. // how much ETH did we just swap into?
  3130. uint256 newBalance = address(this).balance.sub(initialBalance);
  3131.  
  3132. // add liquidity to uniswap
  3133. addLiquidity(otherHalf, newBalance);
  3134.  
  3135. emit SwapAndLiquify(half, newBalance, otherHalf);
  3136. }
  3137.  
  3138. function swapTokensForEth(uint256 tokenAmount) private {
  3139. // generate the uniswap pair path of token -> weth
  3140. address[] memory path = new address[](2);
  3141. path[0] = address(this);
  3142. path[1] = uniswapV2Router.WETH();
  3143.  
  3144. _approve(address(this), address(uniswapV2Router), tokenAmount);
  3145.  
  3146. // make the swap
  3147. uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
  3148. tokenAmount,
  3149. 0, // accept any amount of ETH
  3150. path,
  3151. address(this),
  3152. block.timestamp
  3153. );
  3154. }
  3155.  
  3156. function swapTokensForCake(uint256 tokenAmount) private {
  3157. address[] memory path = new address[](3);
  3158. path[0] = address(this);
  3159. path[1] = uniswapV2Router.WETH();
  3160. path[2] = rewardToken;
  3161.  
  3162. _approve(address(this), address(uniswapV2Router), tokenAmount);
  3163.  
  3164. // make the swap
  3165. uniswapV2Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
  3166. tokenAmount,
  3167. 0,
  3168. path,
  3169. address(this),
  3170. block.timestamp
  3171. );
  3172. }
  3173.  
  3174. function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
  3175. // approve token transfer to cover all possible scenarios
  3176. _approve(address(this), address(uniswapV2Router), tokenAmount);
  3177.  
  3178. // add the liquidity
  3179. uniswapV2Router.addLiquidityETH{value: ethAmount}(
  3180. address(this),
  3181. tokenAmount,
  3182. 0, // slippage is unavoidable
  3183. 0, // slippage is unavoidable
  3184. address(0),
  3185. block.timestamp
  3186. );
  3187. }
  3188.  
  3189. function swapAndSendDividends(uint256 tokens) private {
  3190. swapTokensForCake(tokens);
  3191. uint256 dividends = IERC20(rewardToken).balanceOf(address(this));
  3192. bool success = IERC20(rewardToken).transfer(
  3193. address(dividendTracker),
  3194. dividends
  3195. );
  3196.  
  3197. if (success) {
  3198. dividendTracker.distributeCAKEDividends(dividends);
  3199. emit SendDividends(tokens, dividends);
  3200. }
  3201. }
  3202. }
  3203.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement