Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Raul committed Jan 26, 2024
2 parents 8400264 + 6de2d8b commit 92167b8
Show file tree
Hide file tree
Showing 44 changed files with 2,337 additions and 1,015 deletions.
81 changes: 68 additions & 13 deletions contracts/IPAccountImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { IERC1155Receiver } from "@openzeppelin/contracts/token/ERC1155/IERC1155
import { IAccessController } from "contracts/interfaces/IAccessController.sol";
import { IERC6551Account } from "lib/reference/src/interfaces/IERC6551Account.sol";
import { IIPAccount } from "contracts/interfaces/IIPAccount.sol";
import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
import { AccessPermission } from "contracts/lib/AccessPermission.sol";
import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import { MetaTx } from "contracts/lib/MetaTx.sol";
import { Errors } from "contracts/lib/Errors.sol";

/// @title IPAccountImpl
/// @notice The Story Protocol's implementation of the IPAccount.
Expand Down Expand Up @@ -94,24 +99,55 @@ contract IPAccountImpl is IERC165, IIPAccount {
return IAccessController(accessController).checkPermission(address(this), signer_, to_, selector);
}

/// @notice Executes a transaction from the IP Account.
/// @param to_ The recipient of the transaction.
/// @param value_ The amount of Ether to send.
/// @param data_ The data to send along with the transaction.
/// @return result The return data from the transaction.
function execute(address to_, uint256 value_, bytes calldata data_) external payable returns (bytes memory result) {
require(_isValidSigner(msg.sender, to_, data_), "Invalid signer");
/// @notice Executes a transaction from the IP Account on behalf of the signer.
/// @param to The recipient of the transaction.
/// @param value The amount of Ether to send.
/// @param data The data to send along with the transaction.
/// @param signer The signer of the transaction.
/// @param deadline The deadline of the transaction signature.
/// @param signature The signature of the transaction, EIP-712 encoded.
function executeWithSig(
address to,
uint256 value,
bytes calldata data,
address signer,
uint256 deadline,
bytes calldata signature
) external payable returns (bytes memory result) {
if (signer == address(0)) {
revert Errors.IPAccount__InvalidSigner();
}

if (deadline < block.timestamp) {
revert Errors.IPAccount__ExpiredSignature();
}

++state;

bool success;
(success, result) = to_.call{ value: value_ }(data_);
bytes32 digest = MessageHashUtils.toTypedDataHash(
MetaTx.calculateDomainSeparator(),
MetaTx.getExecuteStructHash(
MetaTx.Execute({ to: to, value: value, data: data, nonce: state, deadline: deadline })
)
);

if (!success) {
assembly {
revert(add(result, 32), mload(result))
}
if (!SignatureChecker.isValidSignatureNow(signer, digest, signature)) {
revert Errors.IPAccount__InvalidSignature();
}

result = _execute(signer, to, value, data);
emit ExecutedWithSig(to, value, data, state, deadline, signer, signature);
}

/// @notice Executes a transaction from the IP Account.
/// @param to The recipient of the transaction.
/// @param value The amount of Ether to send.
/// @param data The data to send along with the transaction.
/// @return result The return data from the transaction.
function execute(address to, uint256 value, bytes calldata data) external payable returns (bytes memory result) {
++state;
result = _execute(msg.sender, to, value, data);
emit Executed(to, value, data, state);
}

function onERC721Received(address, address, uint256, bytes memory) public pure returns (bytes4) {
Expand All @@ -131,4 +167,23 @@ contract IPAccountImpl is IERC165, IIPAccount {
) public pure returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}

function _execute(
address signer,
address to,
uint256 value,
bytes calldata data
) internal returns (bytes memory result) {
require(_isValidSigner(signer, to, data), "Invalid signer");

bool success;
(success, result) = to.call{ value: value }(data);

if (!success) {
assembly {
revert(add(result, 32), mload(result))
}
}
}

}
30 changes: 30 additions & 0 deletions contracts/interfaces/IIPAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,43 @@ import { IERC6551Account } from "lib/reference/src/interfaces/IERC6551Account.so
/// This allows for seamless operations on the state and data of IP.
/// IPAccount is core identity for all actions.
interface IIPAccount is IERC6551Account, IERC721Receiver, IERC1155Receiver {
/// @notice Emitted when a transaction is executed.
event Executed(address indexed to, uint256 value, bytes data, uint256 nonce);

/// @notice Emitted when a transaction is executed on behalf of the signer.
event ExecutedWithSig(
address indexed to,
uint256 value,
bytes data,
uint256 nonce,
uint256 deadline,
address indexed signer,
bytes signature
);

/// @notice Executes a transaction from the IP Account.
/// @param to_ The recipient of the transaction.
/// @param value_ The amount of Ether to send.
/// @param data_ The data to send along with the transaction.
/// @return The return data from the transaction.
function execute(address to_, uint256 value_, bytes calldata data_) external payable returns (bytes memory);

/// @notice Executes a transaction from the IP Account on behalf of the signer.
/// @param to The recipient of the transaction.
/// @param value The amount of Ether to send.
/// @param data The data to send along with the transaction.
/// @param signer The signer of the transaction.
/// @param deadline The deadline of the transaction signature.
/// @param signature The signature of the transaction, EIP-712 encoded.
function executeWithSig(
address to,
uint256 value,
bytes calldata data,
address signer,
uint256 deadline,
bytes calldata signature
) external payable returns (bytes memory);

/// @notice Returns the owner of the IP Account.
/// @return The address of the owner.
function owner() external view returns (address);
Expand Down
4 changes: 2 additions & 2 deletions contracts/interfaces/modules/IRegistrationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface IRegistrationModule {
address tokenContract,
uint256 tokenId,
string memory ipName,
string memory ipDescription,
bytes32 hash
bytes32 hash,
string calldata externalURL
) external;
}
77 changes: 65 additions & 12 deletions contracts/interfaces/modules/dispute/IDisputeModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,55 @@ pragma solidity ^0.8.23;

/// @title Dispute Module Interface
interface IDisputeModule {
/// @notice Event emitted when a dispute tag whitelist status is updated
/// @param tag The dispute tag
/// @param allowed Indicates if the dispute tag is whitelisted
event TagWhitelistUpdated(bytes32 tag, bool allowed);

/// @notice Event emitted when an arbitration policy whitelist status is updated
/// @param arbitrationPolicy The address of the arbitration policy
/// @param allowed Indicates if the arbitration policy is whitelisted
event ArbitrationPolicyWhitelistUpdated(address arbitrationPolicy, bool allowed);

/// @notice Event emitted when an arbitration relayer whitelist status is updated
/// @param arbitrationPolicy The address of the arbitration policy
/// @param arbitrationRelayer The address of the arbitration relayer
/// @param allowed Indicates if the arbitration relayer is whitelisted
event ArbitrationRelayerWhitelistUpdated(address arbitrationPolicy, address arbitrationRelayer, bool allowed);

/// @notice Event emitted when a dispute is raised
/// @param disputeId The dispute id
/// @param targetIpId The ipId that is the target of the dispute
/// @param disputeInitiator The address of the dispute initiator
/// @param arbitrationPolicy The address of the arbitration policy
/// @param linkToDisputeEvidence The link of the dispute evidence
/// @param targetTag The target tag of the dispute
/// @param data Custom data adjusted to each policy
event DisputeRaised(
uint256 disputeId,
address targetIpId,
address disputeInitiator,
address arbitrationPolicy,
bytes32 linkToDisputeEvidence,
bytes32 targetTag,
bytes data
);

/// @notice Event emitted when a dispute judgement is set
/// @param disputeId The dispute id
/// @param decision The decision of the dispute
/// @param data Custom data adjusted to each policy
event DisputeJudgementSet(uint256 disputeId, bool decision, bytes data);

/// @notice Event emitted when a dispute is cancelled
/// @param disputeId The dispute id
/// @param data Custom data adjusted to each policy
event DisputeCancelled(uint256 disputeId, bytes data);

/// @notice Event emitted when a dispute is resolved
/// @param disputeId The dispute id
event DisputeResolved(uint256 disputeId);

/// @notice Whitelists a dispute tag
/// @param tag The dispute tag
/// @param allowed Indicates if the dispute tag is whitelisted or not
Expand All @@ -18,18 +67,18 @@ interface IDisputeModule {
/// @param arbPolicyRelayer The address of the arbitration relayer
/// @param allowed Indicates if the arbitration relayer is whitelisted or not
function whitelistArbitrationRelayer(address arbitrationPolicy, address arbPolicyRelayer, bool allowed) external;

/// @notice Raises a dispute
/// @param ipId The ipId
/// @param targetIpId The ipId that is the target of the dispute
/// @param arbitrationPolicy The address of the arbitration policy
/// @param linkToDisputeSummary The link of the dispute summary
/// @param linkToDisputeEvidence The link of the dispute evidence
/// @param targetTag The target tag of the dispute
/// @param data The data to initialize the policy
/// @return disputeId The dispute id
function raiseDispute(
address ipId,
address targetIpId,
address arbitrationPolicy,
string memory linkToDisputeSummary,
string memory linkToDisputeEvidence,
bytes32 targetTag,
bytes calldata data
) external returns (uint256 disputeId);
Expand All @@ -50,11 +99,15 @@ interface IDisputeModule {
function resolveDispute(uint256 disputeId) external;

/// @notice Gets the dispute struct characteristics
function disputes(uint256 disputeId) external view returns (
address ipId,
address disputeInitiator,
address arbitrationPolicy,
bytes32 linkToDisputeSummary,
bytes32 tag
);
function disputes(uint256 disputeId)
external
view
returns (
address targetIpId, // The ipId that is the target of the dispute
address disputeInitiator, // The address of the dispute initiator
address arbitrationPolicy, // The address of the arbitration policy
bytes32 linkToDisputeEvidence, // The link of the dispute summary
bytes32 targetTag, // The target tag of the dispute
bytes32 currentTag // The current tag of the dispute
);
}
22 changes: 20 additions & 2 deletions contracts/interfaces/registries/IIPRecordRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ interface IIPRecordRegistry {
/// @param tokenContract The address of the IP.
/// @param tokenId The token identifier of the IP.
/// @param resolver The address of the resolver linked to the IP.
/// @param provider The address of the metadata provider linked to the IP.
event IPRegistered(
address ipId,
uint256 indexed chainId,
address indexed tokenContract,
uint256 indexed tokenId,
address resolver
address resolver,
address provider
);

/// @notice Emits when an IP account is created for an IP.
Expand All @@ -39,6 +41,14 @@ interface IIPRecordRegistry {
address resolver
);

/// @notice Emits when a metadata provider is set for an IP.
/// @param ipId The canonical identifier of the specified IP.
/// @param metadataProvider Address of the metadata provider associated with the IP.
event MetadataProviderSet(
address ipId,
address metadataProvider
);

/// @notice Gets the canonical IP identifier associated with an IP (NFT).
/// @dev This is the same as the address of the IP account bound to the IP.
/// @param chainId The chain identifier of where the IP resides.
Expand Down Expand Up @@ -87,18 +97,26 @@ interface IIPRecordRegistry {
uint256 tokenId
) external view returns (address);

/// @notice Gets the metadata provider linked to an IP based on its ID.
/// @param id The canonical identifier for the IP.
/// @return The metadata that was bound to this IP at creation time.
function metadataProvider(address id) external view returns (address);

/// @notice Registers an NFT as IP, creating a corresponding IP record.
/// @dev This is only callable by an authorized registration module.
/// @param chainId The chain identifier of where the IP resides.
/// @param tokenContract The address of the IP.
/// @param tokenId The token identifier of the IP.
/// @param resolverAddr The address of the resolver to associate with the IP.
/// @param createAccount Whether to create an IP account in the process.
/// @param metadataProvider The metadata provider to associate with the IP.
function register(
uint256 chainId,
address tokenContract,
uint256 tokenId,
address resolverAddr,
bool createAccount
bool createAccount,
address metadataProvider
) external returns (address);

/// @notice Creates the IP account for the specified IP.
Expand Down
11 changes: 11 additions & 0 deletions contracts/interfaces/registries/metadata/IMetadataProvider.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: UNLICENSED
// See https://github.com/storyprotocol/protocol-contracts/blob/main/StoryProtocol-AlphaTestingAgreement-17942166.3.pdf
pragma solidity ^0.8.23;

/// @title Metadata Provider Interface
interface IMetadataProvider {

/// @notice Gets the metadata associated with an IP asset.
/// @param ipId The address identifier of the IP asset.
function getMetadata(address ipId) external view returns (bytes memory);
}
Loading

0 comments on commit 92167b8

Please sign in to comment.