Skip to content

Commit

Permalink
feat: debt optimizer applicator
Browse files Browse the repository at this point in the history
  • Loading branch information
fp-crypto committed May 30, 2024
1 parent 26c43a9 commit 7e6ae1a
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions contracts/debtAllocators/DebtOptimizerApplicator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// SPDX-License-Identifier: GNU AGPLv3
pragma solidity >=0.8.18;

import {DebtAllocator, DebtAllocatorFactory} from "./DebtAllocator.sol";

contract DebtOptimizerApplicator {
/// @notice Make sure the caller is governance.
modifier onlyGovernance() {
_isGovernance();
_;
}

/// @notice Make sure the caller is governance or a manager.
modifier onlyManagers() {
_isManager();
_;
}

/// @notice Make sure the caller is a keeper
modifier onlyKeepers() {
_isKeeper();
_;
}

/// @notice Check the Factories governance address.
function _isGovernance() internal view virtual {
require(
msg.sender ==
DebtAllocatorFactory(debtAllocatorFactory).governance(),
"!governance"
);
}

/// @notice Check is either factories governance or local manager.
function _isManager() internal view virtual {
require(
managers[msg.sender] ||
msg.sender ==
DebtAllocatorFactory(debtAllocatorFactory).governance(),
"!manager"
);
}

/// @notice Check is one of the allowed keepers.
function _isKeeper() internal view virtual {
require(
DebtAllocatorFactory(debtAllocatorFactory).keepers(msg.sender),
"!keeper"
);
}

struct StrategyDebtRatio {
address strategy;
uint256 targetRatio;
uint256 maxRatio;
}

/// @notice The address of the debt allocator factory to use for some role checks.
address public immutable debtAllocatorFactory;

/// @notice Mapping of addresses that are allowed to update debt ratios.
mapping(address => bool) public managers;

constructor(address _debtAllocatorFactory) {
debtAllocatorFactory = _debtAllocatorFactory;
}

/**
* @notice Set if a manager can update ratios.
* @param _address The address to set mapping for.
* @param _allowed If the address can call {update_debt}.
*/
function setManager(
address _address,
bool _allowed
) external virtual onlyGovernance {
managers[_address] = _allowed;

emit UpdateManager(_address, _allowed);
}

function setStrategyDebtRatios(
DebtAllocator _debtAllocator,
StrategyDebtRatio[] memory _strategyDebtRatios // TODO: use calldata instead of memory?
) public onlyManagers {
for (uint8 i; i < _strategyDebtRatios.length; ++i) {
if (_strategyDebtRatios[i].maxRatio == 0) {
_debtAllocator.setStrategyDebtRatio(
_strategyDebtRatios[i].strategy,
_strategyDebtRatios[i].targetRatio,
_strategyDebtRatios[i].maxRatio
);
} else {
_debtAllocator.setStrategyDebtRatio(
_strategyDebtRatios[i].strategy,
_strategyDebtRatios[i].targetRatio
);
}
}
}
}

0 comments on commit 7e6ae1a

Please sign in to comment.