Skip to content

Commit

Permalink
feat: vault tag event
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Jan 10, 2024
1 parent bd7c8c4 commit 3fa69fe
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 29 deletions.
52 changes: 32 additions & 20 deletions contracts/registry/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ contract Registry is Governance {
uint256 vaultType
);

event UpdateEndorser(address indexed account, bool status);
event VaultTagged(address indexed vault);

event UpdateTagger(address indexed account, bool status);

event UpdateEndorser(address indexed account, bool status);

modifier onlyEndorsers() {
_isEndorser();
_;
Expand All @@ -65,22 +67,24 @@ contract Registry is Governance {
// The release number corresponding to the release registries version.
uint96 releaseVersion;
// Type of vault.
uint128 vaultType;
uint64 vaultType;
// Time when the vault was deployed for easier indexing.
uint128 deploymentTimestamp;
// String so that management to tag a vault with any info for FE's.
// Index the vault is at in array for easy removals.
uint64 index;
// String so that management can tag a vault with any info for FE's.
string tag;
}

// Address used to get the specific versions from.
address public immutable releaseRegistry;

// Default type used for Multi strategy "Allocator" vaults.
uint256 public constant MULTI_STRATEGY_TYPE = 1;

// Default type used for Single "Tokenized" Strategy vaults.
uint256 public constant SINGLE_STRATEGY_TYPE = 2;

// Address used to get the specific versions from.
address public immutable releaseRegistry;

// Custom name for this Registry.
string public name;

Expand Down Expand Up @@ -362,18 +366,19 @@ contract Registry is Governance {
uint256 _vaultType,
uint256 _deploymentTimestamp
) internal virtual {
// Add to the endorsed vaults array.
_endorsedVaults[_asset].push(_vault);

// Set the Info struct for this vault
vaultInfo[_vault] = Info({
asset: _asset,
releaseVersion: uint96(_releaseTarget),
vaultType: uint128(_vaultType),
vaultType: uint64(_vaultType),
deploymentTimestamp: uint128(_deploymentTimestamp),
index: uint64(_endorsedVaults[_asset].length),
tag: ""
});

// Add to the endorsed vaults array.
_endorsedVaults[_asset].push(_vault);

if (!assetIsUsed[_asset]) {
// We have a new asset to add
assets.push(_asset);
Expand All @@ -387,7 +392,7 @@ contract Registry is Governance {
* @notice Tag a vault with a specific string.
* @dev This is available to governance to tag any vault or strategy
* on chain if desired to arbitrarily classify any vaults.
* i.e. Certain credit ratings ("AAA") / Vault status ("Shutdown") etc.
* i.e. Certain ratings ("A") / Vault status ("Shutdown") etc.
*
* @param _vault Address of the vault or strategy to tag.
* @param _tag The string to tag the vault or strategy with.
Expand All @@ -398,39 +403,46 @@ contract Registry is Governance {
) external virtual onlyTaggers {
require(vaultInfo[_vault].asset != address(0), "!Endorsed");
vaultInfo[_vault].tag = _tag;

emit VaultTagged(_vault);
}

/**
* @notice Remove a `_vault` at a specific `_index`.
* @notice Remove a `_vault`.
* @dev Can be used as an efficient way to remove a vault
* to not have to iterate over the full array.
*
* NOTE: This will not remove the asset from the `assets` array
* if it is no longer in use and will have to be done manually.
*
* @param _vault Address of the vault to remove.
* @param _index Index in the `endorsedVaults` array `_vault` sits at.
*/
function removeVault(
address _vault,
uint256 _index
) external virtual onlyEndorsers {
function removeVault(address _vault) external virtual onlyEndorsers {
require(vaultInfo[_vault].asset != address(0), "!endorsed");

// TODO: just pull full struct down.
// Get the asset the vault is using.
address asset = IVault(_vault).asset();
// Get the release version for this specific vault.
uint256 releaseTarget = ReleaseRegistry(releaseRegistry).releaseTargets(
IVault(_vault).apiVersion()
);
uint256 _index = vaultInfo[_vault].index;

require(_endorsedVaults[asset][_index] == _vault, "wrong index");
require(_endorsedVaults[asset][_index] == _vault, "wrong vault");

// Set the last index to the spot we are removing.
_endorsedVaults[asset][_index] = _endorsedVaults[asset][
// Get the vault at the end of the array
address lastVault = _endorsedVaults[asset][
_endorsedVaults[asset].length - 1
];

// If more than one vault in the array.
if (lastVault != _vault) {
// Set the last index to the spot we are removing.
_endorsedVaults[asset][_index] = lastVault;
vaultInfo[lastVault].index = uint64(_index);
}

// Pop the last item off the array.
_endorsedVaults[asset].pop();

Expand Down
24 changes: 15 additions & 9 deletions tests/registry/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,11 @@ def test__tag_vault(registry, asset, release_registry, vault_factory, daddy, str

tag = "Test Tag"

registry.tagVault(vault.address, tag, sender=daddy)
tx = registry.tagVault(vault.address, tag, sender=daddy)

event = list(tx.decode_logs(registry.VaultTagged))[0]

assert event.vault == vault.address
assert registry.vaultInfo(vault.address).asset == asset.address
assert registry.vaultInfo(vault.address).tag == tag

Expand All @@ -481,8 +484,11 @@ def test__tag_vault(registry, asset, release_registry, vault_factory, daddy, str

tag = "Test Tag"

registry.tagVault(strategy.address, tag, sender=daddy)
tx = registry.tagVault(strategy.address, tag, sender=daddy)

event = list(tx.decode_logs(registry.VaultTagged))[0]

assert event.vault == strategy.address
assert registry.vaultInfo(strategy.address).asset == asset.address
assert registry.vaultInfo(strategy.address).tag == tag

Expand Down Expand Up @@ -534,7 +540,7 @@ def test__remove_vault(registry, asset, release_registry, vault_factory, daddy):
assert registry.vaultInfo(new_vault.address).deploymentTimestamp == block

# Remove the vault
tx = registry.removeVault(new_vault, 0, sender=daddy)
tx = registry.removeVault(new_vault, sender=daddy)

event = list(tx.decode_logs(registry.RemovedVault))

Expand Down Expand Up @@ -607,7 +613,7 @@ def test__remove_vault__two_vaults(
assert registry.vaultInfo(second_vault.address).releaseVersion == 0

# Remove the first vault
tx = registry.removeVault(new_vault, 0, sender=daddy)
tx = registry.removeVault(new_vault, sender=daddy)

event = list(tx.decode_logs(registry.RemovedVault))

Expand Down Expand Up @@ -667,7 +673,7 @@ def test__remove_strategy(
)

# Remove the strategy
tx = registry.removeVault(strategy, 0, sender=daddy)
tx = registry.removeVault(strategy, sender=daddy)

event = list(tx.decode_logs(registry.RemovedVault))

Expand Down Expand Up @@ -728,7 +734,7 @@ def test__remove_strategy__two_strategies(
)

# Remove the first strategy
tx = registry.removeVault(strategy, 0, sender=daddy)
tx = registry.removeVault(strategy, sender=daddy)

event = list(tx.decode_logs(registry.RemovedVault))

Expand Down Expand Up @@ -787,7 +793,7 @@ def test__remove_asset(
registry.removeAsset(asset.address, 0, sender=daddy)

# Remove the strategy
registry.removeVault(strategy.address, 0, sender=daddy)
registry.removeVault(strategy.address, sender=daddy)

registry.removeAsset(asset.address, 0, sender=daddy)

Expand Down Expand Up @@ -832,7 +838,7 @@ def test__access(

# cant remove vault or asset
with ape.reverts("!endorser"):
registry.removeVault(new_vault.address, 0, sender=user)
registry.removeVault(new_vault.address, sender=user)

with ape.reverts("!endorser"):
registry.removeAsset(asset.address, 0, sender=user)
Expand Down Expand Up @@ -874,7 +880,7 @@ def test__access(
assert registry.vaultInfo(new_vault).tag == "tag"

# User should be able to remove vaults and assets now too.
registry.removeVault(new_vault, 0, sender=user)
registry.removeVault(new_vault, sender=user)

assert registry.isEndorsed(new_vault) == False

Expand Down

0 comments on commit 3fa69fe

Please sign in to comment.