Skip to content

Commit

Permalink
commited
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Oct 24, 2023
1 parent 46a76ac commit d7d5e97
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 11 deletions.
1 change: 1 addition & 0 deletions ape-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins:
- name: etherscan
- name: hardhat
- name: infura
- name: polygon

default_ecosystem: ethereum

Expand Down
5 changes: 2 additions & 3 deletions contracts/accountants/HelathCheckAccountant.sol
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion contracts/debtAllocators/GenericDebtAllocator.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 {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
Expand Down
7 changes: 3 additions & 4 deletions contracts/debtAllocators/GenericDebtAllocatorFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

/**
Expand Down
127 changes: 127 additions & 0 deletions scripts/deploy_accountant.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions scripts/deploy_address_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
54 changes: 54 additions & 0 deletions scripts/deploy_allocator_factory.py
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 4 additions & 0 deletions scripts/deploy_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand All @@ -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():
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d7d5e97

Please sign in to comment.