Contract Source Code:
File 1 of 1 : ApeDeposit
// File: @openzeppelin/contracts/security/ReentrancyGuard.sol
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
// File: Contracts/poop.sol
pragma solidity ^0.8.0;
interface IERC20 {
function transfer(address recipient, uint256 amount) external returns (bool);
function balanceOf(address account) external view returns (uint256);
}
interface IERC721 {
function transferFrom(address from, address to, uint256 tokenId) external;
function ownerOf(uint256 tokenId) external view returns (address);
}
interface IPyth {
function getRandomNumber() external view returns (uint256);
}
contract ApeDeposit is ReentrancyGuard {
address public admin;
IERC20 public apeToken = IERC20(0x7f9FBf9bDd3F4105C478b996B648FE6e828a1e98); // $APE token contract address
IERC20 public mpooToken = IERC20(0xAf9DB8640FAFC11c5eF50497b76bD3Fe11541003);
IERC721 public goldenBananaNFT = IERC721(0x825F5E41FfCbe875D19F51895c814F088Bd45169); // Golden Banana NFT contract address
IPyth public pyth; // Pyth Entropy for randomness
uint256 public constant APE_DEPOSIT = 1 * 10**18; // 1 $APE token
uint256 public constant MPOO_REWARD = 5000 * 10**18; // 5,000 $MPOO tokens
uint256 public constant CHANCE = 10; // 10% chance to receive NFT
uint256 public constant SECONDS_IN_A_DAY = 86400; // 24 hours in seconds
uint256 public constant MAX_DEPOSITS_PER_DAY = 3; // 3 deposits allowed per day
address public beneficiary = 0x4D09C5DfD949470c684E6D537E24C399c075AD40; // Address to receive 90% of the $APE deposit
mapping(address => uint256) public lastDeposit; // Timestamp of the last deposit for each user
mapping(address => uint256) public depositCount; // Number of deposits made by each user in the current day
uint256[] public nftTokens; // Array of Golden Banana NFTs held by the contract
uint256 public nftIndex; // Index for the next NFT to be distributed
address public constant funder = 0x4D09C5DfD949470c684E6D537E24C399c075AD40; // Set your address for unlimited deposits
event Deposit(address indexed user, bool receivedNFT, uint256 rewardAmount);
constructor(address _pyth) {
admin = msg.sender;
pyth = IPyth(_pyth);
}
modifier onlyAdmin() {
require(msg.sender == admin, "Not admin");
_;
}
modifier canDeposit() {
// If the caller is the funder (your address), allow unlimited deposits
if (msg.sender != funder) {
// Reset deposit count after 24 hours (i.e., a new day)
if (block.timestamp - lastDeposit[msg.sender] >= SECONDS_IN_A_DAY) {
depositCount[msg.sender] = 0; // Reset the count
}
// Ensure the user has not exceeded the deposit limit of 3 per day
require(depositCount[msg.sender] < MAX_DEPOSITS_PER_DAY, "You can only deposit 3 times a day");
}
_;
}
function deposit() external nonReentrant canDeposit {
// Ensure the user sends exactly 1 $APE
require(apeToken.transfer(msg.sender, APE_DEPOSIT), "Deposit failed");
// Calculate 90% of the deposit to send to the beneficiary
uint256 ninetyPercentApe = (APE_DEPOSIT * 90) / 100;
// Send 90% to the beneficiary address
require(apeToken.transfer(beneficiary, ninetyPercentApe), "Transfer to beneficiary failed");
// Get randomness from Pyth
uint256 randomNumber = pyth.getRandomNumber();
bool receivedNFT = false;
if (randomNumber % 100 < CHANCE && nftIndex < nftTokens.length) {
// 10% chance to receive a Golden Banana NFT
uint256 tokenId = nftTokens[nftIndex];
goldenBananaNFT.transferFrom(address(this), msg.sender, tokenId);
nftIndex++; // Move to the next NFT in the array
receivedNFT = true;
emit Deposit(msg.sender, true, tokenId);
} else {
// 90% chance to receive 5,000 $MPOO
require(mpooToken.transfer(msg.sender, MPOO_REWARD), "MPOO transfer failed");
emit Deposit(msg.sender, false, MPOO_REWARD);
}
// Update the last deposit timestamp and increment the deposit count
lastDeposit[msg.sender] = block.timestamp;
depositCount[msg.sender] += 1;
}
// Admin functions
function withdrawTokens(address token, uint256 amount) external onlyAdmin {
IERC20(token).transfer(admin, amount);
}
function setPythAddress(address _pyth) external onlyAdmin {
pyth = IPyth(_pyth);
}
// Function to add NFTs to the contract (only by the admin)
function addNFTs(uint256[] calldata tokenIds) external onlyAdmin {
for (uint256 i = 0; i < tokenIds.length; i++) {
nftTokens.push(tokenIds[i]);
}
}
}