Skip to content

Commit

Permalink
misc: App setDefaultFeed fix (and address(0) fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicnaum committed Dec 29, 2024
1 parent f69ec12 commit eb59185
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 63 deletions.
4 changes: 4 additions & 0 deletions contracts/dashboard/primitives/app/App.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ contract App is IApp, BaseSource, AccessControlled {

function setDefaultFeed(address feed) external override {
_requireAccess(msg.sender, SET_PRIMITIVES_PID);
if (feed != address(0) && !Core._isFeedPresent(feed)) {
Core._addFeed(feed);
emit Lens_App_FeedAdded(feed);
}
_setDefaultFeed(feed);
}

Expand Down
95 changes: 32 additions & 63 deletions contracts/dashboard/primitives/app/AppCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ library AppCore {
address[] storage array,
mapping(address => ArrayStorageHelper) storage arrayHelper
) internal {
require(element != address(0), "INVALID_ELEMENT");
require(!arrayHelper[element].isSet, "ALREADY_ADDED");
array.push(element);
arrayHelper[element] = ArrayStorageHelper({index: uint8(array.length - 1), isSet: true});
Expand All @@ -72,21 +73,15 @@ library AppCore {

////////////// Graph

function _addGraph(
address graph
) internal {
function _addGraph(address graph) internal {
_add(graph, $storage().graphs, $storage().graphStorageHelper);
}

function _removeGraph(
address graph
) internal {
function _removeGraph(address graph) internal {
_remove(graph, $storage().graphs, $storage().graphStorageHelper);
}

function _setDefaultGraph(
address graph
) internal returns (bool) {
function _setDefaultGraph(address graph) internal returns (bool) {
bool wasAValuePreviouslySet = $storage().defaultGraph != address(0);
if (graph != address(0)) {
// address(0) allowed as a way to remove the default graph
Expand All @@ -98,41 +93,39 @@ library AppCore {

////////////// Feed

function _addFeed(
address feed
) internal {
function _addFeed(address feed) internal {
_add(feed, $storage().feeds, $storage().feedStorageHelper);
}

function _removeFeed(
address feed
) internal {
function _removeFeed(address feed) internal {
_remove(feed, $storage().feeds, $storage().feedStorageHelper);
}

function _setDefaultFeed(
address feed
) internal {
function _setDefaultFeed(address feed) internal returns (bool) {
bool wasAValuePreviouslySet = $storage().defaultFeed != address(0);
if (feed != address(0)) {
// address(0) allowed as a way to remove the default feed
require($storage().feedStorageHelper[feed].isSet, "NOT_FOUND");
}
$storage().defaultFeed = feed;
return wasAValuePreviouslySet;
}

function _isFeedPresent(address feed) internal view returns (bool) {
return $storage().feedStorageHelper[feed].isSet;
}

////////////// Username

function _addUsername(
address username
) internal {
function _addUsername(address username) internal {
_add(username, $storage().usernames, $storage().usernameStorageHelper);
}

function _removeUsername(
address username
) internal {
function _removeUsername(address username) internal {
_remove(username, $storage().usernames, $storage().usernameStorageHelper);
}

function _setDefaultUsername(
address username
) internal returns (bool) {
function _setDefaultUsername(address username) internal returns (bool) {
bool wasAValuePreviouslySet = $storage().defaultUsername != address(0);
if (username != address(0)) {
// address(0) allowed as a way to remove the default username
Expand All @@ -144,21 +137,15 @@ library AppCore {

////////////// Group

function _addGroup(
address group
) internal {
function _addGroup(address group) internal {
_add(group, $storage().groups, $storage().groupStorageHelper);
}

function _removeGroup(
address group
) internal {
function _removeGroup(address group) internal {
_remove(group, $storage().groups, $storage().groupStorageHelper);
}

function _setDefaultGroup(
address group
) internal {
function _setDefaultGroup(address group) internal {
if (group != address(0)) {
// address(0) allowed as a way to remove the default group
require($storage().groupStorageHelper[group].isSet, "NOT_FOUND");
Expand All @@ -168,21 +155,15 @@ library AppCore {

////////////// Paymaster

function _addPaymaster(
address paymaster
) internal {
function _addPaymaster(address paymaster) internal {
_add(paymaster, $storage().paymasters, $storage().paymasterStorageHelper);
}

function _removePaymaster(
address paymaster
) internal {
function _removePaymaster(address paymaster) internal {
_remove(paymaster, $storage().paymasters, $storage().paymasterStorageHelper);
}

function _setDefaultPaymaster(
address paymaster
) internal returns (bool) {
function _setDefaultPaymaster(address paymaster) internal returns (bool) {
bool wasAValuePreviouslySet = $storage().defaultPaymaster != address(0);
if (paymaster != address(0)) {
// address(0) allowed as a way to remove the default paymaster
Expand All @@ -194,45 +175,33 @@ library AppCore {

////////////// Signer

function _addSigner(
address signer
) internal {
function _addSigner(address signer) internal {
_add(signer, $storage().signers, $storage().signerStorageHelper);
}

function _removeSigner(
address signer
) internal {
function _removeSigner(address signer) internal {
_remove(signer, $storage().signers, $storage().signerStorageHelper);
}

////////////// Treasury

function _setTreasury(
address treasury
) internal {
function _setTreasury(address treasury) internal {
$storage().treasury = treasury;
}

////////////// Metadata URI

function _setMetadataURI(
string memory metadataURI
) internal {
function _setMetadataURI(string memory metadataURI) internal {
$storage().metadataURI = metadataURI;
}

////////////// Extra Data

function setExtraData(
KeyValue memory extraDataToSet
) external returns (bool) {
function setExtraData(KeyValue memory extraDataToSet) external returns (bool) {
return _setExtraData(extraDataToSet);
}

function _setExtraData(
KeyValue memory extraDataToSet
) internal returns (bool) {
function _setExtraData(KeyValue memory extraDataToSet) internal returns (bool) {
return $storage().extraData.set(extraDataToSet);
}
}

0 comments on commit eb59185

Please sign in to comment.