From 68b201f38716a8ab5aa5cedce51a90f52c89578b Mon Sep 17 00:00:00 2001 From: FP <83050944+fp-crypto@users.noreply.github.com> Date: Mon, 21 Oct 2024 10:43:14 -0700 Subject: [PATCH] feat: DOA multicall support (#49) * fix: circular dependency * feat: doa multicall support * chore: add multicall test --- .../DebtOptimizerApplicator.sol | 3 +- ....sol => TestDebtOptimizerApplicator.t.sol} | 56 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) rename src/test/debtAllocators/{TestDebtOptimizerApplicatory.t.sol => TestDebtOptimizerApplicator.t.sol} (70%) diff --git a/src/debtAllocators/DebtOptimizerApplicator.sol b/src/debtAllocators/DebtOptimizerApplicator.sol index 4b96e72..a65b7f7 100644 --- a/src/debtAllocators/DebtOptimizerApplicator.sol +++ b/src/debtAllocators/DebtOptimizerApplicator.sol @@ -2,8 +2,9 @@ pragma solidity >=0.8.18; import {DebtAllocator} from "./DebtAllocator.sol"; +import {Multicall} from "@openzeppelin/contracts/utils/Multicall.sol"; -contract DebtOptimizerApplicator { +contract DebtOptimizerApplicator is Multicall { /// @notice An event emitted when a keeper is added or removed. event UpdateManager(address indexed manager, bool allowed); diff --git a/src/test/debtAllocators/TestDebtOptimizerApplicatory.t.sol b/src/test/debtAllocators/TestDebtOptimizerApplicator.t.sol similarity index 70% rename from src/test/debtAllocators/TestDebtOptimizerApplicatory.t.sol rename to src/test/debtAllocators/TestDebtOptimizerApplicator.t.sol index 514c711..3ee6d07 100644 --- a/src/test/debtAllocators/TestDebtOptimizerApplicatory.t.sol +++ b/src/test/debtAllocators/TestDebtOptimizerApplicator.t.sol @@ -144,4 +144,60 @@ contract TestDebtOptimizerApplicator is Setup { assertEq(strategyConfig.targetRatio, 2_000); assertEq(strategyConfig.maxRatio, 2_400); // 2_000 * 1.2 } + + function test_set_ratios_multicall(uint8 _vaultCount) public { + vm.assume(_vaultCount > 0); + + vm.prank(brain); + debtAllocator.setManager(address(debtOptimizerApplicator), true); + + bytes[] memory multicallData = new bytes[](_vaultCount); + IVault[] memory vaults = new IVault[](_vaultCount); + for (uint8 i; i < _vaultCount; ++i) { + vaults[i] = createVault( + address(asset), + daddy, + MAX_INT, + WEEK, + string(abi.encodePacked("Test Vault ", i)), + "tvTEST" + ); + + vm.prank(brain); + debtAllocator.setMinimumChange(address(vaults[i]), 1); + + DebtOptimizerApplicator.StrategyDebtRatio[] + memory strategyDebtRatios = new DebtOptimizerApplicator.StrategyDebtRatio[]( + 1 + ); + strategyDebtRatios[0] = DebtOptimizerApplicator.StrategyDebtRatio( + address(strategy), + 2_000, + (i % 2 == 0) ? 0 : 3_000 // alternate between setting and not setting maxDebt + ); + + multicallData[i] = abi.encodeCall( + debtOptimizerApplicator.setStrategyDebtRatios, + (address(vaults[i]), strategyDebtRatios) + ); + } + + vm.prank(user); + vm.expectRevert("!manager"); + debtOptimizerApplicator.multicall(multicallData); + + vm.prank(brain); + debtOptimizerApplicator.multicall(multicallData); + + for (uint8 i; i < _vaultCount; ++i) { + DebtAllocator.StrategyConfig memory strategyConfig = debtAllocator + .getStrategyConfig(address(vaults[i]), address(strategy)); + assertTrue(strategyConfig.added); + assertEq(strategyConfig.targetRatio, 2_000); + assertEq( + strategyConfig.maxRatio, + (i % 2 == 0) ? (2_000 * 12) / 10 : 3_000 + ); + } + } }