Skip to content

Commit 64abb0e

Browse files
authored
Merge branch 'dev' into dev-1126-safety-checks-erc4626
2 parents ce46e1d + c12f481 commit 64abb0e

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

src/MainnetController.sol

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,15 @@ contract MainnetController is ReentrancyGuard, AccessControlEnumerable {
273273
function setOTCBuffer(address exchange, address otcBuffer) external nonReentrant {
274274
_checkRole(DEFAULT_ADMIN_ROLE);
275275

276-
require(exchange != address(0), "MC/exchange-zero-address");
277-
require(exchange != otcBuffer, "MC/exchange-equals-otcBuffer");
276+
require(exchange != address(0), "MC/exchange-zero-address");
277+
require(otcBuffer != address(0), "MC/otcBuffer-zero-address");
278+
require(exchange != otcBuffer, "MC/exchange-equals-otcBuffer");
278279

279280
OTC storage otc = otcs[exchange];
280281

282+
// Prevent rotating buffer while a swap is pending and not ready
283+
require(otc.sentTimestamp == 0 || isOtcSwapReady(exchange), "MC/swap-in-progress");
284+
281285
emit OTCBufferSet(exchange, otc.buffer, otcBuffer);
282286
otc.buffer = otcBuffer;
283287
}
@@ -1075,8 +1079,7 @@ contract MainnetController is ReentrancyGuard, AccessControlEnumerable {
10751079

10761080
OTC storage otc = otcs[exchange];
10771081

1078-
// Just to check that OTC buffer exists
1079-
require(otc.buffer != address(0), "MC/otc-buffer-not-set");
1082+
// Its impossible to have zero address buffer because of whitelistedAssets.
10801083
require(isOtcSwapReady(exchange), "MC/last-swap-not-returned");
10811084

10821085
otc.sent18 = sent18;

test/mainnet-fork/OTCSwaps.t.sol

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@ contract MainnetControllerOTCSwapBase is ForkTestBase {
9898

9999
}
100100

101+
// NOTE: This test requires the send to be executed first which requires ForkTestBase,
102+
// therefore it is placed here instead of Admin.t.sol.
103+
contract MainnetControllerSetOTCBufferFailureTests is MainnetControllerOTCSwapBase {
104+
105+
function test_setOTCBuffer_swapInProgress() external {
106+
deal(address(usdt), address(almProxy), 5_000_000e6);
107+
108+
// Execute OTC swap
109+
vm.prank(relayer);
110+
mainnetController.otcSend(exchange, address(usdt), 5_000_000e6);
111+
112+
vm.expectRevert("MC/swap-in-progress");
113+
vm.prank(Ethereum.SPARK_PROXY);
114+
mainnetController.setOTCBuffer(exchange, makeAddr("new-buffer"));
115+
}
116+
117+
}
118+
101119
contract MainnetControllerOtcSendFailureTests is MainnetControllerOTCSwapBase {
102120

103121
function test_otcSend_reentrancy() external {
@@ -166,15 +184,6 @@ contract MainnetControllerOtcSendFailureTests is MainnetControllerOTCSwapBase {
166184
mainnetController.otcSend(exchange, address(usds), 10_000_000e18);
167185
}
168186

169-
function test_otcSend_otcBufferNotSet() external {
170-
vm.prank(Ethereum.SPARK_PROXY);
171-
mainnetController.setOTCBuffer(exchange, address(0));
172-
173-
vm.prank(relayer);
174-
vm.expectRevert("MC/otc-buffer-not-set");
175-
mainnetController.otcSend(exchange, address(usdt), 1e6);
176-
}
177-
178187
function test_otcSend_transferFailed() external {
179188
address token = address(new MockTokenReturnFalse());
180189

test/unit/controllers/Admin.t.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ contract MainnetControllerSetOTCBufferTests is MainnetControllerAdminTestBase {
247247
mainnetController.setOTCBuffer(address(0), address(otcBuffer));
248248
}
249249

250+
function test_setOTCBuffer_otcBufferZero() external {
251+
vm.prank(admin);
252+
vm.expectRevert("MC/otcBuffer-zero-address");
253+
mainnetController.setOTCBuffer(exchange, address(0));
254+
}
255+
250256
function test_setOTCBuffer_exchangeEqualsOTCBuffer() external {
251257
vm.prank(admin);
252258
vm.expectRevert("MC/exchange-equals-otcBuffer");

0 commit comments

Comments
 (0)