From a390e09f5f6e9cc2e19877e10aa80bf2422ff9cc Mon Sep 17 00:00:00 2001 From: Schlagonia Date: Mon, 8 Jan 2024 16:58:45 -0700 Subject: [PATCH] chore: comments --- .../YieldManager/YieldManager.sol | 22 ++++++++++++++----- scripts/deploy_allocator_factory.py | 13 ++++++++--- .../yield/test_yield_manager.py | 10 ++++----- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/contracts/debtAllocators/YieldManager/YieldManager.sol b/contracts/debtAllocators/YieldManager/YieldManager.sol index d26f61a..61ec991 100644 --- a/contracts/debtAllocators/YieldManager/YieldManager.sol +++ b/contracts/debtAllocators/YieldManager/YieldManager.sol @@ -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. @@ -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); @@ -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. @@ -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; @@ -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 ) @@ -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. @@ -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. @@ -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; @@ -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; diff --git a/scripts/deploy_allocator_factory.py b/scripts/deploy_allocator_factory.py index 80d958e..99b80e1 100644 --- a/scripts/deploy_allocator_factory.py +++ b/scripts/deploy_allocator_factory.py @@ -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() @@ -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...") @@ -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(): diff --git a/tests/debtAllocators/yield/test_yield_manager.py b/tests/debtAllocators/yield/test_yield_manager.py index 387a652..dbac718 100644 --- a/tests/debtAllocators/yield/test_yield_manager.py +++ b/tests/debtAllocators/yield/test_yield_manager.py @@ -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