Skip to content

Commit

Permalink
chore: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Jan 8, 2024
1 parent 3c3eb3c commit a390e09
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
22 changes: 16 additions & 6 deletions contracts/debtAllocators/YieldManager/YieldManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ contract YieldManager is Governance {
* and debt increases at the end.
* - Account for all limiting values such as the vaults max_debt and min_total_idle
* as well as the strategies maxDeposit/maxRedeem that are enforced on debt updates.
* - Account for the expected differences in amounts caused unrealised losses or profits.
* - Account for the expected differences in amounts caused by unrealised losses or profits.
*
* @param _vault The address of the vault to propose an allocation for.
* @param _newAllocations Array of strategies and their new proposed allocation.
Expand Down Expand Up @@ -110,6 +110,8 @@ contract YieldManager is Governance {
address _strategy;
uint256 _currentDebt;
uint256 _newDebt;
uint256 _strategyRate;
uint256 _targetRatio;
for (uint256 i = 0; i < _newAllocations.length; ++i) {
_strategy = _newAllocations[i].strategy;
_newDebt = uint256(_newAllocations[i].newDebt);
Expand All @@ -119,7 +121,7 @@ contract YieldManager is Governance {
_accountedFor += _currentDebt;

// Get the current weighted rate the strategy is earning
uint256 _strategyRate = (aprOracle.getStrategyApr(_strategy, 0) *
_strategyRate = (aprOracle.getStrategyApr(_strategy, 0) *
_currentDebt);

// Add to the amount currently being earned.
Expand Down Expand Up @@ -170,7 +172,7 @@ contract YieldManager is Governance {
}

// Get the target based on the new debt.
uint256 _targetRatio = _newDebt < _totalAssets
_targetRatio = _newDebt < _totalAssets
? (_newDebt * MAX_BPS) / _totalAssets
: MAX_BPS;

Expand Down Expand Up @@ -249,7 +251,7 @@ contract YieldManager is Governance {
* @return _currentRate The current weighted rate that the collective strategies are earning.
* @return _expectedRate The expected weighted rate that the collective strategies would earn.
*/
function getCurrentAndExpectedYield(
function getCurrentAndExpectedRate(
address _vault,
Allocation[] memory _newAllocations
)
Expand All @@ -267,13 +269,14 @@ contract YieldManager is Governance {
uint256 _newDebt;
address _strategy;
uint256 _currentDebt;
uint256 _strategyRate;
for (uint256 i = 0; i < _newAllocations.length; ++i) {
_newDebt = uint256(_newAllocations[i].newDebt);
_strategy = _newAllocations[i].strategy;
_currentDebt = IVault(_vault).strategies(_strategy).current_debt;

// Get the current weighted rate the strategy is earning
uint256 _strategyRate = (aprOracle.getStrategyApr(_strategy, 0) *
_strategyRate = (aprOracle.getStrategyApr(_strategy, 0) *
_currentDebt);

// Add to the amount currently being earned.
Expand All @@ -299,8 +302,14 @@ contract YieldManager is Governance {
* its strategies and their specific allocation.
*
* The `_newAllocations` array should:
* - Contain all strategies that hold any amount of debt from the vault
* even if the debt wont be adjusted in order to get the correct
* on chain rate.
* - Be ordered so that all debt decreases are at the beginning of the array
* and debt increases at the end.
* - Account for all limiting values such as the vaults max_debt and min_total_idle
* as well as the strategies maxDeposit/maxRedeem that are enforced on debt updates.
* - Account for the expected differences in amounts caused by unrealised losses or profits.
*
* This will not do any APR checks and assumes the sender has completed
* any and all necessary checks before sending.
Expand All @@ -317,6 +326,7 @@ contract YieldManager is Governance {
address _strategy;
uint256 _newDebt;
uint256 _currentDebt;
uint256 _targetRatio;
uint256 _totalAssets = IVault(_vault).totalAssets();
for (uint256 i = 0; i < _newAllocations.length; ++i) {
_strategy = _newAllocations[i].strategy;
Expand Down Expand Up @@ -368,7 +378,7 @@ contract YieldManager is Governance {
}

// Get the target based on the new debt.
uint256 _targetRatio = _newDebt < _totalAssets
_targetRatio = _newDebt < _totalAssets
? (_newDebt * MAX_BPS) / _totalAssets
: MAX_BPS;

Expand Down
13 changes: 10 additions & 3 deletions scripts/deploy_allocator_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@


def deploy_allocator_factory():
print("Deploying Generic Debt Allocator Factory on ChainID", chain.chain_id)
print("Deploying Debt Allocator Factory on ChainID", chain.chain_id)

if input("Do you want to continue? ") == "n":
return

allocator_factory = project.GenericDebtAllocatorFactory
allocator_factory = project.DebtAllocatorFactory
deployer_contract = project.Deployer.at(
"0x8D85e7c9A4e369E53Acc8d5426aE1568198b0112"
)

salt_string = "Generic Debt Allocator Factory"
salt_string = "Debt Allocator Factory"

# Create a SHA-256 hash object
hash_object = hashlib.sha256()
Expand All @@ -34,9 +34,14 @@ def deploy_allocator_factory():
print(f"Salt we are using {salt}")
print("Init balance:", deployer.balance / 1e18)

gov = input("Governance? ")

allocator_constructor = allocator_factory.constructor.encode_input(gov)

# generate and deploy
deploy_bytecode = HexBytes(
HexBytes(allocator_factory.contract_type.deployment_bytecode.bytecode)
+ allocator_constructor
)

print(f"Deploying the Factory...")
Expand All @@ -50,6 +55,8 @@ def deploy_allocator_factory():
print("------------------")
print(f"Deployed the Factory to {address}")
print("------------------")
print(f"Encoded Constructor to use for verifaction {allocator_constructor.hex()[2:]}")



def main():
Expand Down
10 changes: 4 additions & 6 deletions tests/debtAllocators/yield/test_yield_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,27 +589,25 @@ def test_get_current_and_expected(
vault.deposit(amount, user, sender=user)

allocation = []
(current, expected) = yield_manager.getCurrentAndExpectedYield(vault, allocation)
(current, expected) = yield_manager.getCurrentAndExpectedRate(vault, allocation)

assert current == 0
assert expected == 0

allocation = [(strategy_one, 0), (strategy_two, 0)]
(current, expected) = yield_manager.getCurrentAndExpectedYield(vault, allocation)
(current, expected) = yield_manager.getCurrentAndExpectedRate(vault, allocation)
assert current == 0
assert expected == 0

allocation = [(strategy_one, amount), (strategy_two, 0)]
(current, expected) = yield_manager.getCurrentAndExpectedYield(vault, allocation)
(current, expected) = yield_manager.getCurrentAndExpectedRate(vault, allocation)
assert current == 0
assert expected != 0

vault.update_debt(strategy_one, amount, sender=daddy)

allocation = [(strategy_one, 0), (strategy_two, amount)]
(current, new_expected) = yield_manager.getCurrentAndExpectedYield(
vault, allocation
)
(current, new_expected) = yield_manager.getCurrentAndExpectedRate(vault, allocation)
assert current == expected
assert expected != 0
assert expected > 0
Expand Down

0 comments on commit a390e09

Please sign in to comment.