Skip to content

Commit c246345

Browse files
committed
refactor(N-02): deduplicate previewStake via getSharesForRnbw, use public isNonceUsed internally
1 parent 20d73bc commit c246345

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/RNBWStaking.sol

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,11 @@ contract RNBWStaking is IRNBWStaking, ReentrancyGuard, Pausable, EIP712 {
288288
/// @inheritdoc IRNBWStaking
289289
function previewStake(address user, uint256 amount) external view returns (uint256 sharesToMint) {
290290
if (shares[user] == 0 && amount < minStakeAmount) return 0;
291-
if (totalShares == 0) {
292-
if (amount <= MINIMUM_SHARES) return 0;
293-
sharesToMint = amount - MINIMUM_SHARES;
294-
} else {
295-
sharesToMint = (amount * totalShares) / _effectivePooledRnbw();
296-
}
291+
return getSharesForRnbw(amount);
297292
}
298293

299294
/// @inheritdoc IRNBWStaking
300-
function isNonceUsed(address user, uint256 nonce) external view returns (bool) {
295+
function isNonceUsed(address user, uint256 nonce) public view returns (bool) {
301296
return usedNonces[user][nonce];
302297
}
303298

@@ -593,7 +588,7 @@ contract RNBWStaking is IRNBWStaking, ReentrancyGuard, Pausable, EIP712 {
593588
if (block.timestamp > expiry) revert SignatureExpired();
594589

595590
// 2. Check nonce hasn't been used (prevents replay attacks)
596-
if (usedNonces[user][nonce]) revert NonceAlreadyUsed();
591+
if (isNonceUsed(user, nonce)) revert NonceAlreadyUsed();
597592

598593
// 3. Recover signer from EIP-712 typed data hash
599594
bytes32 digest = _hashTypedDataV4(structHash);

0 commit comments

Comments
 (0)