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

Relationship Module #37

Merged
merged 35 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2813cfa
simplify errors
Jun 29, 2023
5e8ac2c
added linking module POC
Jun 29, 2023
62dc0f9
eip-7201 helper task
Jul 5, 2023
1d72fa4
removed __gaps in favour of namespaced storage
Jul 5, 2023
f037d5b
Merge branch 'main' into namespaced_storage
Jul 5, 2023
9adc8a5
refactor
Jul 5, 2023
beb9abe
Merge branch 'refactor_story_block_to_ip_asset' into linking_poc
Jul 5, 2023
cb5182e
add directional linking
Jul 6, 2023
8057158
Merge branch 'main' into refactor_story_block_to_ip_asset
Jul 6, 2023
34f2352
Merge branch 'refactor_story_block_to_ip_asset' into linking_poc
Jul 6, 2023
cb457e6
franchise level intents
Jul 7, 2023
a004a0f
missing refactor files and method
Jul 11, 2023
f4cb48f
remove franchise level links
Jul 13, 2023
6f5bca2
removed intent references in favour of link id
Jul 13, 2023
e12675d
link types mask checker
Jul 13, 2023
4a76f03
moret ipAssetTypeTests
Jul 13, 2023
7a69484
tests for linking
Jul 14, 2023
846ef3f
check for link existance and unify errors
Jul 14, 2023
72cf670
refactor regrouping
Jul 14, 2023
fe8fe28
test fixing
Jul 14, 2023
40fd1c1
refactor protocol out of link
Jul 14, 2023
01b0d5d
refactor link to relationship
Jul 15, 2023
eff34d8
rel processor flow control
Jul 15, 2023
0d58886
fix
Jul 15, 2023
04ebdf3
time links
Jul 15, 2023
6ea53d7
fix tests
Jul 15, 2023
a936176
Merge branch 'main' into linking_poc
Jul 15, 2023
dfd1b5e
Protocol relationship module, abstracted base
Jul 21, 2023
50adcc4
multicall links
Jul 21, 2023
5def3e8
kingter comment 1
Jul 24, 2023
352570b
kingter comment 2
Jul 24, 2023
66c824b
natspec
Jul 24, 2023
ee4ce7c
fix error
Jul 25, 2023
10df528
stray link reference
Jul 25, 2023
680ecbd
Update contracts/modules/relationships/ProtocolRelationshipModule.sol
Ramarti Jul 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contracts/FranchiseRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract FranchiseRegistry is

constructor(address _factory) {
_disableInitializers();
if (_factory == address(0)) revert ZeroAddress("factory");
if (_factory == address(0)) revert ZeroAddress();
FACTORY = IPAssetRegistryFactory(_factory);
}

Expand All @@ -66,7 +66,7 @@ contract FranchiseRegistry is
string calldata description
) external returns (uint256, address) {
FranchiseStorage storage $ = _getFranchiseStorage();
address ipAssetRegistry = FACTORY.createFranchiseBlocks(
address ipAssetRegistry = FACTORY.createFranchiseIPAssets(
++$.franchiseIds,
name,
symbol,
Expand Down
2 changes: 1 addition & 1 deletion contracts/IPAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ enum IPAsset {
ITEM
}

uint8 constant EXTERNAL_ASSET = type(uint8).max;
2 changes: 1 addition & 1 deletion contracts/access-control/AccessControlSingleton.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract AccessControlSingleton is AccessControlUpgradeable, UUPSUpgradeable, Mu
* @param _admin address to be the PROTOCOL_ADMIN_ROLE.
*/
function initialize(address _admin) external initializer {
if (_admin == address(0)) revert ZeroAddress("_admin");
if (_admin == address(0)) revert ZeroAddress();
__AccessControl_init();
__UUPSUpgradeable_init();
_grantRole(PROTOCOL_ADMIN_ROLE, _admin);
Expand Down
5 changes: 5 additions & 0 deletions contracts/access-control/AccessControlledUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,9 @@ abstract contract AccessControlledUpgradeable is UUPSUpgradeable {
emit AccessControlUpdated(accessControl);
}

function getAccessControl() public view returns (address) {
AccessControlledStorage storage $ = _getAccessControlledUpgradeable();
return address($.accessControl);
}

}
3 changes: 2 additions & 1 deletion contracts/access-control/ProtocolRoles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pragma solidity ^0.8.13;

bytes32 constant PROTOCOL_ADMIN_ROLE = bytes32(0);
bytes32 constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");
bytes32 constant DAM_APPROVER = keccak256("DAM_APPROVER");
bytes32 constant RELATIONSHIP_MANAGER_ROLE = keccak256("RELATIONSHIP_MANAGER_ROLE");
bytes32 constant RELATIONSHIP_DISPUTER_ROLE = keccak256("RELATIONSHIP_DISPUTER_ROLE");
4 changes: 2 additions & 2 deletions contracts/errors/General.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

pragma solidity ^0.8.13;

error ZeroAddress(string name);
error ZeroAmount(string name);
error ZeroAddress();
error ZeroAmount();
error UnsupportedInterface(string name);
error Unauthorized();
error NonExistentID(uint256 id);
4 changes: 3 additions & 1 deletion contracts/ip-assets/IIPAssetRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ interface IIPAssetRegistry is
IERC721Upgradeable,
IIPAssetData,
IGroupDAM
{ }
{
function franchiseId() external view returns (uint256);
LeoHChen marked this conversation as resolved.
Show resolved Hide resolved
}
4 changes: 2 additions & 2 deletions contracts/ip-assets/IPAssetRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.13;
//import "forge-std/console.sol";
import { IIPAssetRegistry } from "./IIPAssetRegistry.sol";
import { LibIPAssetId } from "./LibIPAssetId.sol";
import { Unauthorized, ZeroAddress } from "../errors/General.sol";
import { Unauthorized, ZeroAmount } from "../errors/General.sol";
import { IPAssetData } from "./data-access-modules/storage/IPAssetData.sol";
import { IPAsset } from "contracts/IPAsset.sol";
import { GroupDAM } from "./data-access-modules/group/GroupDAM.sol";
Expand Down Expand Up @@ -44,7 +44,7 @@ contract IPAssetRegistry is
) public initializer {
__ERC721_init(_name, _symbol);
__Multicall_init();
if (_franchiseId == 0) revert ZeroAddress("franchiseId");
if (_franchiseId == 0) revert ZeroAmount();
IPAssetRegistryStorage storage $ = _getIPAssetRegistryStorage();
$.franchiseId = _franchiseId;
$.description = _description;
Expand Down
2 changes: 1 addition & 1 deletion contracts/ip-assets/IPAssetRegistryFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract IPAssetRegistryFactory is Ownable {
BEACON = new UpgradeableBeacon(address(new IPAssetRegistry()));
}

function createFranchiseBlocks(
function createFranchiseIPAssets(
uint256 franchiseId,
string calldata name,
string calldata symbol,
Expand Down
95 changes: 95 additions & 0 deletions contracts/modules/relationships/IRelationshipModule.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.13;

import { IRelationshipProcessor } from "./RelationshipProcessors/IRelationshipProcessor.sol";
import { IPAsset } from "contracts/IPAsset.sol";


interface IRelationshipModule {

event RelationSet(
Ramarti marked this conversation as resolved.
Show resolved Hide resolved
address sourceContract,
uint256 sourceId,
address destContract,
uint256 destId,
bytes32 indexed relationshipId,
uint256 endTime
);
event RelationUnset(
address sourceContract,
uint256 sourceId,
address destContract,
uint256 destId,
bytes32 indexed relationshipId
);
event RelationPendingProcessor(
address sourceContract,
uint256 sourceId,
address destContract,
uint256 destId,
bytes32 indexed relationshipId
);

event RelationshipConfigSet(
bytes32 indexed relationshipId,
uint256 sourceIPAssetTypeMask,
uint256 destIPAssetTypeMask,
bool onlySameFranchise,
address processor,
uint256 maxTTL,
uint256 minTTL
);

event RelationshipConfigUnset(bytes32 indexed relationshipId);

error NonExistingRelationship();
error IntentAlreadyRegistered();
error UnsupportedRelationshipSrc();
error UnsupportedRelationshipDst();
error CannotRelateToOtherFranchise();
error InvalidTTL();
error InvalidEndTimestamp();

struct TimeConfig {
uint112 maxTTL;
uint112 minTTL;
bool renewable;
}

struct RelationshipConfig {
uint256 sourceIPAssetTypeMask;
uint256 destIPAssetTypeMask;
bool onlySameFranchise;
IRelationshipProcessor processor;
address disputer;
TimeConfig timeConfig;
}

struct SetRelationshipConfigParams {
IPAsset[] sourceIPAssets;
bool allowedExternalSource;
IPAsset[] destIPAssets;
bool allowedExternalDest;
bool onlySameFranchise;
address processor;
address disputer;
TimeConfig timeConfig;
}

struct RelationshipParams {
address sourceContract;
uint256 sourceId;
address destContract;
uint256 destId;
bytes32 relationshipId;
uint256 ttl;
}

function relate(RelationshipParams calldata params, bytes calldata data) external;
function unrelate(RelationshipParams calldata params) external;
function areTheyRelated(RelationshipParams calldata params) external view returns (bool);
function isRelationshipExpired(RelationshipParams calldata params) external view returns (bool);
function setRelationshipConfig(bytes32 relationshipId, SetRelationshipConfigParams calldata params) external;
function unsetRelationshipConfig(bytes32 relationshipId) external;
function relationshipConfig(bytes32 relationshipId) external view returns (RelationshipConfig memory);
}
37 changes: 37 additions & 0 deletions contracts/modules/relationships/ProtocolRelationshipModule.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.13;

import { RelationshipModuleBase } from "./RelationshipModuleBase.sol";
import { UPGRADER_ROLE, RELATIONSHIP_MANAGER_ROLE, RELATIONSHIP_DISPUTER_ROLE } from "contracts/access-control/ProtocolRoles.sol";

/**
* @title ProtocolRelationshipModule
* @dev Implementation of RelationshipModuleBase that allows relationship configs that will be used protocol wide.
* The meaning and parameters of the relationships are to be defined in Story Protocol Improvement Proposals.
* Example: https://github.com/storyprotocol/protocol-contracts/issues/33
* The relationship configs are set by the RELATIONSHIP_MANAGER_ROLE.
* Upgrades are done by the UPGRADER_ROLE.
*/
contract ProtocolRelationshipModule is RelationshipModuleBase {

constructor(address _franchiseRegistry) RelationshipModuleBase(_franchiseRegistry) {}

function initialize(address accessControl) public initializer {
__RelationshipModuleBase_init(accessControl);
}

/********* Setting Relationships *********/
function setRelationshipConfig(bytes32 relationshipId, SetRelationshipConfigParams calldata params) external onlyRole(RELATIONSHIP_MANAGER_ROLE) {
_setRelationshipConfig(relationshipId, params);
}

function unsetRelationshipConfig(bytes32 relationshipId) external onlyRole(RELATIONSHIP_MANAGER_ROLE) {
_unsetRelationshipConfig(relationshipId);
}


function _authorizeUpgrade(
address newImplementation
) internal virtual override onlyRole(UPGRADER_ROLE) {}

}
Loading