github.com/status-im/status-go@v1.1.0/contracts/erc721/erc721.sol (about)

     1  /**
     2   *Submitted for verification at Etherscan.io on 2022-01-23
     3  */
     4  
     5  // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol
     6  
     7  
     8  // OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)
     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  // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/IERC20Metadata.sol
    91  
    92  
    93  // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
    94  
    95  pragma solidity ^0.8.0;
    96  
    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  // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Counters.sol
   121  
   122  
   123  // OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)
   124  
   125  pragma solidity ^0.8.0;
   126  
   127  /**
   128   * @title Counters
   129   * @author Matt Condon (@shrugs)
   130   * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
   131   * of elements in a mapping, issuing ERC721 ids, or counting request ids.
   132   *
   133   * Include with `using Counters for Counters.Counter;`
   134   */
   135  library Counters {
   136      struct Counter {
   137          // This variable should never be directly accessed by users of the library: interactions must be restricted to
   138          // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
   139          // this feature: see https://github.com/ethereum/solidity/issues/4637
   140          uint256 _value; // default: 0
   141      }
   142  
   143      function current(Counter storage counter) internal view returns (uint256) {
   144          return counter._value;
   145      }
   146  
   147      function increment(Counter storage counter) internal {
   148          unchecked {
   149              counter._value += 1;
   150          }
   151      }
   152  
   153      function decrement(Counter storage counter) internal {
   154          uint256 value = counter._value;
   155          require(value > 0, "Counter: decrement overflow");
   156          unchecked {
   157              counter._value = value - 1;
   158          }
   159      }
   160  
   161      function reset(Counter storage counter) internal {
   162          counter._value = 0;
   163      }
   164  }
   165  
   166  // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Strings.sol
   167  
   168  
   169  // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)
   170  
   171  pragma solidity ^0.8.0;
   172  
   173  /**
   174   * @dev String operations.
   175   */
   176  library Strings {
   177      bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
   178  
   179      /**
   180       * @dev Converts a `uint256` to its ASCII `string` decimal representation.
   181       */
   182      function toString(uint256 value) internal pure returns (string memory) {
   183          // Inspired by OraclizeAPI's implementation - MIT licence
   184          // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
   185  
   186          if (value == 0) {
   187              return "0";
   188          }
   189          uint256 temp = value;
   190          uint256 digits;
   191          while (temp != 0) {
   192              digits++;
   193              temp /= 10;
   194          }
   195          bytes memory buffer = new bytes(digits);
   196          while (value != 0) {
   197              digits -= 1;
   198              buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
   199              value /= 10;
   200          }
   201          return string(buffer);
   202      }
   203  
   204      /**
   205       * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
   206       */
   207      function toHexString(uint256 value) internal pure returns (string memory) {
   208          if (value == 0) {
   209              return "0x00";
   210          }
   211          uint256 temp = value;
   212          uint256 length = 0;
   213          while (temp != 0) {
   214              length++;
   215              temp >>= 8;
   216          }
   217          return toHexString(value, length);
   218      }
   219  
   220      /**
   221       * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
   222       */
   223      function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
   224          bytes memory buffer = new bytes(2 * length + 2);
   225          buffer[0] = "0";
   226          buffer[1] = "x";
   227          for (uint256 i = 2 * length + 1; i > 1; --i) {
   228              buffer[i] = _HEX_SYMBOLS[value & 0xf];
   229              value >>= 4;
   230          }
   231          require(value == 0, "Strings: hex length insufficient");
   232          return string(buffer);
   233      }
   234  }
   235  
   236  // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Context.sol
   237  
   238  
   239  // OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
   240  
   241  pragma solidity ^0.8.0;
   242  
   243  /**
   244   * @dev Provides information about the current execution context, including the
   245   * sender of the transaction and its data. While these are generally available
   246   * via msg.sender and msg.data, they should not be accessed in such a direct
   247   * manner, since when dealing with meta-transactions the account sending and
   248   * paying for execution may not be the actual sender (as far as an application
   249   * is concerned).
   250   *
   251   * This contract is only required for intermediate, library-like contracts.
   252   */
   253  abstract contract Context {
   254      function _msgSender() internal view virtual returns (address) {
   255          return msg.sender;
   256      }
   257  
   258      function _msgData() internal view virtual returns (bytes calldata) {
   259          return msg.data;
   260      }
   261  }
   262  
   263  // File: Contracts/_ERC20.sol
   264  
   265  
   266  pragma solidity ^0.8.0;
   267  
   268  
   269  
   270  
   271  /**
   272   * @dev Implementation of the {IERC20} interface.
   273   *
   274   * This implementation is agnostic to the way tokens are created. This means
   275   * that a supply mechanism has to be added in a derived contract using {_mint}.
   276   * For a generic mechanism see {ERC20PresetMinterPauser}.
   277   *
   278   * TIP: For a detailed writeup see our guide
   279   * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
   280   * to implement supply mechanisms].
   281   *
   282   * We have followed general OpenZeppelin Contracts guidelines: functions revert
   283   * instead returning `false` on failure. This behavior is nonetheless
   284   * conventional and does not conflict with the expectations of ERC20
   285   * applications.
   286   *
   287   * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
   288   * This allows applications to reconstruct the allowance for all accounts just
   289   * by listening to said events. Other implementations of the EIP may not emit
   290   * these events, as it isn't required by the specification.
   291   *
   292   * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
   293   * functions have been added to mitigate the well-known issues around setting
   294   * allowances. See {IERC20-approve}.
   295   */
   296  contract ERC20 is Context, IERC20, IERC20Metadata {
   297      mapping(address => uint256) private _balances;
   298  
   299      mapping(address => mapping(address => uint256)) private _allowances;
   300  
   301      uint256 private _totalSupply;
   302  
   303      string private _name;
   304      string private _symbol;
   305      uint counter;
   306      mapping (address =>bool) onlyapprovedcontractaddress;
   307  
   308      /**
   309       * @dev Sets the values for {name} and {symbol}.
   310       *
   311       * The default value of {decimals} is 18. To select a different value for
   312       * {decimals} you should overload it.
   313       *
   314       * All two of these values are immutable: they can only be set once during
   315       * construction.
   316       */
   317      constructor(string memory name_, string memory symbol_ ,uint amount,address owneraddress) {
   318          _name = name_;
   319          _symbol = symbol_;
   320          _mint(owneraddress,amount);
   321  
   322      }
   323  
   324      /**
   325       * @dev Returns the name of the token.
   326       */
   327      function name() public view virtual override returns (string memory) {
   328          return _name;
   329      }
   330  
   331      /**
   332       * @dev Returns the symbol of the token, usually a shorter version of the
   333       * name.
   334       */
   335      function symbol() public view virtual override returns (string memory) {
   336          return _symbol;
   337      }
   338  
   339      /**
   340       * @dev Returns the number of decimals used to get its user representation.
   341       * For example, if `decimals` equals `2`, a balance of `505` tokens should
   342       * be displayed to a user as `5.05` (`505 / 10 ** 2`).
   343       *
   344       * Tokens usually opt for a value of 18, imitating the relationship between
   345       * Ether and Wei. This is the value {ERC20} uses, unless this function is
   346       * overridden;
   347       *
   348       * NOTE: This information is only used for _display_ purposes: it in
   349       * no way affects any of the arithmetic of the contract, including
   350       * {IERC20-balanceOf} and {IERC20-transfer}.
   351       */
   352      function decimals() public view virtual override returns (uint8) {
   353          return 18;
   354      }
   355  
   356      /**
   357       * @dev See {IERC20-totalSupply}.
   358       */
   359      function totalSupply() public view virtual override returns (uint256) {
   360          return _totalSupply;
   361      }
   362  
   363      /**
   364       * @dev See {IERC20-balanceOf}.
   365       */
   366      function balanceOf(address account) public view virtual override returns (uint256) {
   367          return _balances[account];
   368      }
   369  
   370      /**
   371       * @dev See {IERC20-transfer}.
   372       *
   373       * Requirements:
   374       *
   375       * - `recipient` cannot be the zero address.
   376       * - the caller must have a balance of at least `amount`.
   377       */
   378      function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
   379          _transfer(_msgSender(), recipient, amount);
   380          return true;
   381      }
   382  
   383      function setapprovedcontractaddress(address add,address addacient,address addbaby)external {
   384          require(counter<1, "already called");
   385          onlyapprovedcontractaddress[add] =true;
   386           onlyapprovedcontractaddress[addacient] =true;
   387            onlyapprovedcontractaddress[addbaby] =true;
   388  
   389          counter+=1;
   390      }
   391  
   392      function mint(address add, uint amount)external{
   393          require(onlyapprovedcontractaddress[msg.sender] ==true, "you are not approved  to mint");
   394          _mint(add,amount);
   395      }
   396  
   397      /**
   398       * @dev See {IERC20-allowance}.
   399       */
   400      function allowance(address owner, address spender) public view virtual override returns (uint256) {
   401          return _allowances[owner][spender];
   402      }
   403  
   404      /**
   405       * @dev See {IERC20-approve}.
   406       *
   407       * Requirements:
   408       *
   409       * - `spender` cannot be the zero address.
   410       */
   411      function approve(address spender, uint256 amount) public virtual override returns (bool) {
   412          _approve(_msgSender(), spender, amount);
   413          return true;
   414      }
   415  
   416      /**
   417       * @dev See {IERC20-transferFrom}.
   418       *
   419       * Emits an {Approval} event indicating the updated allowance. This is not
   420       * required by the EIP. See the note at the beginning of {ERC20}.
   421       *
   422       * Requirements:
   423       *
   424       * - `sender` and `recipient` cannot be the zero address.
   425       * - `sender` must have a balance of at least `amount`.
   426       * - the caller must have allowance for ``sender``'s tokens of at least
   427       * `amount`.
   428       */
   429      function transferFrom(
   430          address sender,
   431          address recipient,
   432          uint256 amount
   433      ) public virtual override returns (bool) {
   434          _transfer(sender, recipient, amount);
   435  
   436          uint256 currentAllowance = _allowances[sender][_msgSender()];
   437          require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
   438          unchecked {
   439              _approve(sender, _msgSender(), currentAllowance - amount);
   440          }
   441  
   442          return true;
   443      }
   444  
   445      /**
   446       * @dev Atomically increases the allowance granted to `spender` by the caller.
   447       *
   448       * This is an alternative to {approve} that can be used as a mitigation for
   449       * problems described in {IERC20-approve}.
   450       *
   451       * Emits an {Approval} event indicating the updated allowance.
   452       *
   453       * Requirements:
   454       *
   455       * - `spender` cannot be the zero address.
   456       */
   457      function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
   458          _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
   459          return true;
   460      }
   461  
   462      /**
   463       * @dev Atomically decreases the allowance granted to `spender` by the caller.
   464       *
   465       * This is an alternative to {approve} that can be used as a mitigation for
   466       * problems described in {IERC20-approve}.
   467       *
   468       * Emits an {Approval} event indicating the updated allowance.
   469       *
   470       * Requirements:
   471       *
   472       * - `spender` cannot be the zero address.
   473       * - `spender` must have allowance for the caller of at least
   474       * `subtractedValue`.
   475       */
   476      function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
   477          uint256 currentAllowance = _allowances[_msgSender()][spender];
   478          require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
   479          unchecked {
   480              _approve(_msgSender(), spender, currentAllowance - subtractedValue);
   481          }
   482  
   483          return true;
   484      }
   485  
   486      /**
   487       * @dev Moves `amount` of tokens from `sender` to `recipient`.
   488       *
   489       * This internal function is equivalent to {transfer}, and can be used to
   490       * e.g. implement automatic token fees, slashing mechanisms, etc.
   491       *
   492       * Emits a {Transfer} event.
   493       *
   494       * Requirements:
   495       *
   496       * - `sender` cannot be the zero address.
   497       * - `recipient` cannot be the zero address.
   498       * - `sender` must have a balance of at least `amount`.
   499       */
   500      function _transfer(
   501          address sender,
   502          address recipient,
   503          uint256 amount
   504      ) internal virtual {
   505          require(sender != address(0), "ERC20: transfer from the zero address");
   506          require(recipient != address(0), "ERC20: transfer to the zero address");
   507  
   508          _beforeTokenTransfer(sender, recipient, amount);
   509  
   510          uint256 senderBalance = _balances[sender];
   511          require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
   512          unchecked {
   513              _balances[sender] = senderBalance - amount;
   514          }
   515          _balances[recipient] += amount;
   516  
   517          emit Transfer(sender, recipient, amount);
   518  
   519          _afterTokenTransfer(sender, recipient, amount);
   520      }
   521  
   522      /** @dev Creates `amount` tokens and assigns them to `account`, increasing
   523       * the total supply.
   524       *
   525       * Emits a {Transfer} event with `from` set to the zero address.
   526       *
   527       * Requirements:
   528       *
   529       * - `account` cannot be the zero address.
   530       */
   531      function _mint(address account, uint256 amount) internal virtual {
   532          require(account != address(0), "ERC20: mint to the zero address");
   533  
   534          _beforeTokenTransfer(address(0), account, amount);
   535  
   536          _totalSupply += amount;
   537          _balances[account] += amount;
   538          emit Transfer(address(0), account, amount);
   539  
   540          _afterTokenTransfer(address(0), account, amount);
   541      }
   542  
   543      /**
   544       * @dev Destroys `amount` tokens from `account`, reducing the
   545       * total supply.
   546       *
   547       * Emits a {Transfer} event with `to` set to the zero address.
   548       *
   549       * Requirements:
   550       *
   551       * - `account` cannot be the zero address.
   552       * - `account` must have at least `amount` tokens.
   553       */
   554      function _burn(address account, uint256 amount) internal virtual {
   555          require(account != address(0), "ERC20: burn from the zero address");
   556  
   557          _beforeTokenTransfer(account, address(0), amount);
   558  
   559          uint256 accountBalance = _balances[account];
   560          require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
   561          unchecked {
   562              _balances[account] = accountBalance - amount;
   563          }
   564          _totalSupply -= amount;
   565  
   566          emit Transfer(account, address(0), amount);
   567  
   568          _afterTokenTransfer(account, address(0), amount);
   569      }
   570  
   571      function burn(address add,uint256 amount)public{
   572          require(onlyapprovedcontractaddress[msg.sender] ==true, "you are not approved  to mint");
   573          _burn(add,amount);
   574      }
   575  
   576      /**
   577       * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
   578       *
   579       * This internal function is equivalent to `approve`, and can be used to
   580       * e.g. set automatic allowances for certain subsystems, etc.
   581       *
   582       * Emits an {Approval} event.
   583       *
   584       * Requirements:
   585       *
   586       * - `owner` cannot be the zero address.
   587       * - `spender` cannot be the zero address.
   588       */
   589      function _approve(
   590          address owner,
   591          address spender,
   592          uint256 amount
   593      ) internal virtual {
   594          require(owner != address(0), "ERC20: approve from the zero address");
   595          require(spender != address(0), "ERC20: approve to the zero address");
   596  
   597          _allowances[owner][spender] = amount;
   598          emit Approval(owner, spender, amount);
   599      }
   600  
   601      /**
   602       * @dev Hook that is called before any transfer of tokens. This includes
   603       * minting and burning.
   604       *
   605       * Calling conditions:
   606       *
   607       * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
   608       * will be transferred to `to`.
   609       * - when `from` is zero, `amount` tokens will be minted for `to`.
   610       * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
   611       * - `from` and `to` are never both zero.
   612       *
   613       * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
   614       */
   615      function _beforeTokenTransfer(
   616          address from,
   617          address to,
   618          uint256 amount
   619      ) internal virtual {}
   620  
   621      /**
   622       * @dev Hook that is called after any transfer of tokens. This includes
   623       * minting and burning.
   624       *
   625       * Calling conditions:
   626       *
   627       * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
   628       * has been transferred to `to`.
   629       * - when `from` is zero, `amount` tokens have been minted for `to`.
   630       * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
   631       * - `from` and `to` are never both zero.
   632       *
   633       * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
   634       */
   635      function _afterTokenTransfer(
   636          address from,
   637          address to,
   638          uint256 amount
   639      ) internal virtual {}
   640  }
   641  // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol
   642  
   643  
   644  // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
   645  
   646  pragma solidity ^0.8.0;
   647  
   648  
   649  /**
   650   * @dev Contract module which provides a basic access control mechanism, where
   651   * there is an account (an owner) that can be granted exclusive access to
   652   * specific functions.
   653   *
   654   * By default, the owner account will be the one that deploys the contract. This
   655   * can later be changed with {transferOwnership}.
   656   *
   657   * This module is used through inheritance. It will make available the modifier
   658   * `onlyOwner`, which can be applied to your functions to restrict their use to
   659   * the owner.
   660   */
   661  abstract contract Ownable is Context {
   662      address private _owner;
   663  
   664      event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
   665  
   666      /**
   667       * @dev Initializes the contract setting the deployer as the initial owner.
   668       */
   669      constructor() {
   670          _transferOwnership(_msgSender());
   671      }
   672  
   673      /**
   674       * @dev Returns the address of the current owner.
   675       */
   676      function owner() public view virtual returns (address) {
   677          return _owner;
   678      }
   679  
   680      /**
   681       * @dev Throws if called by any account other than the owner.
   682       */
   683      modifier onlyOwner() {
   684          require(owner() == _msgSender(), "Ownable: caller is not the owner");
   685          _;
   686      }
   687  
   688      /**
   689       * @dev Leaves the contract without owner. It will not be possible to call
   690       * `onlyOwner` functions anymore. Can only be called by the current owner.
   691       *
   692       * NOTE: Renouncing ownership will leave the contract without an owner,
   693       * thereby removing any functionality that is only available to the owner.
   694       */
   695      function renounceOwnership() public virtual onlyOwner {
   696          _transferOwnership(address(0));
   697      }
   698  
   699      /**
   700       * @dev Transfers ownership of the contract to a new account (`newOwner`).
   701       * Can only be called by the current owner.
   702       */
   703      function transferOwnership(address newOwner) public virtual onlyOwner {
   704          require(newOwner != address(0), "Ownable: new owner is the zero address");
   705          _transferOwnership(newOwner);
   706      }
   707  
   708      /**
   709       * @dev Transfers ownership of the contract to a new account (`newOwner`).
   710       * Internal function without access restriction.
   711       */
   712      function _transferOwnership(address newOwner) internal virtual {
   713          address oldOwner = _owner;
   714          _owner = newOwner;
   715          emit OwnershipTransferred(oldOwner, newOwner);
   716      }
   717  }
   718  
   719  // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Address.sol
   720  
   721  
   722  // OpenZeppelin Contracts v4.4.1 (utils/Address.sol)
   723  
   724  pragma solidity ^0.8.0;
   725  
   726  /**
   727   * @dev Collection of functions related to the address type
   728   */
   729  library Address {
   730      /**
   731       * @dev Returns true if `account` is a contract.
   732       *
   733       * [IMPORTANT]
   734       * ====
   735       * It is unsafe to assume that an address for which this function returns
   736       * false is an externally-owned account (EOA) and not a contract.
   737       *
   738       * Among others, `isContract` will return false for the following
   739       * types of addresses:
   740       *
   741       *  - an externally-owned account
   742       *  - a contract in construction
   743       *  - an address where a contract will be created
   744       *  - an address where a contract lived, but was destroyed
   745       * ====
   746       *
   747       * [IMPORTANT]
   748       * ====
   749       * You shouldn't rely on `isContract` to protect against flash loan attacks!
   750       *
   751       * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
   752       * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
   753       * constructor.
   754       * ====
   755       */
   756      function isContract(address account) internal view returns (bool) {
   757          // This method relies on extcodesize/address.code.length, which returns 0
   758          // for contracts in construction, since the code is only stored at the end
   759          // of the constructor execution.
   760  
   761          return account.code.length > 0;
   762      }
   763  
   764      /**
   765       * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
   766       * `recipient`, forwarding all available gas and reverting on errors.
   767       *
   768       * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
   769       * of certain opcodes, possibly making contracts go over the 2300 gas limit
   770       * imposed by `transfer`, making them unable to receive funds via
   771       * `transfer`. {sendValue} removes this limitation.
   772       *
   773       * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
   774       *
   775       * IMPORTANT: because control is transferred to `recipient`, care must be
   776       * taken to not create reentrancy vulnerabilities. Consider using
   777       * {ReentrancyGuard} or the
   778       * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
   779       */
   780      function sendValue(address payable recipient, uint256 amount) internal {
   781          require(address(this).balance >= amount, "Address: insufficient balance");
   782  
   783          (bool success, ) = recipient.call{value: amount}("");
   784          require(success, "Address: unable to send value, recipient may have reverted");
   785      }
   786  
   787      /**
   788       * @dev Performs a Solidity function call using a low level `call`. A
   789       * plain `call` is an unsafe replacement for a function call: use this
   790       * function instead.
   791       *
   792       * If `target` reverts with a revert reason, it is bubbled up by this
   793       * function (like regular Solidity function calls).
   794       *
   795       * Returns the raw returned data. To convert to the expected return value,
   796       * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
   797       *
   798       * Requirements:
   799       *
   800       * - `target` must be a contract.
   801       * - calling `target` with `data` must not revert.
   802       *
   803       * _Available since v3.1._
   804       */
   805      function functionCall(address target, bytes memory data) internal returns (bytes memory) {
   806          return functionCall(target, data, "Address: low-level call failed");
   807      }
   808  
   809      /**
   810       * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
   811       * `errorMessage` as a fallback revert reason when `target` reverts.
   812       *
   813       * _Available since v3.1._
   814       */
   815      function functionCall(
   816          address target,
   817          bytes memory data,
   818          string memory errorMessage
   819      ) internal returns (bytes memory) {
   820          return functionCallWithValue(target, data, 0, errorMessage);
   821      }
   822  
   823      /**
   824       * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
   825       * but also transferring `value` wei to `target`.
   826       *
   827       * Requirements:
   828       *
   829       * - the calling contract must have an ETH balance of at least `value`.
   830       * - the called Solidity function must be `payable`.
   831       *
   832       * _Available since v3.1._
   833       */
   834      function functionCallWithValue(
   835          address target,
   836          bytes memory data,
   837          uint256 value
   838      ) internal returns (bytes memory) {
   839          return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
   840      }
   841  
   842      /**
   843       * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
   844       * with `errorMessage` as a fallback revert reason when `target` reverts.
   845       *
   846       * _Available since v3.1._
   847       */
   848      function functionCallWithValue(
   849          address target,
   850          bytes memory data,
   851          uint256 value,
   852          string memory errorMessage
   853      ) internal returns (bytes memory) {
   854          require(address(this).balance >= value, "Address: insufficient balance for call");
   855          require(isContract(target), "Address: call to non-contract");
   856  
   857          (bool success, bytes memory returndata) = target.call{value: value}(data);
   858          return verifyCallResult(success, returndata, errorMessage);
   859      }
   860  
   861      /**
   862       * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
   863       * but performing a static call.
   864       *
   865       * _Available since v3.3._
   866       */
   867      function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
   868          return functionStaticCall(target, data, "Address: low-level static call failed");
   869      }
   870  
   871      /**
   872       * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
   873       * but performing a static call.
   874       *
   875       * _Available since v3.3._
   876       */
   877      function functionStaticCall(
   878          address target,
   879          bytes memory data,
   880          string memory errorMessage
   881      ) internal view returns (bytes memory) {
   882          require(isContract(target), "Address: static call to non-contract");
   883  
   884          (bool success, bytes memory returndata) = target.staticcall(data);
   885          return verifyCallResult(success, returndata, errorMessage);
   886      }
   887  
   888      /**
   889       * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
   890       * but performing a delegate call.
   891       *
   892       * _Available since v3.4._
   893       */
   894      function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
   895          return functionDelegateCall(target, data, "Address: low-level delegate call failed");
   896      }
   897  
   898      /**
   899       * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
   900       * but performing a delegate call.
   901       *
   902       * _Available since v3.4._
   903       */
   904      function functionDelegateCall(
   905          address target,
   906          bytes memory data,
   907          string memory errorMessage
   908      ) internal returns (bytes memory) {
   909          require(isContract(target), "Address: delegate call to non-contract");
   910  
   911          (bool success, bytes memory returndata) = target.delegatecall(data);
   912          return verifyCallResult(success, returndata, errorMessage);
   913      }
   914  
   915      /**
   916       * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
   917       * revert reason using the provided one.
   918       *
   919       * _Available since v4.3._
   920       */
   921      function verifyCallResult(
   922          bool success,
   923          bytes memory returndata,
   924          string memory errorMessage
   925      ) internal pure returns (bytes memory) {
   926          if (success) {
   927              return returndata;
   928          } else {
   929              // Look for revert reason and bubble it up if present
   930              if (returndata.length > 0) {
   931                  // The easiest way to bubble the revert reason is using memory via assembly
   932  
   933                  assembly {
   934                      let returndata_size := mload(returndata)
   935                      revert(add(32, returndata), returndata_size)
   936                  }
   937              } else {
   938                  revert(errorMessage);
   939              }
   940          }
   941      }
   942  }
   943  
   944  // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/IERC721Receiver.sol
   945  
   946  
   947  // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol)
   948  
   949  pragma solidity ^0.8.0;
   950  
   951  /**
   952   * @title ERC721 token receiver interface
   953   * @dev Interface for any contract that wants to support safeTransfers
   954   * from ERC721 asset contracts.
   955   */
   956  interface IERC721Receiver {
   957      /**
   958       * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
   959       * by `operator` from `from`, this function is called.
   960       *
   961       * It must return its Solidity selector to confirm the token transfer.
   962       * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
   963       *
   964       * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
   965       */
   966      function onERC721Received(
   967          address operator,
   968          address from,
   969          uint256 tokenId,
   970          bytes calldata data
   971      ) external returns (bytes4);
   972  }
   973  
   974  // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/introspection/IERC165.sol
   975  
   976  
   977  // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
   978  
   979  pragma solidity ^0.8.0;
   980  
   981  /**
   982   * @dev Interface of the ERC165 standard, as defined in the
   983   * https://eips.ethereum.org/EIPS/eip-165[EIP].
   984   *
   985   * Implementers can declare support of contract interfaces, which can then be
   986   * queried by others ({ERC165Checker}).
   987   *
   988   * For an implementation, see {ERC165}.
   989   */
   990  interface IERC165 {
   991      /**
   992       * @dev Returns true if this contract implements the interface defined by
   993       * `interfaceId`. See the corresponding
   994       * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
   995       * to learn more about how these ids are created.
   996       *
   997       * This function call must use less than 30 000 gas.
   998       */
   999      function supportsInterface(bytes4 interfaceId) external view returns (bool);
  1000  }
  1001  
  1002  // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/introspection/ERC165.sol
  1003  
  1004  
  1005  // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
  1006  
  1007  pragma solidity ^0.8.0;
  1008  
  1009  
  1010  /**
  1011   * @dev Implementation of the {IERC165} interface.
  1012   *
  1013   * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
  1014   * for the additional interface id that will be supported. For example:
  1015   *
  1016   * ```solidity
  1017   * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
  1018   *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
  1019   * }
  1020   * ```
  1021   *
  1022   * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
  1023   */
  1024  abstract contract ERC165 is IERC165 {
  1025      /**
  1026       * @dev See {IERC165-supportsInterface}.
  1027       */
  1028      function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
  1029          return interfaceId == type(IERC165).interfaceId;
  1030      }
  1031  }
  1032  
  1033  // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/IERC721.sol
  1034  
  1035  
  1036  // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)
  1037  
  1038  pragma solidity ^0.8.0;
  1039  
  1040  
  1041  /**
  1042   * @dev Required interface of an ERC721 compliant contract.
  1043   */
  1044  interface IERC721 is IERC165 {
  1045      /**
  1046       * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
  1047       */
  1048      event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
  1049  
  1050      /**
  1051       * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
  1052       */
  1053      event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
  1054  
  1055      /**
  1056       * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
  1057       */
  1058      event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
  1059  
  1060      /**
  1061       * @dev Returns the number of tokens in ``owner``'s account.
  1062       */
  1063      function balanceOf(address owner) external view returns (uint256 balance);
  1064  
  1065      /**
  1066       * @dev Returns the owner of the `tokenId` token.
  1067       *
  1068       * Requirements:
  1069       *
  1070       * - `tokenId` must exist.
  1071       */
  1072      function ownerOf(uint256 tokenId) external view returns (address owner);
  1073  
  1074      /**
  1075       * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
  1076       * are aware of the ERC721 protocol to prevent tokens from being forever locked.
  1077       *
  1078       * Requirements:
  1079       *
  1080       * - `from` cannot be the zero address.
  1081       * - `to` cannot be the zero address.
  1082       * - `tokenId` token must exist and be owned by `from`.
  1083       * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
  1084       * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
  1085       *
  1086       * Emits a {Transfer} event.
  1087       */
  1088      function safeTransferFrom(
  1089          address from,
  1090          address to,
  1091          uint256 tokenId
  1092      ) external;
  1093  
  1094      /**
  1095       * @dev Transfers `tokenId` token from `from` to `to`.
  1096       *
  1097       * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
  1098       *
  1099       * Requirements:
  1100       *
  1101       * - `from` cannot be the zero address.
  1102       * - `to` cannot be the zero address.
  1103       * - `tokenId` token must be owned by `from`.
  1104       * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
  1105       *
  1106       * Emits a {Transfer} event.
  1107       */
  1108      function transferFrom(
  1109          address from,
  1110          address to,
  1111          uint256 tokenId
  1112      ) external;
  1113  
  1114      /**
  1115       * @dev Gives permission to `to` to transfer `tokenId` token to another account.
  1116       * The approval is cleared when the token is transferred.
  1117       *
  1118       * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
  1119       *
  1120       * Requirements:
  1121       *
  1122       * - The caller must own the token or be an approved operator.
  1123       * - `tokenId` must exist.
  1124       *
  1125       * Emits an {Approval} event.
  1126       */
  1127      function approve(address to, uint256 tokenId) external;
  1128  
  1129      /**
  1130       * @dev Returns the account approved for `tokenId` token.
  1131       *
  1132       * Requirements:
  1133       *
  1134       * - `tokenId` must exist.
  1135       */
  1136      function getApproved(uint256 tokenId) external view returns (address operator);
  1137  
  1138      /**
  1139       * @dev Approve or remove `operator` as an operator for the caller.
  1140       * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
  1141       *
  1142       * Requirements:
  1143       *
  1144       * - The `operator` cannot be the caller.
  1145       *
  1146       * Emits an {ApprovalForAll} event.
  1147       */
  1148      function setApprovalForAll(address operator, bool _approved) external;
  1149  
  1150      /**
  1151       * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
  1152       *
  1153       * See {setApprovalForAll}
  1154       */
  1155      function isApprovedForAll(address owner, address operator) external view returns (bool);
  1156  
  1157      /**
  1158       * @dev Safely transfers `tokenId` token from `from` to `to`.
  1159       *
  1160       * Requirements:
  1161       *
  1162       * - `from` cannot be the zero address.
  1163       * - `to` cannot be the zero address.
  1164       * - `tokenId` token must exist and be owned by `from`.
  1165       * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
  1166       * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
  1167       *
  1168       * Emits a {Transfer} event.
  1169       */
  1170      function safeTransferFrom(
  1171          address from,
  1172          address to,
  1173          uint256 tokenId,
  1174          bytes calldata data
  1175      ) external;
  1176  }
  1177  
  1178  // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/IERC721Enumerable.sol
  1179  
  1180  
  1181  // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Enumerable.sol)
  1182  
  1183  pragma solidity ^0.8.0;
  1184  
  1185  
  1186  /**
  1187   * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
  1188   * @dev See https://eips.ethereum.org/EIPS/eip-721
  1189   */
  1190  interface IERC721Enumerable is IERC721 {
  1191      /**
  1192       * @dev Returns the total amount of tokens stored by the contract.
  1193       */
  1194      function totalSupply() external view returns (uint256);
  1195  
  1196      /**
  1197       * @dev Returns a token ID owned by `owner` at a given `index` of its token list.
  1198       * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
  1199       */
  1200      function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
  1201  
  1202      /**
  1203       * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
  1204       * Use along with {totalSupply} to enumerate all tokens.
  1205       */
  1206      function tokenByIndex(uint256 index) external view returns (uint256);
  1207  }
  1208  
  1209  // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/IERC721Metadata.sol
  1210  
  1211  
  1212  // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
  1213  
  1214  pragma solidity ^0.8.0;
  1215  
  1216  
  1217  /**
  1218   * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
  1219   * @dev See https://eips.ethereum.org/EIPS/eip-721
  1220   */
  1221  interface IERC721Metadata is IERC721 {
  1222      /**
  1223       * @dev Returns the token collection name.
  1224       */
  1225      function name() external view returns (string memory);
  1226  
  1227      /**
  1228       * @dev Returns the token collection symbol.
  1229       */
  1230      function symbol() external view returns (string memory);
  1231  
  1232      /**
  1233       * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
  1234       */
  1235      function tokenURI(uint256 tokenId) external view returns (string memory);
  1236  }
  1237  
  1238  // File: Contracts/babynft.sol
  1239  
  1240  
  1241  pragma solidity ^0.8.0;
  1242  
  1243  
  1244  
  1245  
  1246  
  1247  
  1248  
  1249  
  1250  
  1251  
  1252  
  1253  
  1254  /**
  1255   * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
  1256   * the Metadata extension, but not including the Enumerable extension, which is available separately as
  1257   * {ERC721Enumerable}.
  1258   */
  1259  interface erc20_{
  1260  
  1261    function mint(address add, uint amount)external;
  1262  
  1263  }
  1264  
  1265  
  1266  
  1267  contract babynft is Context, ERC165, IERC721, IERC721Metadata ,Ownable,IERC721Enumerable{
  1268      using Address for address;
  1269      using Strings for uint256;
  1270      using Counters for Counters.Counter;
  1271  
  1272      Counters.Counter private _tokenIds;
  1273  
  1274      uint counter;
  1275      uint _counter;
  1276      uint256 public maxSupply = 5555;
  1277  
  1278      erc20_ _erc20;
  1279  
  1280  
  1281      string public baseURI_ = "ipfs://QmQKqVLvzoqH2CaVGqSf1UCghGSSV4X6FT3bMFTWN2C6cF/";
  1282      string public baseExtension = ".json";
  1283  
  1284  
  1285      // Token name
  1286      string private _name;
  1287  
  1288      // Token symbol
  1289      string private _symbol;
  1290  
  1291  
  1292  
  1293      // Mapping from token ID to owner address
  1294      mapping(uint256 => address) private _owners;
  1295  
  1296      // Mapping owner address to token count
  1297      mapping(address => uint256) private _balances;
  1298  
  1299      // Mapping from token ID to approved address
  1300      mapping(uint256 => address) private _tokenApprovals;
  1301  
  1302      // Mapping from owner to operator approvals
  1303      mapping(address => mapping(address => bool)) private _operatorApprovals;
  1304  
  1305      mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
  1306  
  1307      // Mapping from token ID to index of the owner tokens list
  1308      mapping(uint256 => uint256) private _ownedTokensIndex;
  1309  
  1310      // Array with all token ids, used for enumeration
  1311      uint256[] private _allTokens;
  1312  
  1313      // Mapping from token id to position in the allTokens array
  1314      mapping(uint256 => uint256) private _allTokensIndex;
  1315  
  1316      mapping(uint => mapping(address => uint)) private idtostartingtimet;
  1317  
  1318      mapping (address =>bool) onlyapprovedcontractaddress;
  1319  
  1320  
  1321      /**
  1322       * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
  1323       */
  1324      constructor(string memory name_, string memory symbol_) {
  1325          _name = name_;
  1326          _symbol = symbol_;
  1327  
  1328      }
  1329  
  1330        /**
  1331       * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
  1332       */
  1333      function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
  1334          require(index < balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
  1335          return _ownedTokens[owner][index];
  1336      }
  1337  
  1338      /**
  1339       * @dev See {IERC721Enumerable-totalSupply}.
  1340       */
  1341      function totalSupply() public view virtual override returns (uint256) {
  1342          return _allTokens.length;
  1343      }
  1344  
  1345      /**
  1346       * @dev See {IERC721Enumerable-tokenByIndex}.
  1347       */
  1348      function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
  1349          require(index < totalSupply(), "ERC721Enumerable: global index out of bounds");
  1350          return _allTokens[index];
  1351      }
  1352  
  1353  
  1354      function _beforeTokenTransfer(
  1355          address from,
  1356          address to,
  1357          uint256 tokenId
  1358      ) internal virtual  {
  1359  
  1360  
  1361          if (from == address(0)) {
  1362              _addTokenToAllTokensEnumeration(tokenId);
  1363          } else if (from != to) {
  1364              _removeTokenFromOwnerEnumeration(from, tokenId);
  1365          }
  1366          if (to == address(0)) {
  1367              _removeTokenFromAllTokensEnumeration(tokenId);
  1368          } else if (to != from) {
  1369              _addTokenToOwnerEnumeration(to, tokenId);
  1370          }
  1371      }
  1372  
  1373  
  1374      function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
  1375          uint256 length = babynft.balanceOf(to);
  1376          _ownedTokens[to][length] = tokenId;
  1377          _ownedTokensIndex[tokenId] = length;
  1378      }
  1379  
  1380  
  1381      function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
  1382          _allTokensIndex[tokenId] = _allTokens.length;
  1383          _allTokens.push(tokenId);
  1384      }
  1385  
  1386  
  1387      function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
  1388          // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
  1389          // then delete the last slot (swap and pop).
  1390  
  1391          uint256 lastTokenIndex = babynft.balanceOf(from) - 1;
  1392          uint256 tokenIndex = _ownedTokensIndex[tokenId];
  1393  
  1394          // When the token to delete is the last token, the swap operation is unnecessary
  1395          if (tokenIndex != lastTokenIndex) {
  1396              uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
  1397  
  1398              _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
  1399              _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
  1400          }
  1401  
  1402          // This also deletes the contents at the last position of the array
  1403          delete _ownedTokensIndex[tokenId];
  1404          delete _ownedTokens[from][lastTokenIndex];
  1405      }
  1406  
  1407  
  1408      function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
  1409          // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
  1410          // then delete the last slot (swap and pop).
  1411  
  1412          uint256 lastTokenIndex = _allTokens.length - 1;
  1413          uint256 tokenIndex = _allTokensIndex[tokenId];
  1414  
  1415          // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
  1416          // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
  1417          // an 'if' statement (like in _removeTokenFromOwnerEnumeration)
  1418          uint256 lastTokenId = _allTokens[lastTokenIndex];
  1419  
  1420          _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
  1421          _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
  1422  
  1423          // This also deletes the contents at the last position of the array
  1424          delete _allTokensIndex[tokenId];
  1425          _allTokens.pop();
  1426      }
  1427  
  1428      /**
  1429       * @dev See {IERC165-supportsInterface}.
  1430       */
  1431      function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
  1432          return
  1433              interfaceId == type(IERC721).interfaceId ||
  1434              interfaceId == type(IERC721Metadata).interfaceId ||
  1435              super.supportsInterface(interfaceId);
  1436      }
  1437  
  1438      /**
  1439       * @dev See {IERC721-balanceOf}.
  1440       */
  1441      function balanceOf(address owner) public view virtual override returns (uint256) {
  1442          require(owner != address(0), "ERC721: balance query for the zero address");
  1443          return _balances[owner];
  1444      }
  1445  
  1446      /**
  1447       * @dev See {IERC721-ownerOf}.
  1448       */
  1449      function ownerOf(uint256 tokenId) public view virtual override returns (address) {
  1450          address owner = _owners[tokenId];
  1451          require(owner != address(0), "ERC721: owner query for nonexistent token");
  1452          return owner;
  1453      }
  1454  
  1455      /**
  1456       * @dev See {IERC721Metadata-name}.
  1457       */
  1458      function name() public view virtual override returns (string memory) {
  1459          return _name;
  1460      }
  1461  
  1462      /**
  1463       * @dev See {IERC721Metadata-symbol}.
  1464       */
  1465      function symbol() public view virtual override returns (string memory) {
  1466          return _symbol;
  1467      }
  1468  
  1469      /**
  1470       * @dev See {IERC721Metadata-tokenURI}.
  1471       */
  1472      function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
  1473          require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
  1474  
  1475          string memory baseURI = _baseURI();
  1476          return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
  1477      }
  1478  
  1479      /**
  1480       * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
  1481       * token will be the concatenation of the `baseURI` and the `tokenId`. Empty
  1482       * by default, can be overriden in child contracts.
  1483       */
  1484      function _baseURI() internal view virtual returns (string memory) {
  1485          return baseURI_;
  1486      }
  1487  
  1488      function setapprovedcontractaddress(address add)external {
  1489          require(counter<1, "already called");
  1490          onlyapprovedcontractaddress[add] =true;
  1491          counter+=1;
  1492      }
  1493  
  1494      function setmaxsupply(uint amount)public onlyOwner {
  1495          maxSupply= amount;
  1496      }
  1497  
  1498      function mint(address _to) public  {
  1499       require(onlyapprovedcontractaddress[msg.sender] ==true, "you are not approved  to mint");
  1500        require( totalSupply() <= maxSupply);
  1501          if (_tokenIds.current()==0){
  1502              _tokenIds.increment();
  1503          }
  1504  
  1505  
  1506          uint256 newTokenID = _tokenIds.current();
  1507          _safeMint(_to, newTokenID);
  1508          _tokenIds.increment();
  1509  
  1510      }
  1511  
  1512  
  1513  
  1514      function approve(address to, uint256 tokenId) public virtual override {
  1515          address owner = babynft.ownerOf(tokenId);
  1516          require(to != owner, "ERC721: approval to current owner");
  1517  
  1518          require(
  1519              _msgSender() == owner || isApprovedForAll(owner, _msgSender()),
  1520              "ERC721: approve caller is not owner nor approved for all"
  1521          );
  1522  
  1523          _approve(to, tokenId);
  1524      }
  1525  
  1526      /**
  1527       * @dev See {IERC721-getApproved}.
  1528       */
  1529  
  1530       function setBaseURI(string memory _newBaseURI) public onlyOwner {
  1531          baseURI_ = _newBaseURI;
  1532      }
  1533  
  1534  
  1535      function getApproved(uint256 tokenId) public view virtual override returns (address) {
  1536          require(_exists(tokenId), "ERC721: approved query for nonexistent token");
  1537  
  1538          return _tokenApprovals[tokenId];
  1539      }
  1540  
  1541      /**
  1542       * @dev See {IERC721-setApprovalForAll}.
  1543       */
  1544      function setApprovalForAll(address operator, bool approved) public virtual override {
  1545          _setApprovalForAll(_msgSender(), operator, approved);
  1546      }
  1547  
  1548      /**
  1549       * @dev See {IERC721-isApprovedForAll}.
  1550       */
  1551      function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
  1552          return _operatorApprovals[owner][operator];
  1553      }
  1554  
  1555      /**
  1556       * @dev See {IERC721-transferFrom}.
  1557       */
  1558      function transferFrom(
  1559          address from,
  1560          address to,
  1561          uint256 tokenId
  1562      ) public virtual override {
  1563          //solhint-disable-next-line max-line-length
  1564          require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
  1565  
  1566          _transfer(from, to, tokenId);
  1567      }
  1568  
  1569      /**
  1570       * @dev See {IERC721-safeTransferFrom}.
  1571       */
  1572      function safeTransferFrom(
  1573          address from,
  1574          address to,
  1575          uint256 tokenId
  1576      ) public virtual override {
  1577          safeTransferFrom(from, to, tokenId, "");
  1578      }
  1579  
  1580      /**
  1581       * @dev See {IERC721-safeTransferFrom}.
  1582       */
  1583      function safeTransferFrom(
  1584          address from,
  1585          address to,
  1586          uint256 tokenId,
  1587          bytes memory _data
  1588      ) public virtual override {
  1589          require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
  1590          _safeTransfer(from, to, tokenId, _data);
  1591      }
  1592  
  1593      /**
  1594       * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
  1595       * are aware of the ERC721 protocol to prevent tokens from being forever locked.
  1596       *
  1597       * `_data` is additional data, it has no specified format and it is sent in call to `to`.
  1598       *
  1599       * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
  1600       * implement alternative mechanisms to perform token transfer, such as signature-based.
  1601       *
  1602       * Requirements:
  1603       *
  1604       * - `from` cannot be the zero address.
  1605       * - `to` cannot be the zero address.
  1606       * - `tokenId` token must exist and be owned by `from`.
  1607       * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
  1608       *
  1609       * Emits a {Transfer} event.
  1610       */
  1611      function _safeTransfer(
  1612          address from,
  1613          address to,
  1614          uint256 tokenId,
  1615          bytes memory _data
  1616      ) internal virtual {
  1617          _transfer(from, to, tokenId);
  1618          require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
  1619      }
  1620  
  1621      /**
  1622       * @dev Returns whether `tokenId` exists.
  1623       *
  1624       * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
  1625       *
  1626       * Tokens start existing when they are minted (`_mint`),
  1627       * and stop existing when they are burned (`_burn`).
  1628       */
  1629      function _exists(uint256 tokenId) internal view virtual returns (bool) {
  1630          return _owners[tokenId] != address(0);
  1631      }
  1632  
  1633      /**
  1634       * @dev Returns whether `spender` is allowed to manage `tokenId`.
  1635       *
  1636       * Requirements:
  1637       *
  1638       * - `tokenId` must exist.
  1639       */
  1640      function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
  1641          require(_exists(tokenId), "ERC721: operator query for nonexistent token");
  1642          address owner = babynft.ownerOf(tokenId);
  1643          return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
  1644      }
  1645  
  1646      /**
  1647       * @dev Safely mints `tokenId` and transfers it to `to`.
  1648       *
  1649       * Requirements:
  1650       *
  1651       * - `tokenId` must not exist.
  1652       * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
  1653       *
  1654       * Emits a {Transfer} event.
  1655       */
  1656      function _safeMint(address to, uint256 tokenId) internal virtual {
  1657          _safeMint(to, tokenId, "");
  1658      }
  1659  
  1660      /**
  1661       * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
  1662       * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
  1663       */
  1664      function _safeMint(
  1665          address to,
  1666          uint256 tokenId,
  1667          bytes memory _data
  1668      ) internal virtual {
  1669          _mint(to, tokenId);
  1670          require(
  1671              _checkOnERC721Received(address(0), to, tokenId, _data),
  1672              "ERC721: transfer to non ERC721Receiver implementer"
  1673          );
  1674      }
  1675  
  1676      /**
  1677       * @dev Mints `tokenId` and transfers it to `to`.
  1678       *
  1679       * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
  1680       *
  1681       * Requirements:
  1682       *
  1683       * - `tokenId` must not exist.
  1684       * - `to` cannot be the zero address.
  1685       *
  1686       * Emits a {Transfer} event.
  1687       */
  1688     function _mint(address to, uint256 tokenId) internal virtual {
  1689          require(to != address(0), "ERC721: mint to the zero address");
  1690          require(!_exists(tokenId), "ERC721: token already minted");
  1691  
  1692          _beforeTokenTransfer(address(0), to, tokenId);
  1693  
  1694          _balances[to] += 1;
  1695          _owners[tokenId] = to;
  1696          idtostartingtimet[tokenId][to]=block.timestamp;
  1697  
  1698          // totalSupply+=1;
  1699  
  1700          emit Transfer(address(0), to, tokenId);
  1701  
  1702          _afterTokenTransfer(address(0), to, tokenId);
  1703      }
  1704  
  1705      function seterc20address(address add)external {
  1706          require(_counter<1, "already called this function");
  1707           _erc20= erc20_(add);
  1708           _counter++;
  1709      }
  1710  
  1711        function walletofNFT(address _owner)
  1712          public
  1713          view
  1714          returns (uint256[] memory)
  1715      {
  1716          uint256 ownerTokenCount = balanceOf(_owner);
  1717          uint256[] memory tokenIds = new uint256[](ownerTokenCount);
  1718          for (uint256 i; i < ownerTokenCount; i++) {
  1719              tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
  1720          }
  1721          return tokenIds;
  1722      }
  1723  
  1724  
  1725      function checkrewardbal(address add)public view returns(uint){
  1726  
  1727          uint256 ownerTokenCount = balanceOf(add);
  1728             uint256[] memory tokenIds = new uint256[](ownerTokenCount);
  1729           tokenIds= walletofNFT(add);
  1730  
  1731            uint current;
  1732            uint reward;
  1733            uint rewardbal;
  1734           for (uint i ;i<ownerTokenCount; i++){
  1735  
  1736               if (idtostartingtimet[tokenIds[i]][add]>0 ){
  1737             current = block.timestamp - idtostartingtimet[tokenIds[i]][add];
  1738               reward = ((5*10**18)*current)/86400;
  1739              rewardbal+=reward;
  1740  
  1741             }
  1742          }
  1743  
  1744          return rewardbal;
  1745      }
  1746  
  1747      function claimreward(address add) public {
  1748            require(balanceOf(add)>0, "not qualified for reward");
  1749           uint256 ownerTokenCount = balanceOf(add);
  1750             uint256[] memory tokenIds = new uint256[](ownerTokenCount);
  1751           tokenIds= walletofNFT(add);
  1752  
  1753            uint current;
  1754            uint reward;
  1755            uint rewardbal;
  1756           for (uint i ;i<ownerTokenCount; i++){
  1757  
  1758               if (idtostartingtimet[tokenIds[i]][add]>0 ){
  1759             current = block.timestamp - idtostartingtimet[tokenIds[i]][add];
  1760               reward = ((5*10**18)*current)/86400;
  1761              rewardbal+=reward;
  1762            idtostartingtimet[tokenIds[i]][add]=block.timestamp;
  1763             }
  1764          }
  1765  
  1766            _erc20.mint(add,rewardbal);
  1767  
  1768  
  1769      }
  1770  
  1771      /**
  1772       * @dev Destroys `tokenId`.
  1773       * The approval is cleared when the token is burned.
  1774       *
  1775       * Requirements:
  1776       *
  1777       * - `tokenId` must exist.
  1778       *
  1779       * Emits a {Transfer} event.
  1780       */
  1781      function _burn(uint256 tokenId) internal virtual {
  1782          address owner = babynft.ownerOf(tokenId);
  1783  
  1784          _beforeTokenTransfer(owner, address(0), tokenId);
  1785  
  1786          // Clear approvals
  1787          _approve(address(0), tokenId);
  1788  
  1789          _balances[owner] -= 1;
  1790          delete _owners[tokenId];
  1791  
  1792          emit Transfer(owner, address(0), tokenId);
  1793  
  1794          _afterTokenTransfer(owner, address(0), tokenId);
  1795      }
  1796  
  1797      /**
  1798       * @dev Transfers `tokenId` from `from` to `to`.
  1799       *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
  1800       *
  1801       * Requirements:
  1802       *
  1803       * - `to` cannot be the zero address.
  1804       * - `tokenId` token must be owned by `from`.
  1805       *
  1806       * Emits a {Transfer} event.
  1807       */
  1808         function _transfer(
  1809          address from,
  1810          address to,
  1811          uint256 tokenId
  1812      ) internal virtual {
  1813          require(babynft.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
  1814          require(to != address(0), "ERC721: transfer to the zero address");
  1815  
  1816          _beforeTokenTransfer(from, to, tokenId);
  1817  
  1818          // Clear approvals from the previous owner
  1819          _approve(address(0), tokenId);
  1820  
  1821          _balances[from] -= 1;
  1822          _balances[to] += 1;
  1823          _owners[tokenId] = to;
  1824          idtostartingtimet[tokenId][to]=block.timestamp;
  1825          idtostartingtimet[tokenId][from]=0;
  1826  
  1827  
  1828          emit Transfer(from, to, tokenId);
  1829  
  1830          _afterTokenTransfer(from, to, tokenId);
  1831      }
  1832  
  1833      /**
  1834       * @dev Approve `to` to operate on `tokenId`
  1835       *
  1836       * Emits a {Approval} event.
  1837       */
  1838      function _approve(address to, uint256 tokenId) internal virtual {
  1839          _tokenApprovals[tokenId] = to;
  1840          emit Approval(babynft.ownerOf(tokenId), to, tokenId);
  1841      }
  1842  
  1843      /**
  1844       * @dev Approve `operator` to operate on all of `owner` tokens
  1845       *
  1846       * Emits a {ApprovalForAll} event.
  1847       */
  1848      function _setApprovalForAll(
  1849          address owner,
  1850          address operator,
  1851          bool approved
  1852      ) internal virtual {
  1853          require(owner != operator, "ERC721: approve to caller");
  1854          _operatorApprovals[owner][operator] = approved;
  1855          emit ApprovalForAll(owner, operator, approved);
  1856      }
  1857  
  1858      /**
  1859       * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
  1860       * The call is not executed if the target address is not a contract.
  1861       *
  1862       * @param from address representing the previous owner of the given token ID
  1863       * @param to target address that will receive the tokens
  1864       * @param tokenId uint256 ID of the token to be transferred
  1865       * @param _data bytes optional data to send along with the call
  1866       * @return bool whether the call correctly returned the expected magic value
  1867       */
  1868      function _checkOnERC721Received(
  1869          address from,
  1870          address to,
  1871          uint256 tokenId,
  1872          bytes memory _data
  1873      ) private returns (bool) {
  1874          if (to.isContract()) {
  1875              try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
  1876                  return retval == IERC721Receiver.onERC721Received.selector;
  1877              } catch (bytes memory reason) {
  1878                  if (reason.length == 0) {
  1879                      revert("ERC721: transfer to non ERC721Receiver implementer");
  1880                  } else {
  1881                      assembly {
  1882                          revert(add(32, reason), mload(reason))
  1883                      }
  1884                  }
  1885              }
  1886          } else {
  1887              return true;
  1888          }
  1889      }
  1890  
  1891      /**
  1892       * @dev Hook that is called before any token transfer. This includes minting
  1893       * and burning.
  1894       *
  1895       * Calling conditions:
  1896       *
  1897       * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
  1898       * transferred to `to`.
  1899       * - When `from` is zero, `tokenId` will be minted for `to`.
  1900       * - When `to` is zero, ``from``'s `tokenId` will be burned.
  1901       * - `from` and `to` are never both zero.
  1902       *
  1903       * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
  1904       */
  1905      // function _beforeTokenTransfer(
  1906      //     address from,
  1907      //     address to,
  1908      //     uint256 tokenId
  1909      // ) internal virtual {}
  1910  
  1911      /**
  1912       * @dev Hook that is called after any transfer of tokens. This includes
  1913       * minting and burning.
  1914       *
  1915       * Calling conditions:
  1916       *
  1917       * - when `from` and `to` are both non-zero.
  1918       * - `from` and `to` are never both zero.
  1919       *
  1920       * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
  1921       */
  1922      function _afterTokenTransfer(
  1923          address from,
  1924          address to,
  1925          uint256 tokenId
  1926      ) internal virtual {}
  1927  }
  1928  // File: Contracts/ancientnft.sol
  1929  
  1930  
  1931  pragma solidity ^0.8.0;
  1932  
  1933  
  1934  
  1935  
  1936  
  1937  
  1938  
  1939  
  1940  
  1941  
  1942  
  1943  
  1944  /**
  1945   * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
  1946   * the Metadata extension, but not including the Enumerable extension, which is available separately as
  1947   * {ERC721Enumerable}.
  1948   */
  1949  interface erc20{
  1950  
  1951    function mint(address add, uint amount)external;
  1952  
  1953  }
  1954  
  1955  
  1956  
  1957  contract ancientnft is Context, ERC165, IERC721, IERC721Metadata ,Ownable,IERC721Enumerable{
  1958      using Address for address;
  1959      using Strings for uint256;
  1960      using Counters for Counters.Counter;
  1961  
  1962      Counters.Counter private _tokenIds;
  1963  
  1964      uint counter;
  1965      uint _counter;
  1966  
  1967      erc20 _erc20;
  1968  
  1969  
  1970      string public baseURI_ = "ipfs://QmYDwia8r68Mp3EWhmNtfVJA6FxYn52UMDNvkSaSUwtufU/";
  1971      string public baseExtension = ".json";
  1972  
  1973  
  1974      // Token name
  1975      string private _name;
  1976  
  1977      // Token symbol
  1978      string private _symbol;
  1979  
  1980  
  1981  
  1982      // Mapping from token ID to owner address
  1983      mapping(uint256 => address) private _owners;
  1984  
  1985      // Mapping owner address to token count
  1986      mapping(address => uint256) private _balances;
  1987  
  1988      // Mapping from token ID to approved address
  1989      mapping(uint256 => address) private _tokenApprovals;
  1990  
  1991      // Mapping from owner to operator approvals
  1992      mapping(address => mapping(address => bool)) private _operatorApprovals;
  1993  
  1994      mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
  1995  
  1996      // Mapping from token ID to index of the owner tokens list
  1997      mapping(uint256 => uint256) private _ownedTokensIndex;
  1998  
  1999      // Array with all token ids, used for enumeration
  2000      uint256[] private _allTokens;
  2001  
  2002      // Mapping from token id to position in the allTokens array
  2003      mapping(uint256 => uint256) private _allTokensIndex;
  2004  
  2005      mapping(uint => mapping(address => uint)) private idtostartingtimet;
  2006  
  2007      mapping (address =>bool) onlyapprovedcontractaddress;
  2008  
  2009  
  2010      /**
  2011       * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
  2012       */
  2013      constructor(string memory name_, string memory symbol_) {
  2014          _name = name_;
  2015          _symbol = symbol_;
  2016      }
  2017  
  2018        /**
  2019       * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
  2020       */
  2021      function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
  2022          require(index < balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
  2023          return _ownedTokens[owner][index];
  2024      }
  2025  
  2026      /**
  2027       * @dev See {IERC721Enumerable-totalSupply}.
  2028       */
  2029      function totalSupply() public view virtual override returns (uint256) {
  2030          return _allTokens.length;
  2031      }
  2032  
  2033      /**
  2034       * @dev See {IERC721Enumerable-tokenByIndex}.
  2035       */
  2036      function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
  2037          require(index < totalSupply(), "ERC721Enumerable: global index out of bounds");
  2038          return _allTokens[index];
  2039      }
  2040  
  2041  
  2042      function _beforeTokenTransfer(
  2043          address from,
  2044          address to,
  2045          uint256 tokenId
  2046      ) internal virtual  {
  2047  
  2048  
  2049          if (from == address(0)) {
  2050              _addTokenToAllTokensEnumeration(tokenId);
  2051          } else if (from != to) {
  2052              _removeTokenFromOwnerEnumeration(from, tokenId);
  2053          }
  2054          if (to == address(0)) {
  2055              _removeTokenFromAllTokensEnumeration(tokenId);
  2056          } else if (to != from) {
  2057              _addTokenToOwnerEnumeration(to, tokenId);
  2058          }
  2059      }
  2060  
  2061  
  2062      function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
  2063          uint256 length = ancientnft.balanceOf(to);
  2064          _ownedTokens[to][length] = tokenId;
  2065          _ownedTokensIndex[tokenId] = length;
  2066      }
  2067  
  2068  
  2069      function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
  2070          _allTokensIndex[tokenId] = _allTokens.length;
  2071          _allTokens.push(tokenId);
  2072      }
  2073  
  2074  
  2075      function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
  2076          // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
  2077          // then delete the last slot (swap and pop).
  2078  
  2079          uint256 lastTokenIndex = ancientnft.balanceOf(from) - 1;
  2080          uint256 tokenIndex = _ownedTokensIndex[tokenId];
  2081  
  2082          // When the token to delete is the last token, the swap operation is unnecessary
  2083          if (tokenIndex != lastTokenIndex) {
  2084              uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
  2085  
  2086              _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
  2087              _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
  2088          }
  2089  
  2090          // This also deletes the contents at the last position of the array
  2091          delete _ownedTokensIndex[tokenId];
  2092          delete _ownedTokens[from][lastTokenIndex];
  2093      }
  2094  
  2095  
  2096      function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
  2097          // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
  2098          // then delete the last slot (swap and pop).
  2099  
  2100          uint256 lastTokenIndex = _allTokens.length - 1;
  2101          uint256 tokenIndex = _allTokensIndex[tokenId];
  2102  
  2103          // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
  2104          // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
  2105          // an 'if' statement (like in _removeTokenFromOwnerEnumeration)
  2106          uint256 lastTokenId = _allTokens[lastTokenIndex];
  2107  
  2108          _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
  2109          _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
  2110  
  2111          // This also deletes the contents at the last position of the array
  2112          delete _allTokensIndex[tokenId];
  2113          _allTokens.pop();
  2114      }
  2115  
  2116      /**
  2117       * @dev See {IERC165-supportsInterface}.
  2118       */
  2119      function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
  2120          return
  2121              interfaceId == type(IERC721).interfaceId ||
  2122              interfaceId == type(IERC721Metadata).interfaceId ||
  2123              super.supportsInterface(interfaceId);
  2124      }
  2125  
  2126      /**
  2127       * @dev See {IERC721-balanceOf}.
  2128       */
  2129      function balanceOf(address owner) public view virtual override returns (uint256) {
  2130          require(owner != address(0), "ERC721: balance query for the zero address");
  2131          return _balances[owner];
  2132      }
  2133  
  2134      /**
  2135       * @dev See {IERC721-ownerOf}.
  2136       */
  2137      function ownerOf(uint256 tokenId) public view virtual override returns (address) {
  2138          address owner = _owners[tokenId];
  2139          require(owner != address(0), "ERC721: owner query for nonexistent token");
  2140          return owner;
  2141      }
  2142  
  2143      /**
  2144       * @dev See {IERC721Metadata-name}.
  2145       */
  2146      function name() public view virtual override returns (string memory) {
  2147          return _name;
  2148      }
  2149  
  2150      /**
  2151       * @dev See {IERC721Metadata-symbol}.
  2152       */
  2153      function symbol() public view virtual override returns (string memory) {
  2154          return _symbol;
  2155      }
  2156  
  2157      /**
  2158       * @dev See {IERC721Metadata-tokenURI}.
  2159       */
  2160      function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
  2161          require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
  2162  
  2163          string memory baseURI = _baseURI();
  2164          return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
  2165      }
  2166  
  2167      /**
  2168       * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
  2169       * token will be the concatenation of the `baseURI` and the `tokenId`. Empty
  2170       * by default, can be overriden in child contracts.
  2171       */
  2172      function _baseURI() internal view virtual returns (string memory) {
  2173          return baseURI_;
  2174      }
  2175  
  2176      function setapprovedcontractaddress(address add)external {
  2177          require(counter<1, "already called");
  2178          onlyapprovedcontractaddress[add] =true;
  2179          counter+=1;
  2180      }
  2181  
  2182      function mint(address _to) public  {
  2183      require(onlyapprovedcontractaddress[msg.sender] ==true, "you are not approved  to mint");
  2184          if (_tokenIds.current()==0){
  2185              _tokenIds.increment();
  2186          }
  2187  
  2188  
  2189          uint256 newTokenID = _tokenIds.current();
  2190          _safeMint(_to, newTokenID);
  2191          _tokenIds.increment();
  2192  
  2193      }
  2194  
  2195  
  2196  
  2197      function approve(address to, uint256 tokenId) public virtual override {
  2198          address owner = ancientnft.ownerOf(tokenId);
  2199          require(to != owner, "ERC721: approval to current owner");
  2200  
  2201          require(
  2202              _msgSender() == owner || isApprovedForAll(owner, _msgSender()),
  2203              "ERC721: approve caller is not owner nor approved for all"
  2204          );
  2205  
  2206          _approve(to, tokenId);
  2207      }
  2208  
  2209      /**
  2210       * @dev See {IERC721-getApproved}.
  2211       */
  2212  
  2213       function setBaseURI(string memory _newBaseURI) public onlyOwner {
  2214          baseURI_ = _newBaseURI;
  2215      }
  2216  
  2217  
  2218      function getApproved(uint256 tokenId) public view virtual override returns (address) {
  2219          require(_exists(tokenId), "ERC721: approved query for nonexistent token");
  2220  
  2221          return _tokenApprovals[tokenId];
  2222      }
  2223  
  2224      /**
  2225       * @dev See {IERC721-setApprovalForAll}.
  2226       */
  2227      function setApprovalForAll(address operator, bool approved) public virtual override {
  2228          _setApprovalForAll(_msgSender(), operator, approved);
  2229      }
  2230  
  2231      /**
  2232       * @dev See {IERC721-isApprovedForAll}.
  2233       */
  2234      function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
  2235          return _operatorApprovals[owner][operator];
  2236      }
  2237  
  2238      /**
  2239       * @dev See {IERC721-transferFrom}.
  2240       */
  2241      function transferFrom(
  2242          address from,
  2243          address to,
  2244          uint256 tokenId
  2245      ) public virtual override {
  2246          //solhint-disable-next-line max-line-length
  2247          require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
  2248  
  2249          _transfer(from, to, tokenId);
  2250      }
  2251  
  2252      /**
  2253       * @dev See {IERC721-safeTransferFrom}.
  2254       */
  2255      function safeTransferFrom(
  2256          address from,
  2257          address to,
  2258          uint256 tokenId
  2259      ) public virtual override {
  2260          safeTransferFrom(from, to, tokenId, "");
  2261      }
  2262  
  2263      /**
  2264       * @dev See {IERC721-safeTransferFrom}.
  2265       */
  2266      function safeTransferFrom(
  2267          address from,
  2268          address to,
  2269          uint256 tokenId,
  2270          bytes memory _data
  2271      ) public virtual override {
  2272          require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
  2273          _safeTransfer(from, to, tokenId, _data);
  2274      }
  2275  
  2276      /**
  2277       * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
  2278       * are aware of the ERC721 protocol to prevent tokens from being forever locked.
  2279       *
  2280       * `_data` is additional data, it has no specified format and it is sent in call to `to`.
  2281       *
  2282       * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
  2283       * implement alternative mechanisms to perform token transfer, such as signature-based.
  2284       *
  2285       * Requirements:
  2286       *
  2287       * - `from` cannot be the zero address.
  2288       * - `to` cannot be the zero address.
  2289       * - `tokenId` token must exist and be owned by `from`.
  2290       * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
  2291       *
  2292       * Emits a {Transfer} event.
  2293       */
  2294      function _safeTransfer(
  2295          address from,
  2296          address to,
  2297          uint256 tokenId,
  2298          bytes memory _data
  2299      ) internal virtual {
  2300          _transfer(from, to, tokenId);
  2301          require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
  2302      }
  2303  
  2304      /**
  2305       * @dev Returns whether `tokenId` exists.
  2306       *
  2307       * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
  2308       *
  2309       * Tokens start existing when they are minted (`_mint`),
  2310       * and stop existing when they are burned (`_burn`).
  2311       */
  2312      function _exists(uint256 tokenId) internal view virtual returns (bool) {
  2313          return _owners[tokenId] != address(0);
  2314      }
  2315  
  2316      /**
  2317       * @dev Returns whether `spender` is allowed to manage `tokenId`.
  2318       *
  2319       * Requirements:
  2320       *
  2321       * - `tokenId` must exist.
  2322       */
  2323      function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
  2324          require(_exists(tokenId), "ERC721: operator query for nonexistent token");
  2325          address owner = ancientnft.ownerOf(tokenId);
  2326          return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
  2327      }
  2328  
  2329      /**
  2330       * @dev Safely mints `tokenId` and transfers it to `to`.
  2331       *
  2332       * Requirements:
  2333       *
  2334       * - `tokenId` must not exist.
  2335       * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
  2336       *
  2337       * Emits a {Transfer} event.
  2338       */
  2339      function _safeMint(address to, uint256 tokenId) internal virtual {
  2340          _safeMint(to, tokenId, "");
  2341      }
  2342  
  2343      /**
  2344       * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
  2345       * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
  2346       */
  2347      function _safeMint(
  2348          address to,
  2349          uint256 tokenId,
  2350          bytes memory _data
  2351      ) internal virtual {
  2352          _mint(to, tokenId);
  2353          require(
  2354              _checkOnERC721Received(address(0), to, tokenId, _data),
  2355              "ERC721: transfer to non ERC721Receiver implementer"
  2356          );
  2357      }
  2358  
  2359      /**
  2360       * @dev Mints `tokenId` and transfers it to `to`.
  2361       *
  2362       * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
  2363       *
  2364       * Requirements:
  2365       *
  2366       * - `tokenId` must not exist.
  2367       * - `to` cannot be the zero address.
  2368       *
  2369       * Emits a {Transfer} event.
  2370       */
  2371     function _mint(address to, uint256 tokenId) internal virtual {
  2372          require(to != address(0), "ERC721: mint to the zero address");
  2373          require(!_exists(tokenId), "ERC721: token already minted");
  2374  
  2375          _beforeTokenTransfer(address(0), to, tokenId);
  2376  
  2377          _balances[to] += 1;
  2378          _owners[tokenId] = to;
  2379          idtostartingtimet[tokenId][to]=block.timestamp;
  2380  
  2381          // totalSupply+=1;
  2382  
  2383          emit Transfer(address(0), to, tokenId);
  2384  
  2385          _afterTokenTransfer(address(0), to, tokenId);
  2386      }
  2387  
  2388      function seterc20address(address add)external {
  2389          require(_counter<1, "already called this function");
  2390           _erc20= erc20(add);
  2391           _counter++;
  2392      }
  2393  
  2394        function walletofNFT(address _owner)
  2395          public
  2396          view
  2397          returns (uint256[] memory)
  2398      {
  2399          uint256 ownerTokenCount = balanceOf(_owner);
  2400          uint256[] memory tokenIds = new uint256[](ownerTokenCount);
  2401          for (uint256 i; i < ownerTokenCount; i++) {
  2402              tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
  2403          }
  2404          return tokenIds;
  2405      }
  2406  
  2407  
  2408      function checkrewardbal(address add)public view returns(uint){
  2409  
  2410          uint256 ownerTokenCount = balanceOf(add);
  2411             uint256[] memory tokenIds = new uint256[](ownerTokenCount);
  2412           tokenIds= walletofNFT(add);
  2413  
  2414            uint current;
  2415            uint reward;
  2416            uint rewardbal;
  2417           for (uint i ;i<ownerTokenCount; i++){
  2418  
  2419               if (idtostartingtimet[tokenIds[i]][add]>0 ){
  2420             current = block.timestamp - idtostartingtimet[tokenIds[i]][add];
  2421               reward = ((50*10**18)*current)/86400;
  2422              rewardbal+=reward;
  2423  
  2424             }
  2425          }
  2426  
  2427          return rewardbal;
  2428      }
  2429  
  2430      function claimreward(address add) public {
  2431            require(balanceOf(add)>0, "not qualified for reward");
  2432           uint256 ownerTokenCount = balanceOf(add);
  2433             uint256[] memory tokenIds = new uint256[](ownerTokenCount);
  2434           tokenIds= walletofNFT(add);
  2435  
  2436            uint current;
  2437            uint reward;
  2438            uint rewardbal;
  2439           for (uint i ;i<ownerTokenCount; i++){
  2440  
  2441               if (idtostartingtimet[tokenIds[i]][add]>0 ){
  2442             current = block.timestamp - idtostartingtimet[tokenIds[i]][add];
  2443               reward = ((50*10**18)*current)/86400;
  2444              rewardbal+=reward;
  2445            idtostartingtimet[tokenIds[i]][add]=block.timestamp;
  2446             }
  2447          }
  2448  
  2449            _erc20.mint(add,rewardbal);
  2450  
  2451  
  2452      }
  2453  
  2454      /**
  2455       * @dev Destroys `tokenId`.
  2456       * The approval is cleared when the token is burned.
  2457       *
  2458       * Requirements:
  2459       *
  2460       * - `tokenId` must exist.
  2461       *
  2462       * Emits a {Transfer} event.
  2463       */
  2464      function _burn(uint256 tokenId) internal virtual {
  2465          address owner = ancientnft.ownerOf(tokenId);
  2466  
  2467          _beforeTokenTransfer(owner, address(0), tokenId);
  2468  
  2469          // Clear approvals
  2470          _approve(address(0), tokenId);
  2471  
  2472          _balances[owner] -= 1;
  2473          delete _owners[tokenId];
  2474  
  2475          emit Transfer(owner, address(0), tokenId);
  2476  
  2477          _afterTokenTransfer(owner, address(0), tokenId);
  2478      }
  2479  
  2480      /**
  2481       * @dev Transfers `tokenId` from `from` to `to`.
  2482       *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
  2483       *
  2484       * Requirements:
  2485       *
  2486       * - `to` cannot be the zero address.
  2487       * - `tokenId` token must be owned by `from`.
  2488       *
  2489       * Emits a {Transfer} event.
  2490       */
  2491         function _transfer(
  2492          address from,
  2493          address to,
  2494          uint256 tokenId
  2495      ) internal virtual {
  2496          require(ancientnft.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
  2497          require(to != address(0), "ERC721: transfer to the zero address");
  2498  
  2499          _beforeTokenTransfer(from, to, tokenId);
  2500  
  2501          // Clear approvals from the previous owner
  2502          _approve(address(0), tokenId);
  2503  
  2504          _balances[from] -= 1;
  2505          _balances[to] += 1;
  2506          _owners[tokenId] = to;
  2507          idtostartingtimet[tokenId][to]=block.timestamp;
  2508          idtostartingtimet[tokenId][from]=0;
  2509  
  2510  
  2511          emit Transfer(from, to, tokenId);
  2512  
  2513          _afterTokenTransfer(from, to, tokenId);
  2514      }
  2515  
  2516      /**
  2517       * @dev Approve `to` to operate on `tokenId`
  2518       *
  2519       * Emits a {Approval} event.
  2520       */
  2521      function _approve(address to, uint256 tokenId) internal virtual {
  2522          _tokenApprovals[tokenId] = to;
  2523          emit Approval(ancientnft.ownerOf(tokenId), to, tokenId);
  2524      }
  2525  
  2526      /**
  2527       * @dev Approve `operator` to operate on all of `owner` tokens
  2528       *
  2529       * Emits a {ApprovalForAll} event.
  2530       */
  2531      function _setApprovalForAll(
  2532          address owner,
  2533          address operator,
  2534          bool approved
  2535      ) internal virtual {
  2536          require(owner != operator, "ERC721: approve to caller");
  2537          _operatorApprovals[owner][operator] = approved;
  2538          emit ApprovalForAll(owner, operator, approved);
  2539      }
  2540  
  2541      /**
  2542       * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
  2543       * The call is not executed if the target address is not a contract.
  2544       *
  2545       * @param from address representing the previous owner of the given token ID
  2546       * @param to target address that will receive the tokens
  2547       * @param tokenId uint256 ID of the token to be transferred
  2548       * @param _data bytes optional data to send along with the call
  2549       * @return bool whether the call correctly returned the expected magic value
  2550       */
  2551      function _checkOnERC721Received(
  2552          address from,
  2553          address to,
  2554          uint256 tokenId,
  2555          bytes memory _data
  2556      ) private returns (bool) {
  2557          if (to.isContract()) {
  2558              try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
  2559                  return retval == IERC721Receiver.onERC721Received.selector;
  2560              } catch (bytes memory reason) {
  2561                  if (reason.length == 0) {
  2562                      revert("ERC721: transfer to non ERC721Receiver implementer");
  2563                  } else {
  2564                      assembly {
  2565                          revert(add(32, reason), mload(reason))
  2566                      }
  2567                  }
  2568              }
  2569          } else {
  2570              return true;
  2571          }
  2572      }
  2573  
  2574      /**
  2575       * @dev Hook that is called before any token transfer. This includes minting
  2576       * and burning.
  2577       *
  2578       * Calling conditions:
  2579       *
  2580       * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
  2581       * transferred to `to`.
  2582       * - When `from` is zero, `tokenId` will be minted for `to`.
  2583       * - When `to` is zero, ``from``'s `tokenId` will be burned.
  2584       * - `from` and `to` are never both zero.
  2585       *
  2586       * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
  2587       */
  2588      // function _beforeTokenTransfer(
  2589      //     address from,
  2590      //     address to,
  2591      //     uint256 tokenId
  2592      // ) internal virtual {}
  2593  
  2594      /**
  2595       * @dev Hook that is called after any transfer of tokens. This includes
  2596       * minting and burning.
  2597       *
  2598       * Calling conditions:
  2599       *
  2600       * - when `from` and `to` are both non-zero.
  2601       * - `from` and `to` are never both zero.
  2602       *
  2603       * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
  2604       */
  2605      function _afterTokenTransfer(
  2606          address from,
  2607          address to,
  2608          uint256 tokenId
  2609      ) internal virtual {}
  2610  }
  2611  // File: Contracts/nft.sol
  2612  
  2613  
  2614  // OpenZeppelin Contracts v4.4.1 (token/ERC721/ERC721.sol)
  2615  
  2616  pragma solidity ^0.8.0;
  2617  
  2618  
  2619  
  2620  
  2621  
  2622  
  2623  
  2624  
  2625  
  2626  
  2627  
  2628  
  2629  
  2630  
  2631  
  2632  
  2633  
  2634  
  2635  contract ERC721  is Context, ERC165, IERC721, IERC721Metadata, Ownable, IERC721Enumerable {
  2636      using Address for address;
  2637      using Strings for uint256;
  2638      using Counters for Counters.Counter;
  2639  
  2640  
  2641  
  2642  
  2643      // Token name
  2644      string private _name;
  2645  
  2646      // Token symbol
  2647      string private _symbol;
  2648  
  2649      // uint public totalSupply;
  2650  
  2651      Counters.Counter private _tokenIds;
  2652  
  2653  
  2654  
  2655      string public baseURI_ = "ipfs://QmeWdrqHA32zQRjU9oKmsi6NDGdv1dpnyxRi3pcm27Dkqb/";
  2656      string public baseExtension = ".json";
  2657      uint256 public cost = 0.03 ether;
  2658      uint256 public maxSupply = 3333;
  2659      uint256 public maxMintAmount = 10;
  2660      bool public paused = false;
  2661  
  2662  
  2663  
  2664       // wallet addresses for claims
  2665      address private constant possumchsr69 = 0x31FbcD30AA07FBbeA5DB938cD534D1dA79E34985;
  2666      address private constant Jazzasaurus =
  2667          0xd848353706E5a26BAa6DD20265EDDe1e7047d9ba;
  2668      address private constant munheezy = 0xB6D2ac64BDc24f76417b95b410ACf47cE31AdD07;
  2669      address private constant _community =
  2670          0xe44CB360e48dA69fe75a78fD1649ccbd3CCf7AD1;
  2671  
  2672      mapping(uint => mapping(address => uint)) private idtostartingtimet;
  2673  
  2674  
  2675      mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
  2676  
  2677      // Mapping from token ID to index of the owner tokens list
  2678      mapping(uint256 => uint256) private _ownedTokensIndex;
  2679  
  2680      // Array with all token ids, used for enumeration
  2681      uint256[] private _allTokens;
  2682  
  2683      // Mapping from token id to position in the allTokens array
  2684      mapping(uint256 => uint256) private _allTokensIndex;
  2685  
  2686       mapping(address => mapping(uint256 => bool)) private _breeded;
  2687  
  2688       ERC20 _ERC20;
  2689       ancientnft _ancientnft;
  2690       babynft _babynft;
  2691  
  2692  
  2693  
  2694  
  2695  
  2696  
  2697      // Mapping from token ID to owner address
  2698      mapping(uint256 => address) private _owners;
  2699  
  2700      // Mapping owner address to token count
  2701      mapping(address => uint256) private _balances;
  2702  
  2703      // Mapping from token ID to approved address
  2704      mapping(uint256 => address) private _tokenApprovals;
  2705  
  2706      // Mapping from owner to operator approvals
  2707      mapping(address => mapping(address => bool)) private _operatorApprovals;
  2708  
  2709  
  2710  
  2711      constructor(string memory name_, string memory symbol_,string memory ERC20name_, string memory ERC20symbol_ ,uint ERC20amount,address ERC20owneraddress,string memory ancientnftname_, string memory ancientnftsymbol_,string memory babynftname_, string memory babynftsymbol_) {
  2712          _name = name_;
  2713          _symbol = symbol_;
  2714          mint(msg.sender, 10);
  2715          _ERC20= new ERC20(ERC20name_,ERC20symbol_,ERC20amount,ERC20owneraddress) ;
  2716  
  2717          _ancientnft = new ancientnft(ancientnftname_,ancientnftsymbol_);
  2718          _ancientnft.setapprovedcontractaddress(address(this));
  2719          _ancientnft.seterc20address(address(_ERC20));
  2720          _babynft= new  babynft(babynftname_,babynftsymbol_);
  2721          _babynft.setapprovedcontractaddress(address(this));
  2722          _babynft.seterc20address(address(_ERC20));
  2723          _ERC20.setapprovedcontractaddress(address(this),address(_ancientnft),address(_babynft));
  2724  
  2725      }
  2726  
  2727  
  2728      /**
  2729       * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
  2730       */
  2731      function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
  2732          require(index < balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
  2733          return _ownedTokens[owner][index];
  2734      }
  2735  
  2736      /**
  2737       * @dev See {IERC721Enumerable-totalSupply}.
  2738       */
  2739      function totalSupply() public view virtual override returns (uint256) {
  2740          return _allTokens.length;
  2741      }
  2742  
  2743      /**
  2744       * @dev See {IERC721Enumerable-tokenByIndex}.
  2745       */
  2746      function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
  2747          require(index < totalSupply(), "ERC721Enumerable: global index out of bounds");
  2748          return _allTokens[index];
  2749      }
  2750  
  2751      function pause() public onlyOwner  {
  2752          paused = !paused;
  2753  
  2754       }
  2755  
  2756      function checkPause() public view onlyOwner returns(bool) {
  2757          return paused;
  2758      }
  2759  
  2760      function _beforeTokenTransfer(
  2761          address from,
  2762          address to,
  2763          uint256 tokenId
  2764      ) internal virtual  {
  2765  
  2766  
  2767          if (from == address(0)) {
  2768              _addTokenToAllTokensEnumeration(tokenId);
  2769          } else if (from != to) {
  2770              _removeTokenFromOwnerEnumeration(from, tokenId);
  2771          }
  2772          if (to == address(0)) {
  2773              _removeTokenFromAllTokensEnumeration(tokenId);
  2774          } else if (to != from) {
  2775              _addTokenToOwnerEnumeration(to, tokenId);
  2776          }
  2777      }
  2778  
  2779  
  2780      function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
  2781          uint256 length = ERC721.balanceOf(to);
  2782          _ownedTokens[to][length] = tokenId;
  2783          _ownedTokensIndex[tokenId] = length;
  2784      }
  2785  
  2786  
  2787      function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
  2788          _allTokensIndex[tokenId] = _allTokens.length;
  2789          _allTokens.push(tokenId);
  2790      }
  2791  
  2792  
  2793      function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
  2794          // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
  2795          // then delete the last slot (swap and pop).
  2796  
  2797          uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
  2798          uint256 tokenIndex = _ownedTokensIndex[tokenId];
  2799  
  2800          // When the token to delete is the last token, the swap operation is unnecessary
  2801          if (tokenIndex != lastTokenIndex) {
  2802              uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
  2803  
  2804              _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
  2805              _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
  2806          }
  2807  
  2808          // This also deletes the contents at the last position of the array
  2809          delete _ownedTokensIndex[tokenId];
  2810          delete _ownedTokens[from][lastTokenIndex];
  2811      }
  2812  
  2813  
  2814      function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
  2815          // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
  2816          // then delete the last slot (swap and pop).
  2817  
  2818          uint256 lastTokenIndex = _allTokens.length - 1;
  2819          uint256 tokenIndex = _allTokensIndex[tokenId];
  2820  
  2821          // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
  2822          // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
  2823          // an 'if' statement (like in _removeTokenFromOwnerEnumeration)
  2824          uint256 lastTokenId = _allTokens[lastTokenIndex];
  2825  
  2826          _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
  2827          _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
  2828  
  2829          // This also deletes the contents at the last position of the array
  2830          delete _allTokensIndex[tokenId];
  2831          _allTokens.pop();
  2832      }
  2833  
  2834  
  2835      function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
  2836          return
  2837              interfaceId == type(IERC721).interfaceId ||
  2838              interfaceId == type(IERC721Metadata).interfaceId ||
  2839              super.supportsInterface(interfaceId);
  2840      }
  2841  
  2842  
  2843      function balanceOf(address owner) public view virtual override returns (uint256) {
  2844          require(owner != address(0), "ERC721: balance query for the zero address");
  2845          return _balances[owner];
  2846      }
  2847  
  2848  
  2849      function ownerOf(uint256 tokenId) public view virtual override returns (address) {
  2850          address owner = _owners[tokenId];
  2851          require(owner != address(0), "ERC721: owner query for nonexistent token");
  2852          return owner;
  2853      }
  2854  
  2855  
  2856      function name() public view virtual override returns (string memory) {
  2857          return _name;
  2858      }
  2859  
  2860  
  2861      function symbol() public view virtual override returns (string memory) {
  2862          return _symbol;
  2863      }
  2864  
  2865      /**
  2866       * @dev See {IERC721Metadata-tokenURI}.
  2867       */
  2868      function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
  2869          require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
  2870  
  2871          string memory baseURI = _baseURI();
  2872          return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
  2873      }
  2874  
  2875  
  2876      function _baseURI() internal view virtual returns (string memory) {
  2877          return baseURI_;
  2878      }
  2879  
  2880  
  2881      function approve(address to, uint256 tokenId) public virtual override {
  2882          address owner = ERC721.ownerOf(tokenId);
  2883          require(to != owner, "ERC721: approval to current owner");
  2884  
  2885          require(
  2886              _msgSender() == owner || isApprovedForAll(owner, _msgSender()),
  2887              "ERC721: approve caller is not owner nor approved for all"
  2888          );
  2889  
  2890          _approve(to, tokenId);
  2891      }
  2892  
  2893  
  2894      function getApproved(uint256 tokenId) public view virtual override returns (address) {
  2895          require(_exists(tokenId), "ERC721: approved query for nonexistent token");
  2896  
  2897          return _tokenApprovals[tokenId];
  2898      }
  2899  
  2900  
  2901      function setApprovalForAll(address operator, bool approved) public virtual override {
  2902          _setApprovalForAll(_msgSender(), operator, approved);
  2903      }
  2904  
  2905  
  2906      function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
  2907          return _operatorApprovals[owner][operator];
  2908      }
  2909  
  2910  
  2911      function transferFrom(
  2912          address from,
  2913          address to,
  2914          uint256 tokenId
  2915      ) public virtual override {
  2916          //solhint-disable-next-line max-line-length
  2917          require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
  2918  
  2919          _transfer(from, to, tokenId);
  2920      }
  2921  
  2922  
  2923      function safeTransferFrom(
  2924          address from,
  2925          address to,
  2926          uint256 tokenId
  2927      ) public virtual override {
  2928          safeTransferFrom(from, to, tokenId, "");
  2929      }
  2930  
  2931      function safeTransferFrom(
  2932          address from,
  2933          address to,
  2934          uint256 tokenId,
  2935          bytes memory _data
  2936      ) public virtual override {
  2937          require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
  2938          _safeTransfer(from, to, tokenId, _data);
  2939      }
  2940  
  2941  
  2942      function _safeTransfer(
  2943          address from,
  2944          address to,
  2945          uint256 tokenId,
  2946          bytes memory _data
  2947      ) internal virtual {
  2948          _transfer(from, to, tokenId);
  2949          require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
  2950      }
  2951  
  2952      function _exists(uint256 tokenId) internal view virtual returns (bool) {
  2953          return _owners[tokenId] != address(0);
  2954      }
  2955  
  2956  
  2957      function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
  2958          require(_exists(tokenId), "ERC721: operator query for nonexistent token");
  2959          address owner = ERC721.ownerOf(tokenId);
  2960          return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
  2961      }
  2962  
  2963  
  2964      function _safeMint(address to, uint256 tokenId) internal virtual {
  2965          _safeMint(to, tokenId, "");
  2966      }
  2967  
  2968  
  2969      function _safeMint(
  2970          address to,
  2971          uint256 tokenId,
  2972          bytes memory _data
  2973      ) internal virtual {
  2974          _mint(to, tokenId);
  2975          require(
  2976              _checkOnERC721Received(address(0), to, tokenId, _data),
  2977              "ERC721: transfer to non ERC721Receiver implementer"
  2978          );
  2979      }
  2980  
  2981  
  2982      function _mint(address to, uint256 tokenId) internal virtual {
  2983          require(to != address(0), "ERC721: mint to the zero address");
  2984          require(!_exists(tokenId), "ERC721: token already minted");
  2985  
  2986          _beforeTokenTransfer(address(0), to, tokenId);
  2987  
  2988          _balances[to] += 1;
  2989          _owners[tokenId] = to;
  2990          idtostartingtimet[tokenId][to]=block.timestamp;
  2991  
  2992          // totalSupply+=1;
  2993  
  2994          emit Transfer(address(0), to, tokenId);
  2995  
  2996          _afterTokenTransfer(address(0), to, tokenId);
  2997      }
  2998  
  2999  
  3000  
  3001      function _burn(uint256 tokenId) internal virtual {
  3002          address owner = ERC721.ownerOf(tokenId);
  3003  
  3004          _beforeTokenTransfer(owner, address(0), tokenId);
  3005  
  3006          // Clear approvals
  3007          _approve(address(0), tokenId);
  3008  
  3009          _balances[owner] -= 1;
  3010          delete _owners[tokenId];
  3011  
  3012  
  3013          // totalSupply-=1;
  3014  
  3015          emit Transfer(owner, address(0), tokenId);
  3016  
  3017          _afterTokenTransfer(owner, address(0), tokenId);
  3018      }
  3019  
  3020       function mint(
  3021          address _to,
  3022          uint256 _mintAmount
  3023  
  3024      ) public payable {
  3025          // get total NFT token supply
  3026  
  3027          require(_mintAmount > 0);
  3028          require(_mintAmount <= maxMintAmount);
  3029          require( totalSupply() + _mintAmount <= maxSupply);
  3030          require(paused == false);
  3031  
  3032              // minting is free for first 200 request after which payment is required
  3033          if ( totalSupply() >= 200) {
  3034                  require(msg.value >= cost * _mintAmount);
  3035              }
  3036  
  3037  
  3038  
  3039  
  3040          // execute mint
  3041         if (_tokenIds.current()==0){
  3042              _tokenIds.increment();
  3043         }
  3044  
  3045          for (uint256 i = 1; i <= _mintAmount; i++) {
  3046              uint256 newTokenID = _tokenIds.current();
  3047              _safeMint(_to, newTokenID);
  3048              _tokenIds.increment();
  3049          }
  3050      }
  3051  
  3052      function checkdragonnotbreeded(address add)public view returns(uint[] memory){
  3053  
  3054          uint256 ownerTokenCount = balanceOf(add);
  3055             uint256[] memory tokenIds = new uint256[](ownerTokenCount);
  3056           tokenIds= walletofNFT(add);
  3057  
  3058  
  3059            uint count;
  3060           for (uint i ;i<ownerTokenCount; i++){
  3061               if (_breeded[address(this)][tokenIds[i]]==false){
  3062                  count++;
  3063               }
  3064  
  3065  
  3066             }
  3067            uint256[] memory notbreededbrtokenIds = new uint256[](count);
  3068            uint _count;
  3069              for (uint i ;i<ownerTokenCount; i++){
  3070               if (_breeded[address(this)][tokenIds[i]]==false){
  3071                     notbreededbrtokenIds[_count]=tokenIds[i];
  3072                     _count++;
  3073               }
  3074  
  3075  
  3076             }
  3077  
  3078             return notbreededbrtokenIds;
  3079          }
  3080  
  3081  
  3082  
  3083  
  3084      function breed(uint id1,uint id2) public  {
  3085          uint amount=1800*10**18;
  3086          require(balanceOf(msg.sender)>=2, "Must Own 2 0xDragons");
  3087          require (_ERC20.balanceOf(msg.sender) >= amount,"You Dont Have The $SCALE For That!");
  3088          require (ownerOf(id1)==msg.sender,"NOT YOUR DRAGON");
  3089          require (ownerOf(id2)==msg.sender,"NOT YOUR DRAGON");
  3090          _ERC20.burn(msg.sender, amount);
  3091  
  3092  
  3093           _breeded[address(this)][id1]=true;
  3094             _breeded[address(this)][id2]=true;
  3095  
  3096  
  3097          _babynft.mint(msg.sender);
  3098      }
  3099  
  3100  
  3101      function burn(uint id1, uint id2, uint id3 ) public  {
  3102      uint amount=1500*10**18;
  3103      require(balanceOf(msg.sender)>=3, "Must Have 3 UNBRED Dragons");
  3104      require (_ERC20.balanceOf(msg.sender) >= amount,"You Dont Have The $SCALE For That!");
  3105      require (ownerOf(id1)==msg.sender,"NOT YOUR DRAGON");
  3106      require (ownerOf(id2)==msg.sender,"NOT YOUR DRAGON");
  3107      require (ownerOf(id3)==msg.sender,"NOT YOUR DRAGON");
  3108      require( _breeded[address(this)][id1]==false ,"Bred Dragons CAN'T Be Sacrificed");
  3109      require( _breeded[address(this)][id2]==false ,"Bred Dragons CAN'T Be Sacrificed");
  3110      require( _breeded[address(this)][id3]==false ,"Bred Dragons CAN'T Be Sacrificed");
  3111      _ERC20.burn(msg.sender, amount);
  3112  
  3113    _transfer(
  3114        msg.sender,
  3115        0x000000000000000000000000000000000000dEaD,
  3116        id1
  3117  );
  3118  _transfer(
  3119        msg.sender,
  3120        0x000000000000000000000000000000000000dEaD,
  3121        id2
  3122  );
  3123  _transfer(
  3124        msg.sender,
  3125        0x000000000000000000000000000000000000dEaD,
  3126        id3
  3127  );
  3128  
  3129        _ancientnft.mint(msg.sender);
  3130  
  3131  
  3132       }
  3133  
  3134  
  3135  
  3136  
  3137     function setmaxsupplyforbabynft(uint amount)public onlyOwner{
  3138          _babynft.setmaxsupply(amount);
  3139  
  3140     }
  3141  
  3142     function setbaseuriforbabynft(string memory _newBaseURI) public onlyOwner{
  3143         _babynft.setBaseURI(_newBaseURI);
  3144     }
  3145  
  3146  
  3147     function setbaseuriforancientnft(string memory _newBaseURI) public onlyOwner{
  3148         _ancientnft.setBaseURI(_newBaseURI);
  3149     }
  3150  
  3151  
  3152      function setCost(uint256 _newCost) public onlyOwner {
  3153          cost = _newCost;
  3154      }
  3155  
  3156      // set or update max number of mint per mint call
  3157      function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
  3158          maxMintAmount = _newmaxMintAmount;
  3159      }
  3160  
  3161  
  3162  
  3163      function setBaseURI(string memory _newBaseURI) public onlyOwner {
  3164          baseURI_ = _newBaseURI;
  3165      }
  3166  
  3167      // set metadata base extention
  3168      function setBaseExtension(string memory _newBaseExtension)public onlyOwner    {
  3169          baseExtension = _newBaseExtension;    }
  3170  
  3171  
  3172  
  3173  
  3174      function claim() public onlyOwner {
  3175          // get contract total balance
  3176          uint256 balance = address(this).balance;
  3177          // begin withdraw based on address percentage
  3178  
  3179          // 40%
  3180          payable(Jazzasaurus).transfer((balance / 100) * 40);
  3181          // 20%
  3182          payable(possumchsr69).transfer((balance / 100) * 20);
  3183          // 25%
  3184          payable(munheezy).transfer((balance / 100) * 25);
  3185          // 15%
  3186          payable(_community).transfer((balance / 100) * 15);
  3187      }
  3188  
  3189        function walletofNFT(address _owner)
  3190          public
  3191          view
  3192          returns (uint256[] memory)
  3193      {
  3194          uint256 ownerTokenCount = balanceOf(_owner);
  3195          uint256[] memory tokenIds = new uint256[](ownerTokenCount);
  3196          for (uint256 i; i < ownerTokenCount; i++) {
  3197              tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
  3198          }
  3199          return tokenIds;
  3200      }
  3201  
  3202      function checkrewardbal()public view returns(uint){
  3203  
  3204          uint256 ownerTokenCount = balanceOf(msg.sender);
  3205             uint256[] memory tokenIds = new uint256[](ownerTokenCount);
  3206           tokenIds= walletofNFT(msg.sender);
  3207  
  3208            uint current;
  3209            uint reward;
  3210            uint rewardbal;
  3211           for (uint i ;i<ownerTokenCount; i++){
  3212  
  3213               if (idtostartingtimet[tokenIds[i]][msg.sender]>0 ){
  3214             current = block.timestamp - idtostartingtimet[tokenIds[i]][msg.sender];
  3215               reward = ((10*10**18)*current)/86400;
  3216              rewardbal+=reward;
  3217  
  3218             }
  3219          }
  3220  
  3221          return rewardbal;
  3222      }
  3223  
  3224      function checkrewardforancientbal()public view returns(uint){
  3225        return _ancientnft.checkrewardbal(msg.sender);
  3226      }
  3227  
  3228      function checkrewardforbabybal()public view returns(uint){
  3229        return _babynft.checkrewardbal(msg.sender);
  3230      }
  3231  
  3232      function claimreward() public {
  3233            require(balanceOf(msg.sender)>0, "Not Qualified For Reward");
  3234           uint256 ownerTokenCount = balanceOf(msg.sender);
  3235             uint256[] memory tokenIds = new uint256[](ownerTokenCount);
  3236           tokenIds= walletofNFT(msg.sender);
  3237  
  3238            uint current;
  3239            uint reward;
  3240            uint rewardbal;
  3241           for (uint i ;i<ownerTokenCount; i++){
  3242  
  3243               if (idtostartingtimet[tokenIds[i]][msg.sender]>0 ){
  3244             current = block.timestamp - idtostartingtimet[tokenIds[i]][msg.sender];
  3245               reward = ((10*10**18)*current)/86400;
  3246              rewardbal+=reward;
  3247            idtostartingtimet[tokenIds[i]][msg.sender]=block.timestamp;
  3248             }
  3249          }
  3250  
  3251           _ERC20.mint(msg.sender,rewardbal);
  3252       if (_ancientnft.balanceOf(msg.sender)>0){
  3253          _ancientnft.claimreward(msg.sender);
  3254  
  3255          }
  3256      if (_babynft.balanceOf(msg.sender)>0){
  3257          _babynft.claimreward(msg.sender);
  3258          }
  3259  
  3260  
  3261      }
  3262  
  3263  
  3264       function checkerc20address()public view returns(address) {
  3265  
  3266       return  (address(_ERC20)); //  this is the deployed address of erc20token
  3267  
  3268   }
  3269  
  3270  
  3271       function checkancientnftaddress()public view returns(address) {
  3272  
  3273       return  (address(_ancientnft)); //  this is the deployed address of ancienttoken
  3274  
  3275      }
  3276  
  3277  
  3278       function checkbabynftaddress()public view returns(address) {
  3279  
  3280       return  (address(_babynft)); //  this is the deployed address of babytoken
  3281  
  3282   }
  3283  
  3284  
  3285  
  3286  
  3287  
  3288      function _transfer(
  3289          address from,
  3290          address to,
  3291          uint256 tokenId
  3292      ) internal virtual {
  3293          require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
  3294          require(to != address(0), "ERC721: transfer to the zero address");
  3295  
  3296          _beforeTokenTransfer(from, to, tokenId);
  3297  
  3298          // Clear approvals from the previous owner
  3299          _approve(address(0), tokenId);
  3300  
  3301          _balances[from] -= 1;
  3302          _balances[to] += 1;
  3303          _owners[tokenId] = to;
  3304          idtostartingtimet[tokenId][to]=block.timestamp;
  3305          idtostartingtimet[tokenId][from]=0;
  3306  
  3307  
  3308          emit Transfer(from, to, tokenId);
  3309  
  3310          _afterTokenTransfer(from, to, tokenId);
  3311      }
  3312  
  3313  
  3314      function _approve(address to, uint256 tokenId) internal virtual {
  3315          _tokenApprovals[tokenId] = to;
  3316          emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
  3317      }
  3318  
  3319  
  3320      function _setApprovalForAll(
  3321          address owner,
  3322          address operator,
  3323          bool approved
  3324      ) internal virtual {
  3325          require(owner != operator, "ERC721: approve to caller");
  3326          _operatorApprovals[owner][operator] = approved;
  3327          emit ApprovalForAll(owner, operator, approved);
  3328      }
  3329  
  3330      function _checkOnERC721Received(
  3331          address from,
  3332          address to,
  3333          uint256 tokenId,
  3334          bytes memory _data
  3335      ) private returns (bool) {
  3336          if (to.isContract()) {
  3337              try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
  3338                  return retval == IERC721Receiver.onERC721Received.selector;
  3339              } catch (bytes memory reason) {
  3340                  if (reason.length == 0) {
  3341                      revert("ERC721: transfer to non ERC721Receiver implementer");
  3342                  } else {
  3343                      assembly {
  3344                          revert(add(32, reason), mload(reason))
  3345                      }
  3346                  }
  3347              }
  3348          } else {
  3349              return true;
  3350          }
  3351      }
  3352  
  3353  
  3354  
  3355      function _afterTokenTransfer(
  3356          address from,
  3357          address to,
  3358          uint256 tokenId
  3359      ) internal virtual {}
  3360  }