From d7d5e975c910408fae9fdf1584b4f6b57221ee29 Mon Sep 17 00:00:00 2001 From: Schlagonia Date: Tue, 24 Oct 2023 15:07:56 -0600 Subject: [PATCH] commited --- ape-config.yaml | 1 + .../accountants/HelathCheckAccountant.sol | 5 +- .../debtAllocators/GenericDebtAllocator.sol | 2 +- .../GenericDebtAllocatorFactory.sol | 7 +- scripts/deploy_accountant.py | 127 ++++++++++++++++++ scripts/deploy_address_provider.py | 2 + scripts/deploy_allocator_factory.py | 54 ++++++++ scripts/deploy_registry.py | 4 + tests/conftest.py | 6 +- 9 files changed, 197 insertions(+), 11 deletions(-) create mode 100644 scripts/deploy_accountant.py create mode 100644 scripts/deploy_allocator_factory.py diff --git a/ape-config.yaml b/ape-config.yaml index 858dc57..12e5e6f 100644 --- a/ape-config.yaml +++ b/ape-config.yaml @@ -6,6 +6,7 @@ plugins: - name: etherscan - name: hardhat - name: infura + - name: polygon default_ecosystem: ethereum diff --git a/contracts/accountants/HelathCheckAccountant.sol b/contracts/accountants/HelathCheckAccountant.sol index 098659c..f5bf8ce 100644 --- a/contracts/accountants/HelathCheckAccountant.sol +++ b/contracts/accountants/HelathCheckAccountant.sol @@ -1,11 +1,11 @@ -// SPDX-License-Identifier: GNU AGPLv3 +// SPDX-License-Identifier: AGPL-3.0 pragma solidity 0.8.18; import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; -import "@yearn-vaults/interfaces/IVault.sol"; +import {IVault} from "@yearn-vaults/interfaces/IVault.sol"; contract HealthCheckAccountant { using SafeERC20 for ERC20; @@ -125,7 +125,6 @@ contract HealthCheckAccountant { defaultPerformance <= PERFORMANCE_FEE_THRESHOLD, "exceeds performance fee threshold" ); - require(defaultMaxFee <= MAX_BPS, "too high"); require(defaultMaxGain <= MAX_BPS, "too high"); require(defaultMaxLoss <= MAX_BPS, "too high"); diff --git a/contracts/debtAllocators/GenericDebtAllocator.sol b/contracts/debtAllocators/GenericDebtAllocator.sol index 0575924..c06a72e 100644 --- a/contracts/debtAllocators/GenericDebtAllocator.sol +++ b/contracts/debtAllocators/GenericDebtAllocator.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-3.0 +// SPDX-License-Identifier: AGPL-3.0 pragma solidity 0.8.18; import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; diff --git a/contracts/debtAllocators/GenericDebtAllocatorFactory.sol b/contracts/debtAllocators/GenericDebtAllocatorFactory.sol index 1101fbd..fa1b236 100644 --- a/contracts/debtAllocators/GenericDebtAllocatorFactory.sol +++ b/contracts/debtAllocators/GenericDebtAllocatorFactory.sol @@ -16,10 +16,9 @@ contract GenericDebtAllocatorFactory { // Original allocator to use for cloning. address public immutable original; - constructor(address _vault, address _governance) { - original = address(new GenericDebtAllocator(_vault, _governance)); - - emit NewDebtAllocator(original, _vault); + constructor() { + // Deploy dummy version for original. + original = address(new GenericDebtAllocator(address(1), address(2))); } /** diff --git a/scripts/deploy_accountant.py b/scripts/deploy_accountant.py new file mode 100644 index 0000000..ca83bc5 --- /dev/null +++ b/scripts/deploy_accountant.py @@ -0,0 +1,127 @@ +from ape import project, accounts, Contract, chain, networks +from ape.utils import ZERO_ADDRESS +from web3 import Web3, HTTPProvider +from hexbytes import HexBytes +import os +import hashlib +from copy import deepcopy + +deployer = accounts.load("v3_deployer") + + +def deploy_accountant(): + print("Deploying an Accountant on ChainID", chain.chain_id) + + if input("Do you want to continue? ") == "n": + return + + accountant = project.GenericAccountant + deployer_contract = project.Deployer.at( + "0x8D85e7c9A4e369E53Acc8d5426aE1568198b0112" + ) + + salt_string = f"Accountant {chain.pending_timestamp}" + + # 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) + + if ( + input( + "Would you like to deploy a Generic Accountant or a HealthCheck Accountant? g/h " + ).lower() + == "g" + ): + print("Deploying a Generic accountant.") + print("Enter the default amounts to use in Base Points. (100% == 10_000)") + + management_fee = input("Default management fee? ") + assert int(management_fee) <= 200 + + performance_fee = input("Default performance fee? ") + assert int(performance_fee) <= 5_000 + + refund_ratio = input("Default refund ratio? ") + assert int(refund_ratio) <= 2**16 - 1 + + max_fee = input("Default max fee? ") + assert int(max_fee) <= 2**16 - 1 + + constructor = accountant.constructor.encode_input( + deployer.address, + deployer.address, + management_fee, + performance_fee, + refund_ratio, + max_fee, + ) + + else: + print("Deploying a HealthCheck accountant.") + print("Enter the default amounts to use in Base Points. (100% == 10_000)") + + accountant = project.HealthCheckAccountant + + management_fee = input("Default management fee? ") + assert int(management_fee) <= 200 + + performance_fee = input("Default performance fee? ") + assert int(performance_fee) <= 5_000 + + refund_ratio = input("Default refund ratio? ") + assert int(refund_ratio) <= 2**16 - 1 + + max_fee = input("Default max fee? ") + assert int(max_fee) <= 2**16 - 1 + + max_gain = input("Default max gain? ") + assert int(max_gain) <= 10_000 + + max_loss = input("Default max loss? ") + assert int(max_loss) <= 10_000 + + constructor = accountant.constructor.encode_input( + deployer.address, + deployer.address, + management_fee, + performance_fee, + refund_ratio, + max_fee, + max_gain, + max_loss, + ) + + # generate and deploy + deploy_bytecode = HexBytes( + HexBytes(accountant.contract_type.deployment_bytecode.bytecode) + constructor + ) + + print(f"Deploying Accountant...") + + tx = deployer_contract.deploy(deploy_bytecode, salt, sender=deployer) + + event = list(tx.decode_logs(deployer_contract.Deployed)) + + address = event[0].addr + + print(f"Deployed the Accountant to {address}") + print("------------------") + print(f"Encoded Constructor to use for verifaction {constructor.hex()}") + +def publish(): + acct = project.HealthCheckAccountant.at("0xafDE8A815e5e93b66299f05552138B34dD8d6E97") + + networks.provider.network.explorer.publish_contract(acct) + + +def main(): + #publish() + deploy_accountant() diff --git a/scripts/deploy_address_provider.py b/scripts/deploy_address_provider.py index c944f8e..d29c501 100644 --- a/scripts/deploy_address_provider.py +++ b/scripts/deploy_address_provider.py @@ -53,6 +53,8 @@ def deploy_address_provider(): address = event[0].addr print(f"Deployed the address provider to {address}") + print("------------------") + print(f"Encoded Constructor to use for verifaction {constructor.hex()}") def main(): diff --git a/scripts/deploy_allocator_factory.py b/scripts/deploy_allocator_factory.py new file mode 100644 index 0000000..7db744a --- /dev/null +++ b/scripts/deploy_allocator_factory.py @@ -0,0 +1,54 @@ +from ape import project, accounts, Contract, chain, networks +from ape.utils import ZERO_ADDRESS +from web3 import Web3, HTTPProvider +from hexbytes import HexBytes +import os +import hashlib +from copy import deepcopy + +deployer = accounts.load("") + + +def deploy_allocator_factory(): + print("Deploying Generic Debt Allocator Factory on ChainID", chain.chain_id) + + if input("Do you want to continue? ") == "n": + return + + allocator_factory = project.GenericDebtAllocatorFactory + deployer_contract = project.Deployer.at( + "0x8D85e7c9A4e369E53Acc8d5426aE1568198b0112" + ) + + salt_string = "Generic Debt Allocator Factory" + + # 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) + + # generate and deploy + deploy_bytecode = HexBytes( + HexBytes(allocator_factory.contract_type.deployment_bytecode.bytecode) + ) + + print(f"Deploying the Factory...") + + tx = deployer_contract.deploy(deploy_bytecode, salt, sender=deployer) + + event = list(tx.decode_logs(deployer_contract.Deployed)) + + address = event[0].addr + + print(f"Deployed the Factory to {address}") + + +def main(): + deploy_allocator_factory() diff --git a/scripts/deploy_registry.py b/scripts/deploy_registry.py index 8c6a250..be32284 100644 --- a/scripts/deploy_registry.py +++ b/scripts/deploy_registry.py @@ -59,6 +59,8 @@ def deploy_release_and_factory(): release_address = release_event[0].addr print(f"Deployed the vault release to {release_address}") + print("------------------") + print(f"Encoded Constructor to use for verifaction {release_constructor.hex()}") # Deploy factory print(f"Deploying factory...") @@ -79,6 +81,8 @@ def deploy_release_and_factory(): deployed_factory = factory.at(factory_event[0].addr) print(f"Deployed Registry Factory to {deployed_factory.address}") + print("------------------") + print(f"Encoded Constructor to use for verifaction {factory_constructor.hex()}") def main(): diff --git a/tests/conftest.py b/tests/conftest.py index fb76ae6..4f56d97 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -328,10 +328,10 @@ def address_provider(deploy_address_provider): @pytest.fixture(scope="session") -def deploy_generic_debt_allocator_factory(project, vault, daddy): - def deploy_generic_debt_allocator_factory(initial_vault=vault, gov=daddy): +def deploy_generic_debt_allocator_factory(project, daddy): + def deploy_generic_debt_allocator_factory(gov=daddy): generic_debt_allocator_factory = gov.deploy( - project.GenericDebtAllocatorFactory, initial_vault, gov + project.GenericDebtAllocatorFactory ) return generic_debt_allocator_factory