// SPDX-License-Identifier: MIT pragma solidity ^0.8.21; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; contract NFarming is Ownable { IERC20 public navisToken; // Mapping to track user staking balances mapping(address => uint256) public stakedBalances; // Mapping to track the timestamp when the user last staked mapping(address => uint256) public lastStakeTimestamp; // Event emitted when a user stakes NAVIS tokens event Staked(address indexed user, uint256 amount); // Event emitted when a user withdraws staked NAVIS tokens event Withdrawn(address indexed user, uint256 amount); // Constructor to set the NAVIS token address constructor(address _navisToken) { navisToken = IERC20(_navisToken); } // Function to stake NAVIS tokens function stake(uint256 amount) external { require(amount > 0, "Amount must be greater than zero"); // Transfer NAVIS tokens from the user to this contract require(navisToken.transferFrom(msg.sender, address(this), amount), "Transfer failed"); // Update staking information stakedBalances[msg.sender] += amount; lastStakeTimestamp[msg.sender] = block.timestamp; // Emit Staked event emit Staked(msg.sender, amount); } // Function to withdraw staked NAVIS tokens function withdraw(uint256 amount) external { require(amount > 0, "Amount must be greater than zero"); require(amount <= stakedBalances[msg.sender], "Insufficient balance"); // Transfer staked NAVIS tokens back to the user navisToken.transfer(msg.sender, amount); // Update staking information stakedBalances[msg.sender] -= amount; // Emit Withdrawn event emit Withdrawn(msg.sender, amount); } // Function to get the user's staked balance function getUserStakedBalance(address user) external view returns (uint256) { return stakedBalances[user]; } // Function to get the timestamp when the user last staked function getLastStakeTimestamp(address user) external view returns (uint256) { return lastStakeTimestamp[user]; } }