Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Code changes with Compile without viair #73

Merged
merged 9 commits into from
Jan 10, 2025
76 changes: 35 additions & 41 deletions contracts/core/base/RuleBasedPrimitive.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract contract RuleBasedPrimitive {
using RulesLib for RulesStorage;
using CallLib for address;

function _changePrimitiveRules(RulesStorage storage rulesStorage, RuleChange[] calldata ruleChanges)
function _changePrimitiveRules(RulesStorage storage rulesStorage, RuleChange[] memory ruleChanges)
internal
virtual
{
Expand All @@ -36,8 +36,8 @@ abstract contract RuleBasedPrimitive {
function _changeEntityRules(
RulesStorage storage rulesStorage,
uint256 entityId,
RuleChange[] calldata ruleChanges,
RuleProcessingParams[] calldata ruleChangesProcessingParams
RuleChange[] memory ruleChanges,
RuleProcessingParams[] memory ruleChangesProcessingParams
) internal virtual {
_changeRules(
rulesStorage,
Expand All @@ -50,7 +50,7 @@ abstract contract RuleBasedPrimitive {
);
}

function _encodeConfigureCall(uint256 entityId, bytes32 configSalt, KeyValue[] calldata ruleParams)
function _encodeConfigureCall(uint256 entityId, bytes32 configSalt, KeyValue[] memory ruleParams)
internal
pure
returns (bytes memory)
Expand All @@ -67,7 +67,7 @@ abstract contract RuleBasedPrimitive {
uint256 entityId,
address ruleAddress,
bytes32 configSalt,
KeyValue[] calldata ruleParams
KeyValue[] memory ruleParams
) internal {
if (entityId == 0) {
_emitPrimitiveRuleConfiguredEvent(wasAlreadyConfigured, ruleAddress, configSalt, ruleParams);
Expand All @@ -93,7 +93,7 @@ abstract contract RuleBasedPrimitive {

// Primitive functions:

function _encodePrimitiveConfigureCall(bytes32 configSalt, KeyValue[] calldata ruleParams)
function _encodePrimitiveConfigureCall(bytes32 configSalt, KeyValue[] memory ruleParams)
internal
pure
virtual
Expand All @@ -103,7 +103,7 @@ abstract contract RuleBasedPrimitive {
bool wasAlreadyConfigured,
address ruleAddress,
bytes32 configSalt,
KeyValue[] calldata ruleParams
KeyValue[] memory ruleParams
) internal virtual;

function _emitPrimitiveRuleSelectorEvent(
Expand All @@ -116,7 +116,7 @@ abstract contract RuleBasedPrimitive {

// Entity functions:

function _encodeEntityConfigureCall(uint256 entityId, bytes32 configSalt, KeyValue[] calldata ruleParams)
function _encodeEntityConfigureCall(uint256 entityId, bytes32 configSalt, KeyValue[] memory ruleParams)
internal
pure
virtual
Expand All @@ -128,7 +128,7 @@ abstract contract RuleBasedPrimitive {
uint256 entityId,
address ruleAddress,
bytes32 configSalt,
KeyValue[] calldata ruleParams
KeyValue[] memory ruleParams
) internal virtual {}

function _emitEntityRuleSelectorEvent(
Expand All @@ -145,39 +145,26 @@ abstract contract RuleBasedPrimitive {
function _changeRules(
RulesStorage storage rulesStorage,
uint256 entityId,
RuleChange[] calldata ruleChanges,
RuleChange[] memory ruleChanges,
RuleProcessingParams[] memory ruleChangesProcessingParams,
function(uint256,bytes32,KeyValue[] calldata) internal returns (bytes memory) fn_encodeConfigureCall,
function(bool,uint256,address,bytes32,KeyValue[] calldata) internal fn_emitConfiguredEvent,
function(uint256,bytes32,KeyValue[] memory) internal returns (bytes memory) fn_encodeConfigureCall,
function(bool,uint256,address,bytes32,KeyValue[] memory) internal fn_emitConfiguredEvent,
function(bool,uint256,address,bytes32,bool,bytes4) internal fn_emitSelectorEvent
) private {
_beforeChangeRules(entityId, ruleChanges);
for (uint256 i = 0; i < ruleChanges.length; i++) {
RuleChange memory ruleChange = ruleChanges[i];
if (ruleChange.configurationChanges.configure) {
ruleChange.configSalt = _configureRule(
rulesStorage,
ruleChanges[i].ruleAddress,
ruleChanges[i].configSalt,
entityId,
ruleChanges[i].configurationChanges.ruleParams,
fn_encodeConfigureCall,
fn_emitConfiguredEvent
);
ruleChange.configSalt =
_configureRule(rulesStorage, ruleChange, entityId, fn_encodeConfigureCall, fn_emitConfiguredEvent);
}
for (uint256 j = 0; j < ruleChange.selectorChanges.length; j++) {
_validateIsSupportedRuleSelector(
ruleChange.selectorChanges[j].ruleSelector,
entityId == 0 ? _supportedPrimitiveRuleSelectors() : _supportedEntityRuleSelectors()
);
rulesStorage._changeRulesSelectors(
ruleChanges[i].ruleAddress,
ruleChange.configSalt,
entityId,
ruleChanges[i].selectorChanges[j].ruleSelector,
ruleChanges[i].selectorChanges[j].isRequired,
ruleChanges[i].selectorChanges[j].enabled,
fn_emitSelectorEvent
ruleChange, entityId, ruleChange.selectorChanges[j], fn_emitSelectorEvent
);
}
}
Expand Down Expand Up @@ -207,7 +194,7 @@ abstract contract RuleBasedPrimitive {
revert Errors.UnsupportedSelector();
}

function _beforeChangeRules(uint256 entityId, RuleChange[] calldata ruleChanges) internal virtual {
function _beforeChangeRules(uint256 entityId, RuleChange[] memory ruleChanges) internal virtual {
if (entityId == 0) {
_beforeChangePrimitiveRules(ruleChanges);
} else {
Expand All @@ -217,7 +204,7 @@ abstract contract RuleBasedPrimitive {

function _processEntityRulesChanges(
uint256 entityId,
RuleChange[] calldata ruleChanges,
RuleChange[] memory ruleChanges,
RuleProcessingParams[] memory ruleChangesProcessingParams
) internal virtual {}

Expand All @@ -234,23 +221,30 @@ abstract contract RuleBasedPrimitive {
}
}

function _beforeChangePrimitiveRules(RuleChange[] calldata ruleChanges) internal virtual {}
function _beforeChangePrimitiveRules(RuleChange[] memory ruleChanges) internal virtual {}

function _beforeChangeEntityRules(uint256 entityId, RuleChange[] calldata ruleChanges) internal virtual {}
function _beforeChangeEntityRules(uint256 entityId, RuleChange[] memory ruleChanges) internal virtual {}

function _configureRule(
RulesStorage storage rulesStorage,
address ruleAddress,
bytes32 providedConfigSalt,
RuleChange memory ruleChange,
uint256 entityId,
KeyValue[] calldata ruleParams,
function(uint256,bytes32,KeyValue[] calldata) internal returns (bytes memory) fn_encodeConfigureCall,
function(bool,uint256,address,bytes32,KeyValue[] calldata) internal fn_emitEvent
function(uint256,bytes32,KeyValue[] memory) internal returns (bytes memory) fn_encodeConfigureCall,
function(bool,uint256,address,bytes32,KeyValue[] memory) internal fn_emitEvent
) internal returns (bytes32) {
bytes32 configSalt = rulesStorage.generateOrValidateConfigSalt(ruleAddress, providedConfigSalt);
bool wasAlreadyConfigured =
rulesStorage.configureRule(ruleAddress, configSalt, fn_encodeConfigureCall(entityId, configSalt, ruleParams));
fn_emitEvent(wasAlreadyConfigured, entityId, ruleAddress, configSalt, ruleParams);
bytes32 configSalt = rulesStorage.generateOrValidateConfigSalt(ruleChange.ruleAddress, ruleChange.configSalt);
bool wasAlreadyConfigured = rulesStorage.configureRule(
ruleChange.ruleAddress,
configSalt,
fn_encodeConfigureCall(entityId, configSalt, ruleChange.configurationChanges.ruleParams)
);
fn_emitEvent(
wasAlreadyConfigured,
entityId,
ruleChange.ruleAddress,
configSalt,
ruleChange.configurationChanges.ruleParams
);
return configSalt;
}
}
6 changes: 3 additions & 3 deletions contracts/core/base/SourceStampBased.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract contract SourceStampBased is ExtraStorageBased {
// TODO: We might consider moving source storing out of this contract (see Post created VS lastUpdated source)
function _processSourceStamp(
uint256 entityId,
KeyValue[] calldata customParams,
KeyValue[] memory customParams,
bool storeSource,
bool lastUpdatedSourceType
) internal returns (address) {
Expand All @@ -40,14 +40,14 @@ abstract contract SourceStampBased is ExtraStorageBased {
return address(0);
}

function _processSourceStamp(uint256 entityId, KeyValue[] calldata customParams, bool storeSource)
function _processSourceStamp(uint256 entityId, KeyValue[] memory customParams, bool storeSource)
internal
returns (address)
{
return _processSourceStamp(entityId, customParams, storeSource, false);
}

function _processSourceStamp(uint256 entityId, KeyValue[] calldata customParams) internal returns (address) {
function _processSourceStamp(uint256 entityId, KeyValue[] memory customParams) internal returns (address) {
return _processSourceStamp(entityId, customParams, true, false);
}

Expand Down
28 changes: 19 additions & 9 deletions contracts/core/libraries/RulesLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (C) 2024 Lens Labs. All Rights Reserved.
pragma solidity ^0.8.26;

import {Rule} from "contracts/core/types/Types.sol";
import {Rule, RuleChange, RuleSelectorChange} from "contracts/core/types/Types.sol";
import {CallLib} from "contracts/core/libraries/CallLib.sol";
import {Errors} from "contracts/core/types/Errors.sol";

Expand Down Expand Up @@ -89,18 +89,28 @@ library RulesLib {

function _changeRulesSelectors(
RulesStorage storage rulesStorage,
address ruleAddress,
bytes32 configSalt,
RuleChange memory ruleChange,
uint256 entityId,
bytes4 ruleSelector,
bool isRequired,
bool enabled,
RuleSelectorChange memory ruleSelectorChange,
function(bool,uint256,address,bytes32,bool,bytes4) internal fn_emitEvent
) internal {
function(RulesStorage storage, bool, address, bytes32, bytes4) internal fn_changeRuleSelector =
enabled ? RulesLib.enableRuleSelector : RulesLib.disableRuleSelector;
fn_changeRuleSelector(rulesStorage, isRequired, ruleAddress, configSalt, ruleSelector);
fn_emitEvent(enabled, entityId, ruleAddress, configSalt, isRequired, ruleSelector);
ruleSelectorChange.enabled ? RulesLib.enableRuleSelector : RulesLib.disableRuleSelector;
fn_changeRuleSelector(
rulesStorage,
ruleSelectorChange.isRequired,
ruleChange.ruleAddress,
ruleChange.configSalt,
ruleSelectorChange.ruleSelector
);
fn_emitEvent(
ruleSelectorChange.enabled,
entityId,
ruleChange.ruleAddress,
ruleChange.configSalt,
ruleSelectorChange.isRequired,
ruleSelectorChange.ruleSelector
);
}

// Private
Expand Down
24 changes: 12 additions & 12 deletions contracts/core/primitives/feed/Feed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ contract Feed is
_requireAccess(msg.sender, PID__SET_METADATA);
}

function _beforeChangePrimitiveRules(RuleChange[] calldata /* ruleChanges */ ) internal virtual override {
function _beforeChangePrimitiveRules(RuleChange[] memory /* ruleChanges */ ) internal virtual override {
_requireAccess(msg.sender, PID__CHANGE_RULES);
}

function _beforeChangeEntityRules(uint256 entityId, RuleChange[] calldata /* ruleChanges */ )
function _beforeChangeEntityRules(uint256 entityId, RuleChange[] memory /* ruleChanges */ )
internal
virtual
override
Expand All @@ -84,11 +84,11 @@ contract Feed is
// Public user functions

function createPost(
CreatePostParams calldata postParams,
KeyValue[] calldata customParams,
RuleProcessingParams[] calldata feedRulesParams,
RuleProcessingParams[] calldata rootPostRulesParams,
RuleProcessingParams[] calldata quotedPostRulesParams
CreatePostParams memory postParams,
KeyValue[] memory customParams,
RuleProcessingParams[] memory feedRulesParams,
RuleProcessingParams[] memory rootPostRulesParams,
RuleProcessingParams[] memory quotedPostRulesParams
) external virtual override returns (uint256) {
require(msg.sender == postParams.author, Errors.InvalidMsgSender());
(uint256 postId, uint256 authorPostSequentialId, uint256 rootPostId) = Core._createPost(postParams);
Expand Down Expand Up @@ -133,11 +133,11 @@ contract Feed is

function editPost(
uint256 postId,
EditPostParams calldata postParams,
KeyValue[] calldata customParams,
RuleProcessingParams[] calldata feedRulesParams,
RuleProcessingParams[] calldata rootPostRulesParams,
RuleProcessingParams[] calldata quotedPostRulesParams
EditPostParams memory postParams,
KeyValue[] memory customParams,
RuleProcessingParams[] memory feedRulesParams,
RuleProcessingParams[] memory rootPostRulesParams,
RuleProcessingParams[] memory quotedPostRulesParams
) external virtual override {
address author = Core.$storage().posts[postId].author;
// TODO: We can have this for moderators:
Expand Down
2 changes: 1 addition & 1 deletion contracts/core/primitives/feed/FeedCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ library FeedCore {
return uint256(keccak256(abi.encode("evm:", block.chainid, address(this), author, authorPostSequentialId)));
}

function _createPost(CreatePostParams calldata postParams) internal returns (uint256, uint256, uint256) {
function _createPost(CreatePostParams memory postParams) internal returns (uint256, uint256, uint256) {
uint256 postSequentialId = ++$storage().postCount;
uint256 authorPostSequentialId = ++$storage().authorPostCount[postParams.author];
uint256 postId = _generatePostId(postParams.author, authorPostSequentialId);
Expand Down
Loading