-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Monad devnet deployment and Faucet feature (#17)
* added faucet feature * enforces cooldown after claims * fixes responsiveness for gameover screen * updated env.example * fixing chain errors * removed sepolia support * reset score to zero after claiming * block spammers from abusing disburse * fix incorrect claim mapping
- Loading branch information
1 parent
f5bdce7
commit 4a8b5cd
Showing
37 changed files
with
1,634 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
yarn lint-staged --verbose | ||
#yarn lint-staged --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
contract MouchDrops { | ||
address public owner; | ||
address public admin; | ||
uint256 public cooldownPeriod = 10 minutes; | ||
uint256 public maxDisbursement = 30 ether; | ||
mapping(address => uint256) public lastRequestTime; | ||
|
||
event EtherReceived(address indexed sender, uint256 amount); | ||
event OwnerWithdraw(address indexed owner, uint256 amount); | ||
|
||
constructor(address _admin) { | ||
owner = msg.sender; | ||
admin = _admin; | ||
} | ||
|
||
modifier onlyOwner() { | ||
require(msg.sender == owner, "Caller is not the owner"); | ||
_; | ||
} | ||
|
||
modifier onlyAdmin() { | ||
require(msg.sender == admin, "Not authorized!"); | ||
_; | ||
} | ||
|
||
receive() external payable { | ||
emit EtherReceived(msg.sender, msg.value); | ||
} | ||
|
||
function updateAdmin(address _newAdmin) external onlyOwner { | ||
admin = _newAdmin; | ||
} | ||
|
||
function disburse( | ||
address payable recipient, | ||
uint256 amount | ||
) external onlyAdmin { | ||
require(recipient != address(0), "Invalid recipient"); | ||
require(amount > 0 && amount <= maxDisbursement, "Invalid amount"); | ||
require( | ||
address(this).balance >= amount, | ||
"Insufficient contract balance" | ||
); | ||
require( | ||
block.timestamp >= lastRequestTime[recipient] + cooldownPeriod, | ||
"Cooldown period not yet expired" | ||
); | ||
lastRequestTime[recipient] = block.timestamp; | ||
|
||
// ✅ Send Ether to the recipient | ||
(bool sent, ) = recipient.call{ value: amount }(""); | ||
require(sent, "Failed to disburse rewards"); | ||
} | ||
|
||
function setCooldownPeriod(uint256 newCooldownPeriod) external onlyOwner { | ||
cooldownPeriod = newCooldownPeriod; | ||
} | ||
|
||
function setMaxDisbursement(uint256 newMaxDisbursement) external onlyOwner { | ||
require( | ||
newMaxDisbursement > 0, | ||
"Max disbursement must be greater than zero" | ||
); | ||
maxDisbursement = newMaxDisbursement; | ||
} | ||
|
||
function withdrawAll() external onlyOwner { | ||
uint256 contractBalance = address(this).balance; | ||
require(contractBalance > 0, "No funds to withdraw"); | ||
|
||
(bool sent, ) = owner.call{ value: contractBalance }(""); | ||
require(sent, "Failed to withdraw funds"); | ||
|
||
emit OwnerWithdraw(owner, contractBalance); | ||
} | ||
|
||
function transferOwnership(address newOwner) external onlyOwner { | ||
require(newOwner != address(0), "New owner cannot be zero address"); | ||
owner = newOwner; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { DeployFunction } from "hardhat-deploy/types"; | ||
|
||
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
const { deployments, getNamedAccounts } = hre; | ||
const { deploy } = deployments; | ||
const { deployer } = await getNamedAccounts(); | ||
|
||
const constructorArg = "0x41f3C185123a4519f30eE1507cfd146e85a59a22"; | ||
|
||
// Ensure compilation before deployment | ||
await hre.run("compile"); | ||
|
||
await deploy("MouchDrops", { | ||
from: deployer, | ||
args: [constructorArg], // Add constructor arguments here if any | ||
log: true, | ||
}); | ||
}; | ||
|
||
export default func; | ||
func.tags = ["MouchDrops"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
20143 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.