Skip to content

Commit

Permalink
Merge pull request #70 from smart-transaction/refactor/faucet-auth-an…
Browse files Browse the repository at this point in the history
…d-delay

Refactor: Faucet auth and delay
  • Loading branch information
TokenTitan authored Sep 13, 2024
2 parents 9e35563 + 65ef1cc commit 820e840
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 16 deletions.
22 changes: 22 additions & 0 deletions script/FaucetUpgrade.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import "forge-std/Script.sol";
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";

contract UpgradeFaucet is Script {
function run() external returns (address, address) {
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_KEY");
address proxyAddress = vm.evmAddress("PROXY");
vm.startBroadcast(deployerPrivateKey);
// Upgrade the upgradeable contract
Upgrades.upgradeProxy(proxyAddress, "FaucetV1.sol", "");

// Get the implementation address
address implementationAddress = Upgrades.getImplementationAddress(proxyAddress);

vm.stopBroadcast();

return (implementationAddress, proxyAddress);
}
}
2 changes: 1 addition & 1 deletion src/interfaces/ICallBreaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ interface ICallBreaker {
/*
* @notice Get the portal status
* @return boolean value as true if portal is open
*/
*/
function isPortalOpen() external view returns (bool status);
}
2 changes: 1 addition & 1 deletion src/lamination/LaminatedProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ contract LaminatedProxy is LaminatedStorage, ReentrancyGuard {
/// Can only be invoked by the owner of the contract.
/// @param input The encoded CallObject containing information about the function call to execute.
/// @return returnValue The return value from the executed function call.
function execute(bytes calldata input) external onlyOwner() nonReentrant returns (bytes memory) {
function execute(bytes calldata input) external onlyOwner nonReentrant returns (bytes memory) {
ICallBreaker cb = callBreaker();
if (cb.isPortalOpen()) {
revert PortalOpenInCallBreaker();
Expand Down
29 changes: 15 additions & 14 deletions src/utilities/Faucet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,34 @@ contract Faucet is AccessControlUpgradeable {
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");

uint256 public dripAmount;
uint256 public lockDuration;
/// @notice disable lock features for the initial version of the faucet
/// uint256 public lockDuration;

/// @notice used to block users of faucet for 24 hours after taking every call
/// @dev mapping to store address and blocktime + 1 day
mapping(address => uint256) public lockTime;
// mapping(address => uint256) public lockTime;

event DripAmountUpdated(uint256 amount);
event LockDurationUpdated(uint256 lockDuration);
// event LockDurationUpdated(uint256 lockDuration);
event FundsTransferred(address indexed requestor, uint256 dripAmount);
event FundsGranted(address indexed receiver, uint256 amount);

function initialize() external initializer {
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
_grantRole(ADMIN_ROLE, _msgSender());
_setDripAmount(0.5 ether);
lockDuration = 1 days;
_setDripAmount(5 ether);
// lockDuration = 1 days;
}

/// @notice call to get funds from the faucet
function requestFunds(address payable _requestor) external payable onlyRole(ADMIN_ROLE) {
function requestFunds(address payable _requestor) external payable {
// check if funds were transferred recently
require(block.timestamp > lockTime[_requestor], "Faucet: Please try later");
// require(block.timestamp > lockTime[_requestor], "Faucet: Please try later");
// check if there is enough balance
require(address(this).balance > dripAmount, "Faucet: Not enough funds");

_requestor.transfer(dripAmount);
lockTime[_requestor] = block.timestamp + lockDuration;
// lockTime[_requestor] = block.timestamp + lockDuration;
emit FundsTransferred(_requestor, dripAmount);
}

Expand All @@ -51,12 +52,12 @@ contract Faucet is AccessControlUpgradeable {
_setDripAmount(newDripAmount);
}

/// @notice
function changeLockDuration(uint256 newLockDuration) external onlyRole(ADMIN_ROLE) {
require(newLockDuration > 0, "Faucet: Invalid duration value");
lockDuration = newLockDuration;
emit LockDurationUpdated(newLockDuration);
}
/// @notice commented lock feature for the initial version of the faucet
// function changeLockDuration(uint256 newLockDuration) external onlyRole(ADMIN_ROLE) {
// require(newLockDuration > 0, "Faucet: Invalid duration value");
// lockDuration = newLockDuration;
// emit LockDurationUpdated(newLockDuration);
// }

// function to add funds to the smart contract
receive() external payable {}
Expand Down
12 changes: 12 additions & 0 deletions verifyLestnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Get the contract name
CONTRACT=$1

# Get contract address
ADDRESS=$2

# TODO: Add conditional logic for constructor arguments and make ot modular with other explorers

source .env
forge verify-contract --rpc-url $LESTNET_RPC $ADDRESS $CONTRACT --verifier blockscout --verifier-url $LESTNET_API_KEY

0 comments on commit 820e840

Please sign in to comment.