Skip to content

Commit fb8743d

Browse files
committed
add reentrancy guards
1 parent f30c4ed commit fb8743d

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ solidity-lint:
1111

1212
.PHONY: solidity-snapshot
1313
solidity-snapshot:
14-
cd solidity && FOUNDRY_PROFILE=ci forge snapshot --check
14+
cd solidity && FOUNDRY_PROFILE=ci forge snapshot --match-path test/gas/*.sol --check
1515

1616
.PHONY: solidity-build
1717
solidity-build:

solidity/.gas-snapshot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FCMGasSnapshotsTest:test_gas_deposit() (gas: 314629)
2-
FCMGasSnapshotsTest:test_gas_harvest() (gas: 164232)
3-
FCMGasSnapshotsTest:test_gas_rebalance() (gas: 115148)
4-
FCMGasSnapshotsTest:test_gas_redeem() (gas: 206572)
1+
FCMGasSnapshotsTest:test_gas_deposit() (gas: 318756)
2+
FCMGasSnapshotsTest:test_gas_harvest() (gas: 166758)
3+
FCMGasSnapshotsTest:test_gas_rebalance() (gas: 117675)
4+
FCMGasSnapshotsTest:test_gas_redeem() (gas: 209098)

solidity/src/FCMVault.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
1414
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
1515
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
1616
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
17+
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
1718
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
1819
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
1920

@@ -32,7 +33,7 @@ import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
3233
/// - External Rebalancing: Exposes a external rebalance() function to adjust LTV, preserve 100% net collateral
3334
/// exposure, maximize yield spread, and keep the position clear of liquidation thresholds.
3435
/// - ERC-4626 Tokenized Vault: Yield is auto-compounded directly into share price appreciation.
35-
contract FCMVault is IFCMVault, ERC20, Ownable2Step, IMorphoFlashLoanCallback {
36+
contract FCMVault is IFCMVault, ERC20, Ownable2Step, ReentrancyGuard, IMorphoFlashLoanCallback {
3637
using SafeERC20 for IERC20;
3738
using Math for uint256;
3839
using MorphoLib for IMorpho;
@@ -228,19 +229,19 @@ contract FCMVault is IFCMVault, ERC20, Ownable2Step, IMorphoFlashLoanCallback {
228229
}
229230

230231
/// @inheritdoc IFCMVault
231-
function accrueFees() external {
232+
function accrueFees() external nonReentrant {
232233
_accrueFees();
233234
}
234235

235236
/// @inheritdoc IFCMVault
236-
function rebalance() external logsVaultState {
237+
function rebalance() external nonReentrant logsVaultState {
237238
require(!emergencyRecovered, EmergencyRecoveryActive());
238239
_accrueFees();
239240
_adjustLeverage();
240241
}
241242

242243
/// @inheritdoc IFCMVault
243-
function harvest(uint256 maximumYield) external notInRecovery logsVaultState {
244+
function harvest(uint256 maximumYield) external nonReentrant notInRecovery logsVaultState {
244245
_accrueFees();
245246
_harvest(maximumYield);
246247
}
@@ -291,6 +292,7 @@ contract FCMVault is IFCMVault, ERC20, Ownable2Step, IMorphoFlashLoanCallback {
291292
function deposit(uint256 assets, address receiver)
292293
external
293294
override
295+
nonReentrant
294296
notInRecovery
295297
logsVaultState
296298
returns (uint256 shares)
@@ -332,6 +334,7 @@ contract FCMVault is IFCMVault, ERC20, Ownable2Step, IMorphoFlashLoanCallback {
332334
function redeem(uint256 shares, address receiver, address owner)
333335
external
334336
override
337+
nonReentrant
335338
logsVaultState
336339
returns (uint256 assets)
337340
{
@@ -357,6 +360,7 @@ contract FCMVault is IFCMVault, ERC20, Ownable2Step, IMorphoFlashLoanCallback {
357360
/// @inheritdoc IFCMVault
358361
function redeemInKind(uint256 shares, address receiver, address owner)
359362
external
363+
nonReentrant
360364
logsVaultState
361365
returns (uint256 collateralOut, uint256 yieldOut)
362366
{

0 commit comments

Comments
 (0)