Skip to content

Commit

Permalink
feat: Metadata added to the rules and all primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
vicnaum committed Dec 25, 2024
1 parent afc7cea commit 32a724b
Show file tree
Hide file tree
Showing 24 changed files with 236 additions and 90 deletions.
16 changes: 12 additions & 4 deletions contracts/actions/account/TippingAccountAction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@ import {BaseAccountAction} from "./base/BaseAccountAction.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {KeyValue} from "./../../core/types/Types.sol";
import {MetadataBased} from "./../../core/base/MetadataBased.sol";

contract TippingAccountAction is BaseAccountAction {
contract TippingAccountAction is BaseAccountAction, MetadataBased {
using SafeERC20 for IERC20;

event Lens_Action_MetadataURISet(string metadataURI);

// keccak256("lens.actions.account.TippingAccountAction.param.key.tipAmount");
bytes32 immutable TIP_AMOUNT_PARAM_KEY = 0x9c3dd1983546cd2f985b2e6692b416f4157648b3750ffc5bdf5a6365061d9bd9;
// keccak256("lens.actions.account.TippingAccountAction.param.key.tipToken");
bytes32 immutable TIP_TOKEN_PARAM_KEY = 0xae0b2bf062e67ee8e231397eadff68e32752f185a8cb19379ed8cfa87ae7bd08;

constructor(
address actionHub
) BaseAccountAction(actionHub) {}
constructor(address actionHub) BaseAccountAction(actionHub) {
// TODO: Decide on metadata format
_setMetadataURI("{ lensMetadata: 'some metadata' }");
}

function _emitMetadataURISet(string memory metadataURI) internal override {
emit Lens_Action_MetadataURISet(metadataURI);
}

function _execute(
address originalMsgSender,
Expand Down
16 changes: 12 additions & 4 deletions contracts/actions/post/TippingPostAction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {KeyValue} from "./../../core/types/Types.sol";
import {IFeed} from "./../../core/interfaces/IFeed.sol";
import {MetadataBased} from "./../../core/base/MetadataBased.sol";

contract TippingPostAction is BasePostAction {
contract TippingPostAction is BasePostAction, MetadataBased {
using SafeERC20 for IERC20;

event Lens_Action_MetadataURISet(string metadataURI);

// keccak256("lens.actions.account.TippingPostAction.param.key.tipAmount");
bytes32 immutable TIP_AMOUNT_PARAM_KEY = 0x9c3dd1983546cd2f985b2e6692b416f4157648b3750ffc5bdf5a6365061d9bd9;
// keccak256("lens.actions.account.TippingPostAction.param.key.tipToken");
bytes32 immutable TIP_TOKEN_PARAM_KEY = 0xae0b2bf062e67ee8e231397eadff68e32752f185a8cb19379ed8cfa87ae7bd08;

constructor(
address actionHub
) BasePostAction(actionHub) {}
constructor(address actionHub) BasePostAction(actionHub) {
// TODO: Decide on metadata format
_setMetadataURI("{ lensMetadata: 'some metadata' }");
}

function _emitMetadataURISet(string memory metadataURI) internal override {
emit Lens_Action_MetadataURISet(metadataURI);
}

function _execute(
address originalMsgSender,
Expand Down
15 changes: 12 additions & 3 deletions contracts/actions/post/collect/SimpleCollectAction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import {BasePostAction} from "./../base/BasePostAction.sol";

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import {MetadataBased} from "./../../../core/base/MetadataBased.sol";
import {KeyValue} from "./../../../core/types/Types.sol";

contract SimpleCollectAction is ISimpleCollectAction, BasePostAction {
contract SimpleCollectAction is ISimpleCollectAction, BasePostAction, MetadataBased {
using SafeERC20 for IERC20;

event Lens_Action_MetadataURISet(string metadataURI);

struct CollectActionStorage {
mapping(address => mapping(uint256 => CollectActionData)) collectData;
}
Expand Down Expand Up @@ -77,7 +79,14 @@ contract SimpleCollectAction is ISimpleCollectAction, BasePostAction {
address currency; // (Optional, but required if amount > 0) Default: address(0)
}

constructor(address actionHub) BasePostAction(actionHub) {}
constructor(address actionHub) BasePostAction(actionHub) {
// TODO: Decide on metadata format
_setMetadataURI("{ lensMetadata: 'some metadata' }");
}

function _emitMetadataURISet(string memory metadataURI) internal override {
emit Lens_Action_MetadataURISet(metadataURI);
}

function _configure(
address originalMsgSender,
Expand Down
18 changes: 8 additions & 10 deletions contracts/core/base/MetadataBased.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

abstract contract MetadataBased {
import {IMetadataBased} from "./../interfaces/IMetadataBased.sol";

abstract contract MetadataBased is IMetadataBased {
struct MetadataURIStorage {
string metadataURI;
}
Expand All @@ -15,27 +17,23 @@ abstract contract MetadataBased {
}
}

event Lens_MetadataURISet(string metadataURI);

constructor(string memory metadataURI) {
_setMetadataURI(metadataURI);
}

function setMetadataURI(string memory metadataURI) external {
function setMetadataURI(string memory metadataURI) external override {
_beforeMetadataURIUpdate(metadataURI);
_setMetadataURI(metadataURI);
}

function _setMetadataURI(string memory metadataURI) internal {
$metadataStorage().metadataURI = metadataURI;
emit Lens_MetadataURISet(metadataURI);
_emitMetadataURISet(metadataURI);
}

function _beforeMetadataURIUpdate(string memory /* metadataURI */ ) internal virtual {
revert();
}

function getMetadataURI() external view returns (string memory) {
function _emitMetadataURISet(string memory /* metadataURI */ ) internal virtual;

function getMetadataURI() external view override returns (string memory) {
return $metadataStorage().metadataURI;
}
}
21 changes: 10 additions & 11 deletions contracts/core/primitives/feed/Feed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,26 @@ import {ExtraStorageBased} from "./../../base/ExtraStorageBased.sol";
import {RuleChange, RuleProcessingParams, KeyValue} from "./../../types/Types.sol";
import {Events} from "./../../types/Events.sol";
import {SourceStampBased} from "./../../base/SourceStampBased.sol";
import {MetadataBased} from "./../../base/MetadataBased.sol";

contract Feed is IFeed, RuleBasedFeed, AccessControlled, ExtraStorageBased, SourceStampBased {
contract Feed is IFeed, RuleBasedFeed, AccessControlled, ExtraStorageBased, SourceStampBased, MetadataBased {
// TODO: Move these to respective contracts
// Resource IDs involved in the contract
uint256 constant SET_RULES_PID = uint256(keccak256("SET_RULES"));
uint256 constant SET_METADATA_PID = uint256(keccak256("SET_METADATA"));
uint256 constant SET_RULES_PID = uint256(keccak256("SET_RULES"));
uint256 constant SET_EXTRA_DATA_PID = uint256(keccak256("SET_EXTRA_DATA"));
uint256 constant REMOVE_POST_PID = uint256(keccak256("REMOVE_POST"));

constructor(string memory metadataURI, IAccessControl accessControl) AccessControlled(accessControl) {
Core.$storage().metadataURI = metadataURI;
emit Lens_Feed_MetadataURISet(metadataURI);
_setMetadataURI(metadataURI);
_emitPIDs();
emit Events.Lens_Contract_Deployed("feed", "lens.feed", "feed", "lens.feed");
}

function _emitMetadataURISet(string memory metadataURI) internal override {
emit Lens_Feed_MetadataURISet(metadataURI);
}

function _emitPIDs() internal override {
super._emitPIDs();
emit Events.Lens_PermissionId_Available(SET_RULES_PID, "SET_RULES");
Expand All @@ -36,10 +41,8 @@ contract Feed is IFeed, RuleBasedFeed, AccessControlled, ExtraStorageBased, Sour

// Access Controlled functions

function setMetadataURI(string calldata metadataURI) external override {
function _beforeMetadataURIUpdate(string memory /* metadataURI */ ) internal view override {
_requireAccess(msg.sender, SET_METADATA_PID);
Core.$storage().metadataURI = metadataURI;
emit Lens_Feed_MetadataURISet(metadataURI);
}

function _beforeChangePrimitiveRules(RuleChange[] calldata /* ruleChanges */ ) internal virtual override {
Expand Down Expand Up @@ -220,10 +223,6 @@ contract Feed is IFeed, RuleBasedFeed, AccessControlled, ExtraStorageBased, Sour
return Core.$storage().authorPostCount[author];
}

function getMetadataURI() external view override returns (string memory) {
return Core.$storage().metadataURI;
}

function getPostExtraData(uint256 postId, bytes32 key) external view override returns (bytes memory) {
address postAuthor = Core.$storage().posts[postId].author;
return _getEntityExtraData(postAuthor, postId, key);
Expand Down
1 change: 0 additions & 1 deletion contracts/core/primitives/feed/FeedCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ library FeedCore {
// Storage

struct Storage {
string metadataURI;
uint256 postCount;
mapping(address => uint256) authorPostCount;
mapping(uint256 => PostStorage) posts;
Expand Down
24 changes: 11 additions & 13 deletions contracts/core/primitives/graph/Graph.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {AccessControlled} from "./../../access/AccessControlled.sol";
import {ExtraStorageBased} from "./../../base/ExtraStorageBased.sol";
import {Events} from "./../../types/Events.sol";
import {SourceStampBased} from "./../../base/SourceStampBased.sol";
import {MetadataBased} from "./../../base/MetadataBased.sol";

contract Graph is IGraph, RuleBasedGraph, AccessControlled, ExtraStorageBased, SourceStampBased {
contract Graph is IGraph, RuleBasedGraph, AccessControlled, ExtraStorageBased, SourceStampBased, MetadataBased {
// Resource IDs involved in the contract
uint256 constant SET_RULES_PID = uint256(keccak256("SET_RULES"));
uint256 constant SET_METADATA_PID = uint256(keccak256("SET_METADATA"));
Expand All @@ -21,12 +22,15 @@ contract Graph is IGraph, RuleBasedGraph, AccessControlled, ExtraStorageBased, S
// uint256 constant SKIP_FOLLOW_RULES_CHECKS_PID = uint256(keccak256("SKIP_FOLLOW_RULES_CHECKS"));

constructor(string memory metadataURI, IAccessControl accessControl) AccessControlled(accessControl) {
Core.$storage().metadataURI = metadataURI;
emit Lens_Graph_MetadataURISet(metadataURI);
_setMetadataURI(metadataURI);
_emitPIDs();
emit Events.Lens_Contract_Deployed("graph", "lens.graph", "graph", "lens.graph");
}

function _emitMetadataURISet(string memory metadataURI) internal override {
emit Lens_Graph_MetadataURISet(metadataURI);
}

function _emitPIDs() internal override {
super._emitPIDs();
emit Events.Lens_PermissionId_Available(SET_RULES_PID, "SET_RULES");
Expand All @@ -36,6 +40,10 @@ contract Graph is IGraph, RuleBasedGraph, AccessControlled, ExtraStorageBased, S

// Access Controlled functions

function _beforeMetadataURIUpdate(string memory /* metadataURI */ ) internal view override {
_requireAccess(msg.sender, SET_METADATA_PID);
}

function _beforeChangePrimitiveRules(RuleChange[] calldata /* ruleChanges */ ) internal virtual override {
_requireAccess(msg.sender, SET_RULES_PID);
}
Expand All @@ -48,12 +56,6 @@ contract Graph is IGraph, RuleBasedGraph, AccessControlled, ExtraStorageBased, S
// TODO: What should we validate here?
}

function setMetadataURI(string calldata metadataURI) external override {
_requireAccess(msg.sender, SET_METADATA_PID);
Core.$storage().metadataURI = metadataURI;
emit Lens_Graph_MetadataURISet(metadataURI);
}

function setExtraData(KeyValue[] calldata extraDataToSet) external override {
_requireAccess(msg.sender, SET_EXTRA_DATA_PID);
for (uint256 i = 0; i < extraDataToSet.length; i++) {
Expand Down Expand Up @@ -143,8 +145,4 @@ contract Graph is IGraph, RuleBasedGraph, AccessControlled, ExtraStorageBased, S
function getExtraData(bytes32 key) external view override returns (bytes memory) {
return _getPrimitiveExtraData(key);
}

function getMetadataURI() external view override returns (string memory) {
return Core.$storage().metadataURI;
}
}
1 change: 0 additions & 1 deletion contracts/core/primitives/graph/GraphCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ library GraphCore {
// Storage

struct Storage {
string metadataURI;
mapping(address => uint256) lastFollowIdAssigned;
mapping(address => mapping(address => Follow)) follows;
mapping(address => mapping(uint256 => address)) followers;
Expand Down
24 changes: 11 additions & 13 deletions contracts/core/primitives/group/Group.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import {ExtraStorageBased} from "./../../base/ExtraStorageBased.sol";
import {Events} from "./../../types/Events.sol";
import {IGroupRule} from "./../../interfaces/IGroupRule.sol";
import {SourceStampBased} from "./../../base/SourceStampBased.sol";
import {MetadataBased} from "./../../base/MetadataBased.sol";

contract Group is IGroup, RuleBasedGroup, AccessControlled, ExtraStorageBased, SourceStampBased {
contract Group is IGroup, RuleBasedGroup, AccessControlled, ExtraStorageBased, SourceStampBased, MetadataBased {
// Resource IDs involved in the contract
uint256 constant SET_RULES_PID = uint256(keccak256("SET_RULES"));
uint256 constant SET_METADATA_PID = uint256(keccak256("SET_METADATA"));
Expand All @@ -22,12 +23,15 @@ contract Group is IGroup, RuleBasedGroup, AccessControlled, ExtraStorageBased, S
uint256 constant REMOVE_MEMBER_PID = uint256(keccak256("REMOVE_MEMBER"));

constructor(string memory metadataURI, IAccessControl accessControl) AccessControlled(accessControl) {
Core.$storage().metadataURI = metadataURI;
emit Lens_Group_MetadataURISet(metadataURI);
_setMetadataURI(metadataURI);
_emitPIDs();
emit Events.Lens_Contract_Deployed("group", "lens.group", "group", "lens.group");
}

function _emitMetadataURISet(string memory metadataURI) internal override {
emit Lens_Group_MetadataURISet(metadataURI);
}

function _emitPIDs() internal override {
super._emitPIDs();
emit Events.Lens_PermissionId_Available(SET_RULES_PID, "SET_RULES");
Expand All @@ -39,14 +43,12 @@ contract Group is IGroup, RuleBasedGroup, AccessControlled, ExtraStorageBased, S

// Access Controlled functions

function _beforeChangePrimitiveRules(RuleChange[] calldata /* ruleChanges */ ) internal virtual override {
_requireAccess(msg.sender, SET_RULES_PID);
function _beforeMetadataURIUpdate(string memory /* metadataURI */ ) internal view override {
_requireAccess(msg.sender, SET_METADATA_PID);
}

function setMetadataURI(string calldata metadataURI) external override {
_requireAccess(msg.sender, SET_METADATA_PID);
Core.$storage().metadataURI = metadataURI;
emit Lens_Group_MetadataURISet(metadataURI);
function _beforeChangePrimitiveRules(RuleChange[] calldata /* ruleChanges */ ) internal virtual override {
_requireAccess(msg.sender, SET_RULES_PID);
}

function setExtraData(KeyValue[] calldata extraDataToSet) external override {
Expand Down Expand Up @@ -123,10 +125,6 @@ contract Group is IGroup, RuleBasedGroup, AccessControlled, ExtraStorageBased, S

// Getters

function getMetadataURI() external view override returns (string memory) {
return Core.$storage().metadataURI;
}

function getNumberOfMembers() external view override returns (uint256) {
return Core.$storage().numberOfMembers;
}
Expand Down
1 change: 0 additions & 1 deletion contracts/core/primitives/group/GroupCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ library GroupCore {
// Storage

struct Storage {
string metadataURI;
uint256 lastMemberIdAssigned;
uint256 numberOfMembers;
mapping(address => Membership) memberships;
Expand Down
Loading

0 comments on commit 32a724b

Please sign in to comment.