// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)pragmasolidity ^0.8.0;/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (address) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytescalldata) {
returnmsg.data;
}
}
Contract Source Code
File 2 of 4: IERC20.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)pragmasolidity ^0.8.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address to, uint256 amount) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(addressfrom,
address to,
uint256 amount
) externalreturns (bool);
}
Contract Source Code
File 3 of 4: Ownable.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)pragmasolidity ^0.8.0;import"../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/abstractcontractOwnableisContext{
addressprivate _owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/modifieronlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewvirtualreturns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/function_checkOwner() internalviewvirtual{
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/functionrenounceOwnership() publicvirtualonlyOwner{
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
require(newOwner !=address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/function_transferOwnership(address newOwner) internalvirtual{
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Contract Source Code
File 4 of 4: PulseBitcoinLockRewards.sol
// SPDX-License-Identifier: UNLICENSEDpragmasolidity ^0.8.0;import"@openzeppelin/contracts/token/ERC20/IERC20.sol";
import"@openzeppelin/contracts/access/Ownable.sol";
interfacePulseBitcoinLockNFTInterface{
functionownerOf(uint256 tokenId) externalviewreturns (address);
functionlockTime(uint256 tokenId) externalviewreturns (uint256);
functiontokenIdsToAmounts(uint256 tokenId) externalviewreturns (uint256);
}
contractPulseBitcoinLockNFTRewardsisOwnable{
addresspublic CARN;
addresspublicimmutable waatcaAddress;
addresspublicimmutable bulkClaimer;
PulseBitcoinLockNFTInterface pulseBitcoinLockNftContract;
addresspublic pulseBitcoinLockNftContractAddress;
mapping(uint256=>bool) public tokenIdsToRegistered; // True if they registered their NFT for rewards...will be able to withdraw rewards 1 day after registeringmapping(uint256=>uint256) public tokenIdsToLastWithdrawalDay; // records the last day they withdrew rewardsmapping(uint256=>uint256) public tokenIdsToDailyRewardAmount; // records their daily rewards amountmapping(uint256=>uint256) public tokenIdsToEndRewardsDay; // records their last day they can get rewards (max 1000 after registering)...(the smaller of 1000 or their actual end day measured from registration day)uint256internalconstant LAUNCH_TIME =1680048000; // Wednesday, March 29, 2023 12:00:00 AMuint256public totalFreeCarnWithdrawn;
constructor(address _waatcaAddress, address _pulseBitcoinLockNftContractAddress, address _bulkClaimer) {
waatcaAddress = _waatcaAddress;
pulseBitcoinLockNftContractAddress = _pulseBitcoinLockNftContractAddress;
pulseBitcoinLockNftContract = PulseBitcoinLockNFTInterface(pulseBitcoinLockNftContractAddress);
bulkClaimer = _bulkClaimer;
}
functionsetCarnAddress(address _rewardTokenCARN) publiconlyOwner{
CARN = _rewardTokenCARN;
}
functionwithdrawRewards(uint256 tokenId) public{
address tokenOwner = pulseBitcoinLockNftContract.ownerOf(tokenId);
require(
msg.sender== tokenOwner ||msg.sender== bulkClaimer,
"You are not the owner of this NFT, or the bulk claimer address"
);
require(
tokenIdsToRegistered[tokenId],
"You must register your NFT for rewards first"
);
require(
tokenIdsToLastWithdrawalDay[tokenId] < tokenIdsToEndRewardsDay[tokenId],
"You have already received all possible rewards for this NFT"
);
require(
_currentDay() > tokenIdsToLastWithdrawalDay[tokenId],
"Cannot withdraw twice on the same day, try again tomorrow"
);
uint256 totalDaysOfRewardsLeft = tokenIdsToEndRewardsDay[tokenId] - tokenIdsToLastWithdrawalDay[tokenId];
uint256 numOfDaysSinceLastWithdrawal = _currentDay() - tokenIdsToLastWithdrawalDay[tokenId];
// if numOfDaysSinceLastWithdrawal is greater than (their EndRewardsDay-LastWithdrawalDay) then set numOfDaysSinceLastWithdrawal to (their EndRewardsDay-LastWithdrawalDay)if (numOfDaysSinceLastWithdrawal > totalDaysOfRewardsLeft) {
// in this scenario they are past the end of their lock up period.// meaning they locked up for 500 days, and its now day 540 for example (or 501)// in that case we only want to give them rewards from their last withdrawal day, up until the last day they are eligible for rewards (day 500)// so if their last withdrawal day was day 400, we would only give them 100 days worth of rewards and not 140
numOfDaysSinceLastWithdrawal = totalDaysOfRewardsLeft;
}
IERC20(CARN).transfer(tokenOwner, tokenIdsToDailyRewardAmount[tokenId] * numOfDaysSinceLastWithdrawal);
IERC20(CARN).transfer(waatcaAddress, tokenIdsToDailyRewardAmount[tokenId] * numOfDaysSinceLastWithdrawal);
totalFreeCarnWithdrawn += tokenIdsToDailyRewardAmount[tokenId] * numOfDaysSinceLastWithdrawal;
tokenIdsToLastWithdrawalDay[tokenId] = _currentDay();
}
functionregisterNftForRewards(uint256 tokenId) public{
address tokenOwner = pulseBitcoinLockNftContract.ownerOf(tokenId);
require(
msg.sender== tokenOwner ||msg.sender== bulkClaimer,
"You are not the owner of this NFT, shame on you!"
);
require(!tokenIdsToRegistered[tokenId], "It seems you have already registered this NFT, go enjoy the rest of the carnival!");
// get the '(the end day of their lock period)' for this tokenIduint256 endOfLockPeriod = pulseBitcoinLockNftContract.lockTime(tokenId);
// calculate numDaysLockedUpFromRegistration (the end day of their lock period) - (the day they are registering...today) // set this to 1000 if its greater than 1000uint256 numDaysLockedUpFromRegistration = ((endOfLockPeriod - LAUNCH_TIME) /1days) - _currentDay();
uint256 numDaysLockedUpFromRegistrationForRewards = numDaysLockedUpFromRegistration;
if (numDaysLockedUpFromRegistrationForRewards >1000) {
// this makes locking more than 1000 PLSB for more than 1000 days, not beneficial in terms of getting rewards// we still want to let the user collect rewards everyday throughout their whole lock period, we keep the value of numDaysLockedUpFromRegistration// for the calculation of tokenIdsToEndRewardsDay later in this function
numDaysLockedUpFromRegistrationForRewards =1000;
}
uint256 amountPLSBLockedUp = pulseBitcoinLockNftContract.tokenIdsToAmounts(tokenId);
if (amountPLSBLockedUp >1000) {
// this makes locking more than 1000 plsb for more than 1000 days, not beneficial in terms of getting rewards
amountPLSBLockedUp =1000;
}
// calculate this nft's tokenIdsToDailyRewardAmount (amount of PLSB locked * (numDaysLockedUpSinceRegistration / 1000) * 0.0015)
tokenIdsToDailyRewardAmount[tokenId] =1_000_000_000_000* (amountPLSBLockedUp * numDaysLockedUpFromRegistrationForRewards *15) /10_000_000;
// set his registered value as TRUE (for that first require statement at the top of the function)
tokenIdsToRegistered[tokenId] =true;
// set his tokenIdsToLastWithdrawalDay to the _curentDay// even though this nft never had a real withdrawal, set the lastWithdrwalDay to today as a starting point to measure future withdrawals from
tokenIdsToLastWithdrawalDay[tokenId] = _currentDay();
// send the user his daily allotement of reward token for 1 days worth// as 1) a reward for registering, also it informs the user how much theyll be recieving per dayif (tokenId <1343){
// give a bonus to the first 500 NFT's created// partially beneveolent and partially because people lost out who locked up earlier before the launch of this project
IERC20(CARN).transfer(tokenOwner, tokenIdsToDailyRewardAmount[tokenId] * (1350-tokenId)/10 );
IERC20(CARN).transfer(waatcaAddress, tokenIdsToDailyRewardAmount[tokenId] * (1350-tokenId)/10 );
totalFreeCarnWithdrawn += tokenIdsToDailyRewardAmount[tokenId] * (1350-tokenId)/10;
} else {
IERC20(CARN).transfer(tokenOwner, tokenIdsToDailyRewardAmount[tokenId] *7);
IERC20(CARN).transfer(waatcaAddress, tokenIdsToDailyRewardAmount[tokenId] *7);
totalFreeCarnWithdrawn += tokenIdsToDailyRewardAmount[tokenId];
}
// set tokenIdsToEndRewardsDay to currentday + numDaysLockedUpFromRegistration (max 1000 days from registration)
tokenIdsToEndRewardsDay[tokenId] = _currentDay() + numDaysLockedUpFromRegistration;
}
functioncurrentDay() externalviewreturns (uint256) {
return _currentDay();
}
function_currentDay() internalviewreturns (uint256) {
return (block.timestamp- LAUNCH_TIME) /1days;
}
}