From 5f01e719ce888f39981bb7ca79b3c5ab0e91cf8c Mon Sep 17 00:00:00 2001 From: bout3fiddy <11488427+bout3fiddy@users.noreply.github.com> Date: Wed, 3 Apr 2024 11:33:11 +0200 Subject: [PATCH] remove tagging (incorporating feedback) --- contracts/AddressProviderNG.vy | 168 ++------------------------------- 1 file changed, 6 insertions(+), 162 deletions(-) diff --git a/contracts/AddressProviderNG.vy b/contracts/AddressProviderNG.vy index af9d453..00c33af 100644 --- a/contracts/AddressProviderNG.vy +++ b/contracts/AddressProviderNG.vy @@ -4,6 +4,7 @@ @author Curve.Fi @license Copyright (c) Curve.Fi, 2020-2023 - all rights reserved @notice An entrypoint contract for Curve's various registries +@dev Allows adding arbitrary IDs instead of sequential IDs. """ event NewEntry: @@ -15,6 +16,9 @@ event EntryModified: id: indexed(uint256) version: uint256 +event EntryRemoved: + id: indexed(uint256) + event CommitNewAdmin: admin: indexed(address) @@ -25,7 +29,6 @@ event NewAdmin: struct AddressInfo: addr: address description: String[256] - tags: DynArray[String[64], 20] version: uint256 last_modified: uint256 @@ -34,11 +37,8 @@ admin: public(address) future_admin: public(address) num_entries: public(uint256) -check_tag_exists: public(HashMap[String[64], bool]) check_id_exists: public(HashMap[uint256, bool]) _ids: DynArray[uint256, 1000] -_tags: DynArray[String[64], 1000] -id_tag_mapping: HashMap[bytes32, bool] get_id_info: public(HashMap[uint256, AddressInfo]) @@ -49,22 +49,6 @@ def __init__(_admin: address): # ------------------------------ View Methods -------------------------------- - -@view -@external -def tags() -> DynArray[String[64], 1000]: - """ - @notice Returns active tags registered in the AddressProvider. - @returns An array of tags. - """ - _tags: DynArray[String[64], 1000] = [] - for _tag in self._tags: - if self.check_tag_exists[_tag]: - _tags.append(_tag) - - return _tags - - @view @external def ids() -> DynArray[uint256, 1000]: @@ -92,23 +76,6 @@ def get_address(_id: uint256) -> address: return self.get_id_info[_id].addr -@view -@external -def get_addresses_for_tags(_tag: String[64]) -> DynArray[address, 100]: - """ - @notice Fetch all addresses that are tagged with `_tag` - @param _tag tag to fetch an address for - @return Array of addresses tagged with `_tag` - """ - - tagged_ids: DynArray[address, 100] = [] - for _id in self._ids: - if self.id_tag_mapping[keccak256(concat(uint2str(_id), _tag))]: - tagged_ids.append(self.get_id_info[_id].addr) - - return tagged_ids - - # -------------------------- State-Mutable Methods --------------------------- @@ -122,56 +89,29 @@ def _update_entry_metadata(_id: uint256): log EntryModified(_id, version) -@external -def add_new_tags(_new_tags: DynArray[String[64], 20]): - """ - @notice Add new tags - @dev method allows a max number of entry of 20 - @param _new_tags An array of types to add to the registry - e.g. ['StableSwap', 'CryptoSwap', ...] - """ - for _new_tag in _new_tags: - if not self.check_tag_exists[_new_tag]: - self.check_tag_exists[_new_tag] = True - self._tags.append(_new_tag) - - @external def add_new_id( _id: uint256, _address: address, - _tags: DynArray[String[64], 20], _description: String[64], ): """ @notice Enter a new registry item @param _id Address assigned to the input _id @param _address Address assigned to the _id - @param _tags tags defining the entry. e.g. ['StableSwap', 'Factory'] - Entry can have a maximum of 20 tags. Tags need to be - added to the AddressProvider via `add_new_tags` before id can be added. @param _description Human-readable description of the identifier """ assert msg.sender == self.admin # dev: admin-only function assert not self.check_id_exists[_id] # dev: id exists - assert len(_tags) > 0 # dev: entry needs at least one tag self.check_id_exists[_id] = True self._ids.append(_id) - # Check if tags are correct and add them to tag > id mapping: - for _tag in _tags: - assert self.check_tag_exists[_tag] # dev: unrecognised tag - self.id_tag_mapping[ - keccak256(concat(uint2str(_id), _tag)) - ] = True - # Add entry: self.get_id_info[_id] = AddressInfo( { addr: _address, description: _description, - tags: _tags, version: 1, last_modified: block.timestamp, } @@ -185,42 +125,21 @@ def add_new_id( def update_id( _id: uint256, _new_address: address, - _new_tags: DynArray[String[64], 20], _new_description: String[64], ): """ @notice Update entries at an ID @param _id Address assigned to the input _id @param _new_address Address assigned to the _id - @param _new_tags tags defining the entry. e.g. ['StableSwap', 'Factory'] - Entry can have a maximum of 20 tags. Tags need to be - added to the AddressProvider via `add_new_tags` before id can be added. @param _new_description Human-readable description of the identifier """ assert msg.sender == self.admin # dev: admin-only function assert self.check_id_exists[_id] # dev: id does not exist - assert len(_new_tags) > 0 # dev: entry needs at least one tag # Update entry at _id: self.get_id_info[_id].addr = _new_address self.get_id_info[_id].description = _new_description - # Update id > tag mapping - _old_tags: DynArray[String[64], 20] = self.get_id_info[_id].tags - for _tag in _new_tags: - assert self.check_tag_exists[_tag] # dev: unauthorised tag - key: bytes32 = keccak256(concat(uint2str(_id), _tag)) - if not self.id_tag_mapping[key]: - self.id_tag_mapping[key] = True - - # Remove mapping if tag was removed: - for _tag in _old_tags: - key: bytes32 = keccak256(concat(uint2str(_id), _tag)) - self.id_tag_mapping[key] = False - - # Update tags: - self.get_id_info[_id].tags = _new_tags - # Update metadata (version, update time): self._update_entry_metadata(_id) @@ -258,36 +177,6 @@ def update_description(_id: uint256, _description: String[256]): self._update_entry_metadata(_id) -@external -def update_tags(_id: uint256, _new_tags: DynArray[String[64], 20]): - """ - @notice Update tags for an existing _id - @param _id Identifier to set the new description for - @param _new_tags New tags to set to - """ - assert msg.sender == self.admin # dev: admin-only function - assert self.get_id_info[_id].addr != empty(address) # dev: id is empty - - # Add mapping if new tag is added: - _old_tags: DynArray[String[64], 20] = self.get_id_info[_id].tags - for _tag in _new_tags: - assert self.check_tag_exists[_tag] # dev: unauthorised tag - key: bytes32 = keccak256(concat(uint2str(_id), _tag)) - if not self.id_tag_mapping[key]: - self.id_tag_mapping[key] = True - - # Remove mapping if tag was removed: - for _tag in _old_tags: - key: bytes32 = keccak256(concat(uint2str(_id), _tag)) - self.id_tag_mapping[key] = False - - # Update tags: - self.get_id_info[_id].tags = _new_tags - - # Update metadata (version, update time): - self._update_entry_metadata(_id) - - @external def remove_id(_id: uint256) -> bool: """ @@ -300,17 +189,10 @@ def remove_id(_id: uint256) -> bool: assert msg.sender == self.admin # dev: admin-only function assert self.get_id_info[_id].addr != empty(address) # dev: inactive id - # Remove id > Tag mapping: - _tags: DynArray[String[64], 20] = self.get_id_info[_id].tags - for _tag in _tags: - key: bytes32 = keccak256(concat(uint2str(_id), _tag)) - self.id_tag_mapping[key] = False - # Clear ID: self.get_id_info[_id].addr = empty(address) - self.get_id_info[_id].last_modified = block.timestamp + self.get_id_info[_id].last_modified = 0 self.get_id_info[_id].description = '' - self.get_id_info[_id].tags = [] self.get_id_info[_id].version = 0 self.check_id_exists[_id] = False @@ -319,46 +201,11 @@ def remove_id(_id: uint256) -> bool: self.num_entries -= 1 # Emit 0 in version to notify removal of id: - log EntryModified(_id, 0) + log EntryRemoved(_id) return True -@external -def remove_tags(_tags_to_remove: DynArray[String[64], 20]): - """ - @notice Remove tags and clear id > tag mappings. - @dev method allows a max number of entry of 20 - @param _tags_to_remove An array of types to removed from the registry - e.g. ['StableSwap', 'CryptoSwap', ...] - """ - - # Remove tags from mapping and invalidate each tag: - for _tag in _tags_to_remove: - - # Check if tag is valid - if self.check_tag_exists[_tag]: - - # Remove Tag - self.check_tag_exists[_tag] = False - - # Clear id > tag mapping: - for _id in self._ids: - self.id_tag_mapping[keccak256(concat(uint2str(_id), _tag))] = False - - # Update tags per id: - for _id in self._ids: - _id_tags: DynArray[String[64], 20] = self.get_id_info[_id].tags - _new_tags: DynArray[String[64], 20] = [] - - for _id_tag in _id_tags: - if self.check_tag_exists[_id_tag]: - _new_tags.append(_id_tag) - - self.get_id_info[_id].tags = _new_tags - self._update_entry_metadata(_id) - - # ------------------------------ Admin Methods ------------------------------- @@ -406,6 +253,3 @@ def revert_transfer_ownership() -> bool: self.future_admin = empty(address) return True - - -# TODO: Separate tags away from AddressInfo