Skip to content

Commit

Permalink
feat: script and changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Dec 21, 2023
1 parent 5337260 commit 232b754
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 30 deletions.
58 changes: 31 additions & 27 deletions contracts/debtAllocators/YieldManager/YieldManager.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: GPL-3.0
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.18;

import {IVault} from "@yearn-vaults/interfaces/IVault.sol";
Expand Down Expand Up @@ -48,7 +48,7 @@ contract YieldManager is Governance {

/// @notice Contract that holds the logic and oracles for each strategy.
AprOracle internal constant aprOracle =
AprOracle(0x02b0210fC1575b38147B232b40D7188eF14C04f2);
AprOracle(0xF012fBb9283e03994A7829fCE994a105cC066c14);

/// @notice Flag to set to allow anyone to propose allocations.
bool public open;
Expand All @@ -62,7 +62,7 @@ contract YieldManager is Governance {
/// @notice Mapping for vaults that can be allocated for => its debt allocator.
mapping(address => address) public vaultAllocator;

constructor(address _keeper, address _governance) Governance(_governance) {
constructor(address _governance, address _keeper) Governance(_governance) {
keeper = _keeper;
}

Expand Down Expand Up @@ -146,13 +146,6 @@ contract YieldManager is Governance {
// Add to the amount currently being earned.
_currentYield += _strategyApr;

// If no change move to the next strategy.
if (_newDebt == _currentDebt) {
// We assume the new apr will be the same as current.
_afterYield += _strategyApr;
continue;
}

// If we are withdrawing.
if (_currentDebt > _newDebt) {
// If we are pulling all debt from a strategy.
Expand All @@ -178,14 +171,24 @@ contract YieldManager is Governance {
? (_newDebt * MAX_BPS) / _totalAssets
: MAX_BPS;

// Update allocation.
GenericDebtAllocator(allocator).setStrategyDebtRatios(
_strategy,
_targetRatio
);
// If different than the current target.
if (
GenericDebtAllocator(allocator).getStrategyTargetRatio(
_strategy
) != _targetRatio
) {
// Update allocation.
GenericDebtAllocator(allocator).setStrategyDebtRatios(
_strategy,
_targetRatio
);
}

// Get the new APR
if (_newDebt != 0) {
// Add the expected change in APR based on new debt.
if (_newDebt == _currentDebt) {
// We assume the new apr will be the same as current.
_afterYield += _strategyApr;
} else if (_newDebt != 0) {
_afterYield += (aprOracle.getStrategyApr(
_strategy,
int256(_newDebt) - int256(_currentDebt)
Expand Down Expand Up @@ -300,11 +303,6 @@ contract YieldManager is Governance {
// Get the debt the strategy current has.
_currentDebt = IVault(_vault).strategies(_strategy).current_debt;

// If no change move to the next strategy.
if (_newDebt == _currentDebt) {
continue;
}

// If we are withdrawing.
if (_currentDebt > _newDebt) {
// If we are pulling all debt from a strategy.
Expand All @@ -330,11 +328,17 @@ contract YieldManager is Governance {
? (_newDebt * MAX_BPS) / _totalAssets
: MAX_BPS;

// Update allocation.
GenericDebtAllocator(allocator).setStrategyDebtRatios(
_strategy,
_targetRatio
);
if (
GenericDebtAllocator(allocator).getStrategyTargetRatio(
_strategy
) != _targetRatio
) {
// Update allocation.
GenericDebtAllocator(allocator).setStrategyDebtRatios(
_strategy,
_targetRatio
);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy_role_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from hexbytes import HexBytes
import hashlib

deployer = accounts.load("v3_deployer")
deployer = accounts.load("")


def deploy_role_manager():
Expand Down
63 changes: 63 additions & 0 deletions scripts/deploy_yield_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from ape import project, accounts, Contract, chain, networks, managers, compilers
from ape.utils import ZERO_ADDRESS
from hexbytes import HexBytes
import hashlib

deployer = accounts.load("")


def deploy_yield_manager():

print("Deploying Yield Manager on ChainID", chain.chain_id)

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

yield_manager = project.YieldManager
deployer_contract = project.Deployer.at(
"0x8D85e7c9A4e369E53Acc8d5426aE1568198b0112"
)

salt_string = "Yield Manager test"

# Create a SHA-256 hash object
hash_object = hashlib.sha256()
# Update the hash object with the string data
hash_object.update(salt_string.encode("utf-8"))
# Get the hexadecimal representation of the hash
hex_hash = hash_object.hexdigest()
# Convert the hexadecimal hash to an integer
salt = int(hex_hash, 16)

print(f"Salt we are using {salt}")
print("Init balance:", deployer.balance / 1e18)

print(f"Deploying the Yield Manager...")
print("Enter the addresses to use on deployment.")

gov = input("Governance? ")
keeper = input("Keeper? ")

constructor = yield_manager.constructor.encode_input(
gov,
keeper,
)

deploy_bytecode = HexBytes(
HexBytes(yield_manager.contract_type.deployment_bytecode.bytecode) + constructor
)

tx = deployer_contract.deploy(deploy_bytecode, salt, sender=deployer)

event = list(tx.decode_logs(deployer_contract.Deployed))

address = event[0].addr

print("------------------")
print(f"Deployed the Yield Manager to {address}")
print("------------------")
print(f"Encoded Constructor to use for verifaction {constructor.hex()[2:]}")


def main():
deploy_yield_manager()
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def keeper(deploy_keeper):
@pytest.fixture(scope="session")
def deploy_yield_manager(project, daddy, keeper):
def deploy_yield_manager():
yield_manager = daddy.deploy(project.YieldManager, keeper, daddy)
yield_manager = daddy.deploy(project.YieldManager, daddy, keeper)

return yield_manager

Expand All @@ -500,6 +500,6 @@ def yield_manager(deploy_yield_manager):
@pytest.fixture(scope="session")
def apr_oracle(project):
oracle = project.MockOracle
address = "0x02b0210fC1575b38147B232b40D7188eF14C04f2"
address = "0xF012fBb9283e03994A7829fCE994a105cC066c14"
networks.provider.set_code(address, oracle.contract_type.runtime_bytecode.bytecode)
yield oracle.at(address)

0 comments on commit 232b754

Please sign in to comment.