Skip to content

Commit

Permalink
add withdraw event
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmaxbu committed Feb 11, 2025
1 parent a1aa5f7 commit 472db3e
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
25 changes: 25 additions & 0 deletions script/Config.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {Script} from "forge-std/Script.sol";

struct netConfig {
uint256 chainId;
}

contract Config is Script {

constructor() {

}

function run() public {

}

function getAnvilConfig() public pure returns (netConfig memory) {
return netConfig({
chainId: 137
});
}
}
22 changes: 22 additions & 0 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {Script} from "forge-std/Script.sol";
import {Faucet} from "src/Faucet.sol";

contract Deploy is Script {

constructor() {

}

function run() public returns (Faucet) {
vm.startBroadcast();

Faucet faucet = new Faucet();

vm.stopBroadcast();
return faucet;
}

}
29 changes: 29 additions & 0 deletions src/Faucet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract Faucet {

error Faucet__amountTooLarge();
error Faucet__rateLimt();

event Withdrawal(address indexed to, uint amount);

mapping(address => uint) private lastAccessTime;

/**
* @notice Withdraw ether from faucet
*/
function withdraw(uint withdraw_amount) public {
if (withdraw_amount > 0.1 ether) {
revert Faucet__amountTooLarge();
}
if(block.timestamp < lastAccessTime[msg.sender] + 1 days) {
revert Faucet__rateLimt();
}
payable(msg.sender).transfer(withdraw_amount);
lastAccessTime[msg.sender] = block.timestamp;
emit Withdrawal(msg.sender, withdraw_amount);
}

receive() external payable {}
}
14 changes: 14 additions & 0 deletions test/Faucet.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {Test} from "forge-std/Test.sol";
import {Faucet} from "src/Faucet.sol";

contract FaucetTest is Test {

function test_withdraw() public {
Faucet faucet = new Faucet();
faucet.deposit{value: 1 ether}();
}

}

0 comments on commit 472db3e

Please sign in to comment.