Skip to content

Commit

Permalink
Merge pull request #101 from yaxis-project/single-asset-vaults
Browse files Browse the repository at this point in the history
Refactor to 1 vault = 1 token
  • Loading branch information
transferAndCall authored Oct 10, 2021
2 parents 6c3eac8 + 0c2298c commit 6dcff91
Show file tree
Hide file tree
Showing 26 changed files with 493 additions and 918 deletions.
9 changes: 3 additions & 6 deletions contracts/v3/Harvester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,12 @@ contract Harvester is IHarvester {

function earn(
address _strategy,
IVault _vault,
address _token
address _vault
)
external
onlyHarvester
{
_vault.earn(_token, _strategy);
IVault(_vault).earn(_strategy);
}

/**
Expand Down Expand Up @@ -225,17 +224,15 @@ contract Harvester is IHarvester {

/**
* @notice Earns tokens in the LegacyController to the v3 vault
* @param _token The address of the token
* @param _expected The expected amount to deposit after conversion
*/
function legacyEarn(
address _token,
uint256 _expected
)
external
onlyHarvester
{
legacyController.legacyDeposit(_token, _expected);
legacyController.legacyDeposit(_expected);
}

/**
Expand Down
84 changes: 19 additions & 65 deletions contracts/v3/Manager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,12 @@ contract Manager is IManager {
mapping(address => bool) public override allowedControllers;
mapping(address => bool) public override allowedConverters;
mapping(address => bool) public override allowedStrategies;
mapping(address => bool) public override allowedTokens;
mapping(address => bool) public override allowedVaults;

// vault => controller
mapping(address => address) public override controllers;
// vault => tokens[]
mapping(address => address[]) public override tokens;
// token => vault
mapping(address => address) public override vaults;
// vault => token
mapping(address => address) internal tokens;

event AllowedController(
address indexed _controller,
Expand All @@ -78,10 +75,6 @@ contract Manager is IManager {
address indexed _strategy,
bool _allowed
);
event AllowedToken(
address indexed _token,
bool _allowed
);
event AllowedVault(
address indexed _vault,
bool _allowed
Expand All @@ -100,13 +93,12 @@ contract Manager is IManager {
event SetStrategist(
address indexed _strategist
);
event TokenAdded(
event VaultAdded(
address indexed _vault,
address indexed _token
);
event TokenRemoved(
address indexed _vault,
address indexed _token
event VaultRemoved(
address indexed _vault
);

/**
Expand Down Expand Up @@ -186,23 +178,6 @@ contract Manager is IManager {
emit AllowedStrategy(_strategy, _allowed);
}

/**
* @notice Sets the permission for the given token
* @param _token The address of the token
* @param _allowed The status of if it is allowed
*/
function setAllowedToken(
address _token,
bool _allowed
)
external
notHalted
onlyGovernance
{
allowedTokens[_token] = _allowed;
emit AllowedToken(_token, _allowed);
}

/**
* @notice Sets the permission for the given vault
* @param _vault The address of the vault
Expand Down Expand Up @@ -416,24 +391,20 @@ contract Manager is IManager {
/**
* @notice Adds a token to be able to be deposited for a given vault
* @param _vault The address of the vault
* @param _token The address of the token
*/
function addToken(
address _vault,
address _token
function addVault(
address _vault
)
external
override
notHalted
onlyStrategist
{
require(allowedTokens[_token], "!allowedTokens");
require(allowedVaults[_vault], "!allowedVaults");
require(tokens[_vault].length < MAX_TOKENS, ">tokens");
require(vaults[_token] == address(0), "!_token");
vaults[_token] = _vault;
tokens[_vault].push(_token);
emit TokenAdded(_vault, _token);
require(tokens[_vault] == address(0), "!_vault");
address _token = IVault(_vault).getToken();
tokens[_vault] = _token;
emit VaultAdded(_vault, _token);
}

/**
Expand All @@ -458,36 +429,19 @@ contract Manager is IManager {
/**
* @notice Removes a token from being able to be deposited for a given vault
* @param _vault The address of the vault
* @param _token The address of the token
*/
function removeToken(
address _vault,
address _token
function removeVault(
address _vault
)
external
override
notHalted
onlyStrategist
{
uint256 k = tokens[_vault].length;
uint256 index;
bool found;

for (uint i = 0; i < k; i++) {
if (tokens[_vault][i] == _token) {
index = i;
found = true;
break;
}
}

// TODO: Verify added check
if (found) {
tokens[_vault][index] = tokens[_vault][k-1];
tokens[_vault].pop();
delete vaults[_token];
emit TokenRemoved(_vault, _token);
}
require(tokens[_vault] != address(0), "!_vault");
delete tokens[_vault];
delete allowedVaults[_vault];
emit VaultRemoved(_vault);
}

/**
Expand Down Expand Up @@ -530,13 +484,13 @@ contract Manager is IManager {
* @notice Returns an array of token addresses for a given vault
* @param _vault The address of the vault
*/
function getTokens(
function getToken(
address _vault
)
external
view
override
returns (address[] memory)
returns (address)
{
return tokens[_vault];
}
Expand Down
Loading

0 comments on commit 6dcff91

Please sign in to comment.