Skip to content

Commit

Permalink
feat: DOA multicall support (#49)
Browse files Browse the repository at this point in the history
* fix: circular dependency

* feat: doa multicall support

* chore: add multicall test
  • Loading branch information
fp-crypto authored Oct 21, 2024
1 parent 148d4e7 commit 68b201f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
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
);
}
}
}

0 comments on commit 68b201f

Please sign in to comment.