Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlovdog committed Nov 5, 2024
1 parent 1ed5e81 commit 9559471
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 28 deletions.
4 changes: 1 addition & 3 deletions src/MagicSpendStakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ contract MagicSpendStakeManager is StakeManager, OwnableUpgradeable, EIP712Upgra
mapping(bytes32 hash_ => bool) public requestStatuses;
mapping(address asset => uint128) public claimed;

function initialize(
address _owner
) external initializer {
function initialize(address _owner) external initializer {
__Ownable_init(_owner);
__EIP712_init("Pimlico Magic Spend", "1");
}
Expand Down
1 change: 0 additions & 1 deletion src/MagicSpendWithdrawalManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {ETH, WithdrawRequest, CallStruct} from "./base/Helpers.sol";

import {SafeTransferLib} from "@solady-0.0.259/utils/SafeTransferLib.sol";


/// @title MagicSpendWithdrawalManager
/// @author Pimlico (https://github.com/pimlicolabs/magic-spend)
/// @notice Contract that allows users to pull funds from if they provide a valid signed request.
Expand Down
56 changes: 37 additions & 19 deletions src/Timelock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,38 @@ pragma solidity ^0.8.0;
contract Timelock {
event NewAdmin(address indexed newAdmin);
event NewPendingAdmin(address indexed newPendingAdmin);
event NewDelay(uint indexed newDelay);
event CancelTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta);
event ExecuteTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta);
event QueueTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta);

uint public constant GRACE_PERIOD = 14 days;
uint public constant MINIMUM_DELAY = 2 days;
uint public constant MAXIMUM_DELAY = 30 days;
event NewDelay(uint256 indexed newDelay);
event CancelTransaction(
bytes32 indexed txHash, address indexed target, uint256 value, string signature, bytes data, uint256 eta
);
event ExecuteTransaction(
bytes32 indexed txHash, address indexed target, uint256 value, string signature, bytes data, uint256 eta
);
event QueueTransaction(
bytes32 indexed txHash, address indexed target, uint256 value, string signature, bytes data, uint256 eta
);

uint256 public constant GRACE_PERIOD = 14 days;
uint256 public constant MINIMUM_DELAY = 2 days;
uint256 public constant MAXIMUM_DELAY = 30 days;

address public admin;
address public pendingAdmin;
uint public delay;
uint256 public delay;

mapping (bytes32 => bool) public queuedTransactions;
mapping(bytes32 => bool) public queuedTransactions;

constructor(address admin_, uint delay_) {
constructor(address admin_, uint256 delay_) {
require(delay_ >= MINIMUM_DELAY, "Timelock::constructor: Delay must exceed minimum delay.");
require(delay_ <= MAXIMUM_DELAY, "Timelock::setDelay: Delay must not exceed maximum delay.");

admin = admin_;
delay = delay_;
}

receive() external payable { }
receive() external payable {}

function setDelay(uint delay_) public {
function setDelay(uint256 delay_) public {
require(msg.sender == address(this), "Timelock::setDelay: Call must come from Timelock.");
require(delay_ >= MINIMUM_DELAY, "Timelock::setDelay: Delay must exceed minimum delay.");
require(delay_ <= MAXIMUM_DELAY, "Timelock::setDelay: Delay must not exceed maximum delay.");
Expand All @@ -54,9 +60,15 @@ contract Timelock {
emit NewPendingAdmin(pendingAdmin);
}

function queueTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public returns (bytes32) {
function queueTransaction(address target, uint256 value, string memory signature, bytes memory data, uint256 eta)
public
returns (bytes32)
{
require(msg.sender == admin, "Timelock::queueTransaction: Call must come from admin.");
require(eta >= getBlockTimestamp() + delay, "Timelock::queueTransaction: Estimated execution block must satisfy delay.");
require(
eta >= getBlockTimestamp() + delay,
"Timelock::queueTransaction: Estimated execution block must satisfy delay."
);

bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
queuedTransactions[txHash] = true;
Expand All @@ -65,7 +77,9 @@ contract Timelock {
return txHash;
}

function cancelTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public {
function cancelTransaction(address target, uint256 value, string memory signature, bytes memory data, uint256 eta)
public
{
require(msg.sender == admin, "Timelock::cancelTransaction: Call must come from admin.");

bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
Expand All @@ -74,7 +88,11 @@ contract Timelock {
emit CancelTransaction(txHash, target, value, signature, data, eta);
}

function executeTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public payable returns (bytes memory) {
function executeTransaction(address target, uint256 value, string memory signature, bytes memory data, uint256 eta)
public
payable
returns (bytes memory)
{
require(msg.sender == admin, "Timelock::executeTransaction: Call must come from admin.");

bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
Expand All @@ -101,8 +119,8 @@ contract Timelock {
return returnData;
}

function getBlockTimestamp() internal view returns (uint) {
function getBlockTimestamp() internal view returns (uint256) {
// solium-disable-next-line security/no-block-members
return block.timestamp;
}
}
}
3 changes: 3 additions & 0 deletions src/base/MagicSpendFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library MagicSpendFactory {

}
8 changes: 7 additions & 1 deletion src/base/StakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
pragma solidity ^0.8.0;

import {SafeTransferLib} from "@solady-0.0.259/utils/SafeTransferLib.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin-5.0.2/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import {ReentrancyGuardUpgradeable} from
"@openzeppelin-5.0.2/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import {ETH} from "./Helpers.sol";

/* solhint-disable avoid-low-level-calls */
Expand Down Expand Up @@ -78,6 +79,11 @@ abstract contract StakeManager is ReentrancyGuardUpgradeable {
revert InvalidUnstakeDelay();
}

// If asset is already staked, unstake delay must be the same
if (stakeInfo.unstakeDelaySec > 0 && stakeInfo.unstakeDelaySec != unstakeDelaySec) {
revert InvalidUnstakeDelay();
}

uint128 stake = stakeInfo.amount + amount;

if (stake == 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/base/WithdrawalManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pragma solidity ^0.8.0;

import {SafeTransferLib} from "@solady-0.0.259/utils/SafeTransferLib.sol";
import {OwnableUpgradeable} from "@openzeppelin-5.0.2/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin-5.0.2/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import {ReentrancyGuardUpgradeable} from
"@openzeppelin-5.0.2/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import {ETH} from "./Helpers.sol";

abstract contract WithdrawalManager is OwnableUpgradeable, ReentrancyGuardUpgradeable {
Expand Down
4 changes: 1 addition & 3 deletions test/MagicSpendStakeManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ contract MagicSpendStakeManagerTest is Test {
(alice, aliceKey) = makeAddrAndKey("alice");

address proxy = Upgrades.deployTransparentProxy(
"MagicSpendStakeManager.sol",
OWNER,
abi.encodeCall(MagicSpendStakeManager.initialize, (OWNER))
"MagicSpendStakeManager.sol", OWNER, abi.encodeCall(MagicSpendStakeManager.initialize, (OWNER))
);

magicSpendStakeManager = MagicSpendStakeManager(payable(proxy));
Expand Down

0 comments on commit 9559471

Please sign in to comment.