Skip to content

Commit

Permalink
chore: fix interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Jan 11, 2024
1 parent d4db53f commit 644f3b6
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 82 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
with:
python-version: '3.10'
ape-version-pin: "==0.7.0"
#ape-plugins-list: 'solidity==0.6.0 vyper==0.6.1 hardhat==0.6.0'

- name: install vyper
run: pip install git+https://github.com/vyperlang/vyper
Expand Down
8 changes: 4 additions & 4 deletions contracts/VaultFactory.vy
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ from vyper.interfaces import ERC20

interface IVault:
def initialize(
asset: ERC20,
asset: address,
name: String[64],
symbol: String[32],
role_manager: address,
Expand Down Expand Up @@ -109,7 +109,7 @@ def __init__(name: String[64], vault_original: address, governance: address):

@external
def deploy_new_vault(
asset: ERC20,
asset: address,
name: String[64],
symbol: String[32],
role_manager: address,
Expand All @@ -131,7 +131,7 @@ def deploy_new_vault(
vault_address: address = create_minimal_proxy_to(
VAULT_ORIGINAL,
value=0,
salt=keccak256(_abi_encode(msg.sender, asset.address, name, symbol))
salt=keccak256(_abi_encode(msg.sender, asset, name, symbol))
)

IVault(vault_address).initialize(
Expand All @@ -142,7 +142,7 @@ def deploy_new_vault(
profit_max_unlock_time,
)

log NewVault(vault_address, asset.address)
log NewVault(vault_address, asset)
return vault_address

@view
Expand Down
69 changes: 32 additions & 37 deletions contracts/VaultV3.vy
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ enum Rounding:

# STORAGE #
# Underlying token used by the vault.
ASSET: ERC20
asset: public(address)
# Based off the `asset` decimals.
decimals: public(uint256)
# Deployer contract used to retrieve the protocol fee config.
Expand Down Expand Up @@ -272,12 +272,12 @@ PERMIT_TYPE_HASH: constant(bytes32) = keccak256("Permit(address owner,address sp
# Constructor
@external
def __init__():
# Set `ASSET` so it cannot be re-initialized.
self.ASSET = ERC20(self)
# Set `asset` so it cannot be re-initialized.
self.asset = self

@external
def initialize(
asset: ERC20,
asset: address,
name: String[64],
symbol: String[32],
role_manager: address,
Expand All @@ -297,11 +297,11 @@ def initialize(
@param profit_max_unlock_time
The amount of time that the profit will be locked for
"""
assert self.ASSET.address == empty(address), "initialized"
assert asset.address != empty(address), "ZERO ADDRESS"
assert self.asset == empty(address), "initialized"
assert asset != empty(address), "ZERO ADDRESS"

self.ASSET = asset
decimals: uint256 = convert(ERC20Detailed(asset.address).decimals(), uint256)
self.asset = asset
decimals: uint256 = convert(ERC20Detailed(asset).decimals(), uint256)
assert decimals < 256 # dev: see VVE-2020-0001
self.decimals = decimals

Expand Down Expand Up @@ -686,7 +686,7 @@ def _deposit(sender: address, recipient: address, assets: uint256) -> uint256:
assert assets <= self._max_deposit(recipient), "exceed deposit limit"

# Transfer the tokens to the vault first.
self._erc20_safe_transfer_from(self.ASSET.address, msg.sender, self, assets)
self._erc20_safe_transfer_from(self.asset, msg.sender, self, assets)
# Record the change in total assets.
self.total_idle += assets

Expand All @@ -713,7 +713,7 @@ def _mint(sender: address, recipient: address, shares: uint256) -> uint256:
assert assets <= self._max_deposit(recipient), "exceed deposit limit"

# Transfer the tokens to the vault first.
self._erc20_safe_transfer_from(self.ASSET.address, msg.sender, self, assets)
self._erc20_safe_transfer_from(self.asset, msg.sender, self, assets)
# Record the change in total assets.
self.total_idle += assets

Expand Down Expand Up @@ -814,7 +814,7 @@ def _redeem(

# load to memory to save gas
current_total_idle: uint256 = self.total_idle
asset: ERC20 = self.ASSET
_asset: address = self.asset

# If there are not enough assets in the Vault contract, we try to free
# funds from strategies.
Expand All @@ -838,7 +838,7 @@ def _redeem(
assets_to_withdraw: uint256 = 0

# To compare against real withdrawals from strategies
previous_balance: uint256 = asset.balanceOf(self)
previous_balance: uint256 = ERC20(_asset).balanceOf(self)

for strategy in _strategies:
# Make sure we have a valid strategy.
Expand Down Expand Up @@ -902,7 +902,7 @@ def _redeem(

# WITHDRAW FROM STRATEGY
self._withdraw_from_strategy(strategy, assets_to_withdraw)
post_balance: uint256 = asset.balanceOf(self)
post_balance: uint256 = ERC20(_asset).balanceOf(self)

# Always check withdrawn against the real amounts.
withdrawn: uint256 = post_balance - previous_balance
Expand Down Expand Up @@ -961,7 +961,7 @@ def _redeem(
# Commit memory to storage.
self.total_idle = current_total_idle - requested_assets
# Transfer the requested amount to the receiver.
self._erc20_safe_transfer(asset.address, receiver, requested_assets)
self._erc20_safe_transfer(_asset, receiver, requested_assets)

log Withdraw(sender, receiver, owner, requested_assets, shares)
return requested_assets
Expand All @@ -970,7 +970,7 @@ def _redeem(
@internal
def _add_strategy(new_strategy: address):
assert new_strategy not in [self, empty(address)], "strategy cannot be zero address"
assert IStrategy(new_strategy).asset() == self.ASSET.address, "invalid asset"
assert IStrategy(new_strategy).asset() == self.asset, "invalid asset"
assert self.strategies[new_strategy].activation == 0, "strategy already active"

# Add the new strategy to the mapping.
Expand Down Expand Up @@ -1039,8 +1039,6 @@ def _update_debt(strategy: address, target_debt: uint256, max_loss: uint256) ->
new_debt: uint256 = target_debt
# How much the strategy currently has.
current_debt: uint256 = self.strategies[strategy].current_debt
# Cache for repeated use.
asset: ERC20 = self.ASSET

# If the vault is shutdown we can only pull funds.
if self.shutdown:
Expand Down Expand Up @@ -1078,10 +1076,13 @@ def _update_debt(strategy: address, target_debt: uint256, max_loss: uint256) ->
unrealised_losses_share: uint256 = self._assess_share_of_unrealised_losses(strategy, assets_to_withdraw)
assert unrealised_losses_share == 0, "strategy has unrealised losses"

# Cache for repeated use.
_asset: address = self.asset

# Always check the actual amount withdrawn.
pre_balance: uint256 = asset.balanceOf(self)
pre_balance: uint256 = ERC20(_asset).balanceOf(self)
self._withdraw_from_strategy(strategy, assets_to_withdraw)
post_balance: uint256 = asset.balanceOf(self)
post_balance: uint256 = ERC20(_asset).balanceOf(self)

# making sure we are changing idle according to the real result no matter what.
# We pull funds with {redeem} so there can be losses or rounding differences.
Expand Down Expand Up @@ -1131,16 +1132,19 @@ def _update_debt(strategy: address, target_debt: uint256, max_loss: uint256) ->

# Can't Deposit 0.
if assets_to_deposit > 0:
# Cache for repeated use.
_asset: address = self.asset

# Approve the strategy to pull only what we are giving it.
self._erc20_safe_approve(asset.address, strategy, assets_to_deposit)
self._erc20_safe_approve(_asset, strategy, assets_to_deposit)

# Always update based on actual amounts deposited.
pre_balance: uint256 = asset.balanceOf(self)
pre_balance: uint256 = ERC20(_asset).balanceOf(self)
IStrategy(strategy).deposit(assets_to_deposit, self)
post_balance: uint256 = asset.balanceOf(self)
post_balance: uint256 = ERC20(_asset).balanceOf(self)

# Make sure our approval is always back to 0.
self._erc20_safe_approve(asset.address, strategy, 0)
self._erc20_safe_approve(_asset, strategy, 0)

# Making sure we are changing according to the real result no
# matter what. This will spend more gas but makes it more robust.
Expand Down Expand Up @@ -1245,12 +1249,12 @@ def _process_report(strategy: address) -> (uint256, uint256):
# Shares to lock is any amounts that would otherwise increase the vaults PPS.
newly_locked_shares: uint256 = 0
if total_refunds > 0:
# Load `ASSET` to memory.
asset: ERC20 = self.ASSET
# Load `asset` to memory.
_asset: address = self.asset
# Make sure we have enough approval and enough asset to pull.
total_refunds = min(total_refunds, min(asset.balanceOf(accountant), asset.allowance(accountant, self)))
total_refunds = min(total_refunds, min(ERC20(_asset).balanceOf(accountant), ERC20(_asset).allowance(accountant, self)))
# Transfer the refunded amount of asset to the vault.
self._erc20_safe_transfer_from(asset.address, accountant, self, total_refunds)
self._erc20_safe_transfer_from(_asset, accountant, self, total_refunds)
# Update storage to increase total assets.
self.total_idle += total_refunds

Expand Down Expand Up @@ -1621,7 +1625,7 @@ def buy_debt(strategy: address, amount: uint256):

assert shares > 0, "cannot buy zero"

self._erc20_safe_transfer_from(self.ASSET.address, msg.sender, self, _amount)
self._erc20_safe_transfer_from(self.asset, msg.sender, self, _amount)

# Lower strategy debt
self.strategies[strategy].current_debt -= _amount
Expand Down Expand Up @@ -1879,15 +1883,6 @@ def totalSupply() -> uint256:
"""
return self._total_supply()

@view
@external
def asset() -> address:
"""
@notice Get the address of the asset.
@return The address of the asset.
"""
return self.ASSET.address

@view
@external
def totalAssets() -> uint256:
Expand Down
31 changes: 14 additions & 17 deletions contracts/interfaces/IVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ interface IVault is IERC4626 {
);
// ROLE UPDATES
event RoleSet(address indexed account, uint256 role);
event RoleStatusChanged(uint256 role, uint256 status);
event UpdateRoleManager(address indexed role_manager);

event UpdateAccountant(address indexed accountant);
Expand Down Expand Up @@ -69,8 +68,6 @@ interface IVault is IERC4626 {

function roles(address) external view returns (uint256);

function open_roles(uint256) external view returns (bool);

function role_manager() external view returns (address);

function future_role_manager() external view returns (address);
Expand All @@ -79,6 +76,14 @@ interface IVault is IERC4626 {

function nonces(address) external view returns (uint256);

function initialize(
address,
string memory,
string memory,
address,
uint256
) external;

function set_accountant(address new_accountant) external;

function set_default_queue(address[] memory new_default_queue) external;
Expand Down Expand Up @@ -107,10 +112,6 @@ interface IVault is IERC4626 {

function remove_role(address account, uint256 role) external;

function set_open_role(uint256 role) external;

function close_open_role(uint256 role) external;

function transfer_role_manager(address role_manager) external;

function accept_role_manager() external;
Expand Down Expand Up @@ -143,6 +144,12 @@ interface IVault is IERC4626 {
uint256 target_debt
) external returns (uint256);

function update_debt(
address strategy,
uint256 target_debt,
uint256 max_loss
) external returns (uint256);

function shutdown_vault() external;

function totalIdle() external view returns (uint256);
Expand Down Expand Up @@ -220,16 +227,6 @@ interface IVault is IERC4626 {

//// NON-STANDARD ERC-20 FUNCTIONS \\\\

function increaseAllowance(
address spender,
uint256 amount
) external returns (bool);

function decreaseAllowance(
address spender,
uint256 amount
) external returns (bool);

function DOMAIN_SEPARATOR() external view returns (bytes32);

function permit(
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IVaultFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface IVaultFactory {
function use_custom_protocol_fee(address) external view returns (bool);

function deploy_new_vault(
ERC20 asset,
address asset,
string memory name,
string memory symbol,
address role_manager,
Expand Down
21 changes: 21 additions & 0 deletions contracts/interfaces/Roles.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.18;

// prettier-ignore
library Roles {
uint256 internal constant ADD_STRATEGY_MANAGER = 1;
uint256 internal constant REVOKE_STRATEGY_MANAGER = 2;
uint256 internal constant FORCE_REVOKE_MANAGER = 4;
uint256 internal constant ACCOUNTANT_MANAGER = 8;
uint256 internal constant QUEUE_MANAGER = 16;
uint256 internal constant REPORTING_MANAGER = 32;
uint256 internal constant DEBT_MANAGER = 64;
uint256 internal constant MAX_DEBT_MANAGER = 128;
uint256 internal constant DEPOSIT_LIMIT_MANAGER = 256;
uint256 internal constant WITHDRAW_LIMIT_MANAGER = 512;
uint256 internal constant MINIMUM_IDLE_MANAGER = 1024;
uint256 internal constant PROFIT_UNLOCK_MANAGER = 2048;
uint256 internal constant DEBT_PURCHASER = 4096;
uint256 internal constant EMERGENCY_MANAGER = 8192;
uint256 internal constant ALL = 16383;
}
23 changes: 1 addition & 22 deletions contracts/interfaces/VaultConstants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,10 @@
pragma solidity 0.8.18;

// prettier-ignore
contract Roles {
uint256 public constant ADD_STRATEGY_MANAGER = 1;
uint256 public constant REVOKE_STRATEGY_MANAGER = 2;
uint256 public constant FORCE_REVOKE_MANAGER = 4;
uint256 public constant ACCOUNTANT_MANAGER = 8;
uint256 public constant QUEUE_MANAGER = 16;
uint256 public constant REPORTING_MANAGER = 32;
uint256 public constant DEBT_MANAGER = 64;
uint256 public constant MAX_DEBT_MANAGER = 128;
uint256 public constant DEPOSIT_LIMIT_MANAGER = 256;
uint256 public constant WITHDRAW_LIMIT_MANAGER = 512;
uint256 public constant MINIMUM_IDLE_MANAGER = 1024;
uint256 public constant PROFIT_UNLOCK_MANAGER = 2048;
uint256 public constant DEBT_PURCHASER = 4096;
uint256 public constant EMERGENCY_MANAGER = 8192;
uint256 public constant ALL = 16383;
}

// prettier-ignore
contract VaultConstants is Roles {
contract VaultConstants {
uint256 public constant MAX_QUEUE = 10;
uint256 public constant MAX_BPS = 10_000;
uint256 public constant MAX_BPS_EXTENDED = 1_000_000_000_000;
uint256 public constant STRATEGY_ADDED = 1;
uint256 public constant STRATEGY_REVOKED = 2;
uint256 public constant ROLE_OPENED = 1;
uint256 public constant ROLE_CLOSED = 2;
}

0 comments on commit 644f3b6

Please sign in to comment.