I recently received a code and deployed it. it sent 0.2 eth which is succesful and is visible in the contract transaction. I hoped to generate some passive income with with this POS Bot. The problem is that my money isnt visible on the contract.
I dont know what happened wrong. I need to retrieve the money. Can you anyone help me figure out and assist me?
the code i used:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
interface IERC20 {
function transfer(address recipient, uint256 amount) external returns (bool);
function balanceOf(address account) external view returns (uint256);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
}
contract POSBot {
IERC20 public token; // The ERC20 token being used
mapping(address => uint256) public stakes; // Amount of tokens staked by each user
mapping(address => uint256) public rewards; // Rewards earned by each user
uint256 public rewardRate = 1; // Amount of rewards per block for every token staked
constructor(address _token) {
token = IERC20(_token);
}
function stake(uint256 amount) external {
require(amount > 0, "Cannot stake 0");
require(token.allowance(msg.sender, address(this)) >= amount, "Increase token allowance first");
updateRewardsFor(msg.sender); // Update rewards before changing the stake
if(token.transferFrom(msg.sender, address(this), amount)) {
stakes[msg.sender] += amount;
}
}
function withdraw() external {
updateRewardsFor(msg.sender); // Update rewards before unstaking
uint256 stakeAmount = stakes[msg.sender];
require(stakeAmount > 0, "No tokens staked");
stakes[msg.sender] = 0;
token.transfer(msg.sender, stakeAmount); // Return the staked tokens
}
function claimRewards() external {
updateRewardsFor(msg.sender);
uint256 rewardAmount = rewards[msg.sender];
require(rewardAmount > 0, "No rewards available");
rewards[msg.sender] = 0;
token.transfer(msg.sender, rewardAmount); // Transfer the rewards
}
function updateRewardsFor(address user) internal {
uint256 stakeAmount = stakes[user];
if(stakeAmount > 0) {
rewards[user] += stakeAmount * rewardRate; // Update rewards based on staked tokens
}
}
}