Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: DOA multicall support #49

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/debtAllocators/DebtOptimizerApplicator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
}
Loading