Skip to content

Commit

Permalink
Merge pull request #2 from corddry/master
Browse files Browse the repository at this point in the history
Code4rena Changes
  • Loading branch information
FortisFortuna authored Sep 29, 2022
2 parents 318456a + 996d528 commit 170d08a
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions src/sfrxETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,44 @@ import "openzeppelin-contracts/contracts/security/ReentrancyGuard.sol";
mint() - deposit targeting a specific number of sfrxETH out
deposit() - deposit knowing a specific number of frxETH in */
contract sfrxETH is xERC4626, ReentrancyGuard {

modifier andSync {
if (block.timestamp >= rewardsCycleEnd) { syncRewards(); }
_;
}

/* ========== CONSTRUCTOR ========== */
constructor(ERC20 _underlying, uint32 _rewardsCycleLength)
ERC4626(_underlying, "Staked Frax Ether", "sfrxETH")
xERC4626(_rewardsCycleLength)
{}

/// @notice Syncs rewards if applicable beforehand. Noop if otherwise
function beforeWithdraw(uint256 assets, uint256 shares) internal override {
super.beforeWithdraw(assets, shares); // call xERC4626's beforeWithdraw first
if (block.timestamp >= rewardsCycleEnd) { syncRewards(); }
/// @notice inlines syncRewards with deposits when able
function deposit(uint256 assets, address receiver) public override andSync returns (uint256 shares) {
return super.deposit(assets, receiver);
}

/// @notice inlines syncRewards with mints when able
function mint(uint256 shares, address receiver) public override andSync returns (uint256 assets) {
return super.mint(shares, receiver);
}

/// @notice inlines syncRewards with withdrawals when able
function withdraw(
uint256 assets,
address receiver,
address owner
) public override andSync returns (uint256 shares) {
return super.withdraw(assets, receiver, owner);
}

/// @notice inlines syncRewards with redemptions when able
function redeem(
uint256 shares,
address receiver,
address owner
) public override andSync returns (uint256 assets) {
return super.redeem(shares, receiver, owner);
}

/// @notice How much frxETH is 1E18 sfrxETH worth. Price is in ETH, not USD
Expand All @@ -70,20 +98,4 @@ contract sfrxETH is xERC4626, ReentrancyGuard {
return (deposit(assets, receiver));
}

/// @notice Approve and mint() in one transaction
/// @dev Similar to the deposit method, but you give it the number of shares you want instead.
function mintWithSignature(
uint256 shares,
address receiver,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external nonReentrant returns (uint256 assets) {
uint256 amount = approveMax ? type(uint256).max : previewMint(shares);
asset.permit(msg.sender, address(this), amount, deadline, v, r, s);
return (mint(shares, receiver));
}

}

0 comments on commit 170d08a

Please sign in to comment.