-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
0 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 |
---|---|---|
@@ -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 | ||
}); | ||
} | ||
} |
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 @@ | ||
//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; | ||
} | ||
|
||
} |
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,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 {} | ||
} |
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,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}(); | ||
} | ||
|
||
} |