//SPDX-License-Identifier: MIT Licensed
pragma solidity ^0.8.18;
contract ClaimContract {
address public owner;
uint256 public totalAddedReward;
uint256 public totalClaimedReward;
uint256 public totalUsersClaimed;
bool public enableClaim;
mapping(address => uint256) public userBalance;
mapping(address => uint256) public claimedBalance;
mapping(address => bool) public alreadyClaimed;
modifier onlyOwner() {
require(msg.sender == owner, " Not an owner");
_;
}
receive() external payable {
totalAddedReward += msg.value;
}
constructor(address _owner) {
owner = _owner;
}
function addWalletsData(
address[] memory wallet,
uint256[] memory amount
) public onlyOwner {
require(
wallet.length == amount.length,
"wallet and amount length mismatch"
);
for (uint256 i = 0; i < wallet.length; i++) {
userBalance[wallet[i]] += amount[i];
}
}
function claim() public {
require(enableClaim, "wait for owner to start claim");
uint256 availableBalance = userBalance[msg.sender] -
claimedBalance[msg.sender];
require(availableBalance > 0, "already claimed");
claimedBalance[msg.sender] += availableBalance;
totalClaimedReward += availableBalance;
if (!alreadyClaimed[msg.sender]) {
totalUsersClaimed++;
alreadyClaimed[msg.sender] = true;
}
payable(msg.sender).transfer(availableBalance);
}
function enableClaimState(bool _state) external onlyOwner {
enableClaim = _state;
}
// transfer ownership
function changeOwner(address payable _newOwner) external onlyOwner {
owner = _newOwner;
}
// to draw out tokens
function transferStuckFunds(
address _receiver,
uint256 _value
) external onlyOwner {
payable(_receiver).transfer(_value);
}
}
{
"compilationTarget": {
"ClaimContract.sol": "ClaimContract"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address[]","name":"wallet","type":"address[]"},{"internalType":"uint256[]","name":"amount","type":"uint256[]"}],"name":"addWalletsData","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"alreadyClaimed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address payable","name":"_newOwner","type":"address"}],"name":"changeOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"claimedBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"enableClaim","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"_state","type":"bool"}],"name":"enableClaimState","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAddedReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalClaimedReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalUsersClaimed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_receiver","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferStuckFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]