Skip to content

Commit 78e1f7e

Browse files
committed
fix: PR review
1 parent 8d18c18 commit 78e1f7e

File tree

8 files changed

+17
-58
lines changed

8 files changed

+17
-58
lines changed

src/ForeignController.sol

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,10 @@ contract ForeignController is ReentrancyGuard, AccessControlEnumerable {
349349
rateLimitedAddress(LIMIT_4626_DEPOSIT, token, amount)
350350
returns (uint256 shares)
351351
{
352-
uint256 maxExchangeRate = maxExchangeRates[token];
353-
354-
require(maxExchangeRate != 0, "FC/max-exchange-rate-not-set");
355-
356352
// Approve asset to token from the proxy (assumes the proxy has enough of the asset).
357353
_approve(IERC4626(token).asset(), token, amount);
358354

359-
// Deposit asset into the token, proxy receives token shares, decode the resulting shares
355+
// Deposit asset into the token, proxy receives token shares, decode the resulting shares.
360356
shares = abi.decode(
361357
proxy.doCall(
362358
token,
@@ -365,10 +361,7 @@ contract ForeignController is ReentrancyGuard, AccessControlEnumerable {
365361
(uint256)
366362
);
367363

368-
require(
369-
_getExchangeRate(shares, amount) <= maxExchangeRate,
370-
"FC/exchange-rate-too-high"
371-
);
364+
require(_getExchangeRate(shares, amount) <= maxExchangeRates[token], "FC/exchange-rate-too-high");
372365
}
373366

374367
function withdrawERC4626(address token, uint256 amount)

src/MainnetController.sol

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,10 @@ contract MainnetController is ReentrancyGuard, AccessControlEnumerable {
458458
_checkRole(RELAYER);
459459
_rateLimitedAddress(LIMIT_4626_DEPOSIT, token, amount);
460460

461-
uint256 maxExchangeRate = maxExchangeRates[token];
462-
463-
require(maxExchangeRate != 0, "MC/max-exchange-rate-not-set");
464-
465461
// Approve asset to token from the proxy (assumes the proxy has enough of the asset).
466462
_approve(IERC4626(token).asset(), token, amount);
467463

468-
// Deposit asset into the token, proxy receives token shares, decode the resulting shares
464+
// Deposit asset into the token, proxy receives token shares, decode the resulting shares.
469465
shares = abi.decode(
470466
proxy.doCall(
471467
token,
@@ -474,10 +470,7 @@ contract MainnetController is ReentrancyGuard, AccessControlEnumerable {
474470
(uint256)
475471
);
476472

477-
require(
478-
_getExchangeRate(shares, amount) <= maxExchangeRate,
479-
"MC/rate-too-high"
480-
);
473+
require(_getExchangeRate(shares, amount) <= maxExchangeRates[token], "MC/exchange-rate-too-high");
481474
}
482475

483476
function withdrawERC4626(address token, uint256 amount)

test/base-fork/Morpho.t.sol

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ contract MorphoBaseTest is ForkTestBase {
102102
uint256(5_000_000e6) / 1 days
103103
);
104104

105-
foreignController.setMaxExchangeRate(MORPHO_VAULT_USDS, 1e18, usdsVault.convertToAssets(1e18));
106-
foreignController.setMaxExchangeRate(MORPHO_VAULT_USDC, 1e18, usdcVault.convertToAssets(1e18));
105+
foreignController.setMaxExchangeRate(MORPHO_VAULT_USDS, usdsVault.convertToShares(1e18), 1e18);
106+
foreignController.setMaxExchangeRate(MORPHO_VAULT_USDC, usdcVault.convertToShares(1e18), 1e18);
107107

108108
vm.stopPrank();
109109
}
@@ -162,28 +162,19 @@ contract MorphoDepositFailureTests is MorphoBaseTest {
162162
foreignController.depositERC4626(MORPHO_VAULT_USDC, 25_000_000e6);
163163
}
164164

165-
function test_morpho_deposit_maxExchangeRateNotSet() external {
166-
vm.prank(Base.SPARK_EXECUTOR);
167-
foreignController.setMaxExchangeRate(MORPHO_VAULT_USDS, 0, 0);
168-
169-
vm.prank(relayer);
170-
vm.expectRevert("FC/max-exchange-rate-not-set");
171-
foreignController.depositERC4626(MORPHO_VAULT_USDS, 1_000_000e18);
172-
}
173-
174165
function test_depositERC4626_exchangeRateBoundary() external {
175166
deal(Base.USDS, address(almProxy), 25_000_000e18);
176167

177168
vm.startPrank(Base.SPARK_EXECUTOR);
178-
foreignController.setMaxExchangeRate(MORPHO_VAULT_USDS, 1e18, usdsVault.convertToAssets(1e18) - 1);
169+
foreignController.setMaxExchangeRate(MORPHO_VAULT_USDS, usdsVault.convertToShares(1e18) - 1, 1e18);
179170
vm.stopPrank();
180171

181172
vm.prank(relayer);
182173
vm.expectRevert("FC/exchange-rate-too-high");
183174
foreignController.depositERC4626(MORPHO_VAULT_USDS, 25_000_000e18);
184175

185176
vm.startPrank(Base.SPARK_EXECUTOR);
186-
foreignController.setMaxExchangeRate(MORPHO_VAULT_USDS, 1e18, usdsVault.convertToAssets(1e18));
177+
foreignController.setMaxExchangeRate(MORPHO_VAULT_USDS, usdsVault.convertToShares(1e18), 1e18);
187178
vm.stopPrank();
188179

189180
vm.prank(relayer);

test/base-fork/MorphoAllocations.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ contract MorphoReallocateMorphoSuccessTests is MorphoTestBase {
219219
25_000_000e6,
220220
uint256(5_000_000e6) / 1 days
221221
);
222-
foreignController.setMaxExchangeRate(address(morphoVault), 1_000_000e6, morphoVault.convertToAssets(2_000_000e6));
222+
foreignController.setMaxExchangeRate(address(morphoVault), morphoVault.convertToShares(1_000_000e6), 1_100_000e6);
223223
vm.stopPrank();
224224

225225
// Refresh markets so calculations don't include interest

test/mainnet-fork/4626Calls.t.sol

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ contract SUSDSTestBase is ForkTestBase {
2828
rateLimits.setRateLimitData(mainnetController.LIMIT_USDS_MINT(), 10_000_000e18, uint256(10_000_000e18) / 4 hours);
2929
rateLimits.setRateLimitData(depositKey, 5_000_000e18, uint256(1_000_000e18) / 4 hours);
3030
rateLimits.setRateLimitData(withdrawKey, 5_000_000e18, uint256(1_000_000e18) / 4 hours);
31-
mainnetController.setMaxExchangeRate(address(susds), 1e18, susds.convertToAssets(1.2e18));
31+
mainnetController.setMaxExchangeRate(address(susds), susds.convertToShares(1e18), 1.2e18);
3232
vm.stopPrank();
3333

3434
SUSDS_CONVERTED_ASSETS = susds.convertToAssets(1e18);
@@ -86,29 +86,20 @@ contract MainnetControllerDepositERC4626FailureTests is SUSDSTestBase {
8686
vm.stopPrank();
8787
}
8888

89-
function test_depositERC4626_maxExchangeRateNotSet() external {
90-
vm.prank(Ethereum.SPARK_PROXY);
91-
mainnetController.setMaxExchangeRate(address(susds), 0, 0);
92-
93-
vm.prank(relayer);
94-
vm.expectRevert("MC/max-exchange-rate-not-set");
95-
mainnetController.depositERC4626(address(susds), 1e18);
96-
}
97-
9889
function test_depositERC4626_exchangeRateBoundary() external {
9990
vm.prank(relayer);
10091
mainnetController.mintUSDS(5_000_000e18);
10192

10293
vm.startPrank(Ethereum.SPARK_PROXY);
103-
mainnetController.setMaxExchangeRate(address(susds), 5_000_000e18, susds.convertToAssets(5_000_000e18));
94+
mainnetController.setMaxExchangeRate(address(susds), susds.convertToShares(5_000_000e18), 5_000_000e18 - 1);
10495
vm.stopPrank();
10596

10697
vm.prank(relayer);
10798
vm.expectRevert("MC/exchange-rate-too-high");
10899
mainnetController.depositERC4626(address(susds), 5_000_000e18);
109100

110101
vm.startPrank(Ethereum.SPARK_PROXY);
111-
mainnetController.setMaxExchangeRate(address(susds), 5_000_000e18, susds.convertToAssets(5_000_001e18));
102+
mainnetController.setMaxExchangeRate(address(susds), susds.convertToShares(5_000_000e18), 5_000_000e18);
112103
vm.stopPrank();
113104

114105
vm.prank(relayer);

test/mainnet-fork/ERC4626DonationAttack.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ contract ERC4626DonationAttack is ERC4626DonationAttackTestBase {
8686

8787
function test_depositERC4626_donationAttackFailure() external {
8888
vm.startPrank(Ethereum.SPARK_PROXY);
89-
mainnetController.setMaxExchangeRate(address(morphoVault), 1e18, morphoVault.convertToAssets(1.2e18));
89+
mainnetController.setMaxExchangeRate(address(morphoVault), morphoVault.convertToShares(1e18), 1.2e18);
9090
vm.stopPrank();
9191

9292
_doAttack();

test/mainnet-fork/Ethena.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ contract MainnetControllerEthenaE2ETests is EthenaTestBase {
661661
rateLimits.setRateLimitData(depositKey, 5_000_000e18, uint256(1_000_000e18) / 4 hours);
662662
rateLimits.setRateLimitData(mintKey, 5_000_000e6, uint256(1_000_000e6) / 4 hours);
663663

664-
mainnetController.setMaxExchangeRate(address(susde), 1e18, susde.convertToAssets(1.2e18));
664+
mainnetController.setMaxExchangeRate(address(susde), susde.convertToShares(1e18), 1.2e18);
665665

666666
vm.stopPrank();
667667
}

test/mainnet-fork/Maple.t.sol

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ contract MapleTestBase is ForkTestBase {
5656
vm.startPrank(Ethereum.SPARK_PROXY);
5757
rateLimits.setRateLimitData(depositKey, 1_000_000e6, uint256(1_000_000e6) / 1 days);
5858
rateLimits.setRateLimitData(redeemKey, 1_000_000e6, uint256(1_000_000e6) / 1 days);
59-
mainnetController.setMaxExchangeRate(address(syrup), 1e18, syrup.convertToAssets(1.2e18));
59+
mainnetController.setMaxExchangeRate(address(syrup), syrup.convertToShares(1e18), 2e18);
6060
vm.stopPrank();
6161

6262
// Maple onboarding process
@@ -126,28 +126,19 @@ contract MainnetControllerDepositERC4626MapleFailureTests is MapleTestBase {
126126
mainnetController.depositERC4626(address(syrup), 1_000_000e6);
127127
}
128128

129-
function test_depositERC4626_maple_maxExchangeRateNotSet() external {
130-
vm.prank(Ethereum.SPARK_PROXY);
131-
mainnetController.setMaxExchangeRate(address(syrup), 0, 0);
132-
133-
vm.prank(relayer);
134-
vm.expectRevert("MC/max-exchange-rate-not-set");
135-
mainnetController.depositERC4626(address(syrup), 1_000_000e6);
136-
}
137-
138129
function test_depositERC4626_maple_exchangeRateTooHigh() external {
139130
deal(address(usdc), address(almProxy), 1_000_000e6);
140131

141132
vm.startPrank(Ethereum.SPARK_PROXY);
142-
mainnetController.setMaxExchangeRate(address(syrup), 1_000_000e6, syrup.convertToAssets(1_000_000e6));
133+
mainnetController.setMaxExchangeRate(address(syrup), syrup.convertToShares(1_000_000e6), 1_000_000e6 - 1);
143134
vm.stopPrank();
144135

145136
vm.prank(relayer);
146137
vm.expectRevert("MC/exchange-rate-too-high");
147138
mainnetController.depositERC4626(address(syrup), 1_000_000e6);
148139

149140
vm.startPrank(Ethereum.SPARK_PROXY);
150-
mainnetController.setMaxExchangeRate(address(syrup), 1_000_000e6, syrup.convertToAssets(1_000_001e6));
141+
mainnetController.setMaxExchangeRate(address(syrup), syrup.convertToShares(1_000_000e6), 1_000_000e6);
151142
vm.stopPrank();
152143

153144
vm.prank(relayer);

0 commit comments

Comments
 (0)