Skip to content

Commit

Permalink
build: scripts and license (#24)
Browse files Browse the repository at this point in the history
* chore: accountant deployment

* build: allocator deployment

* build: scripts and license

* fix: accountant name
  • Loading branch information
Schlagonia authored Oct 25, 2023
1 parent 46a76ac commit 13101c0
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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
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: GNU AGPLv3
pragma solidity 0.8.18;

import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
Expand Down
8 changes: 3 additions & 5 deletions contracts/debtAllocators/GenericDebtAllocatorFactory.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: GPL-3.0
// SPDX-License-Identifier: GNU AGPLv3
pragma solidity 0.8.18;

import {GenericDebtAllocator} from "./GenericDebtAllocator.sol";
Expand All @@ -16,10 +16,8 @@ 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() {
original = address(new GenericDebtAllocator(address(1), address(2)));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/registry/Registry.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: GPL-3.0
// SPDX-License-Identifier: GNU AGPLv3
pragma solidity 0.8.18;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/registry/RegistryFactory.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: GPL-3.0
// SPDX-License-Identifier: GNU AGPLv3
pragma solidity 0.8.18;

import {Registry} from "./Registry.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/registry/ReleaseRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: GPL-3.0
// SPDX-License-Identifier: GNU AGPLv3
pragma solidity 0.8.18;

import {Governance} from "@periphery/utils/Governance.sol";
Expand Down
121 changes: 121 additions & 0 deletions scripts/deploy_accountant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
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_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 main():
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
8 changes: 3 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,9 @@ 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):
generic_debt_allocator_factory = gov.deploy(
project.GenericDebtAllocatorFactory, initial_vault, gov
)
def deploy_generic_debt_allocator_factory(project, daddy):
def deploy_generic_debt_allocator_factory(gov=daddy):
generic_debt_allocator_factory = gov.deploy(project.GenericDebtAllocatorFactory)

return generic_debt_allocator_factory

Expand Down

0 comments on commit 13101c0

Please sign in to comment.