Skip to content

Commit

Permalink
Update erc-321
Browse files Browse the repository at this point in the history
  • Loading branch information
SaulBuilds authored Feb 17, 2024
1 parent c48d66d commit e7ef36f
Showing 1 changed file with 8 additions and 71 deletions.
79 changes: 8 additions & 71 deletions ERCS/erc-321
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
eip: eip-321
eip: 321

Check failure on line 2 in ERCS/erc-321

View workflow job for this annotation

GitHub Actions / EIP Walidator

file name must reflect the preamble header `eip`

error[preamble-file-name]: file name must reflect the preamble header `eip` --> ERCS/erc-321:2:5 | 2 | eip: 321 | ^^^^ this value | = help: this file's name should be `erc-321.md` = help: see https://ethereum.github.io/eipw/preamble-file-name/

Check failure on line 2 in ERCS/erc-321

View workflow job for this annotation

GitHub Actions / EIP Walidator

file name must reflect the preamble header `eip`

error[preamble-file-name]: file name must reflect the preamble header `eip` --> ERCS/erc-321:2:5 | 2 | eip: 321 | ^^^^ this value | = help: this file's name should be `erc-321.md` = help: see https://ethereum.github.io/eipw/preamble-file-name/
title: Smart Contract Id's and Metadata Extension
description: interface for contractId's and metadata at the smartcontract level
description: Proposes an interface for contractId's and metadata at the smart contract level.
author: Larry V. Kłosowski (@SaulBuilds)
discussions-to: https://ethereum-magicians.org/t/eip-321-smart-contract-id-tokenization-standard/18742
status: Draft
Expand All @@ -18,15 +18,13 @@ This EIP introduces a protocol for the tokenization of smart contracts, facilita

The advancement of blockchain technology and the proliferation of decentralized applications (dApps) underscore the need for a dynamic, interoperable protocol for managing smart contracts. A standardized mechanism for tokenization, exchange, and aggregation is necessary. This EIP, with its ERC-321Metadata extension, proposes a structured interface for lifecycle management of smart contracts within marketplaces.

Check failure on line 19 in ERCS/erc-321

View workflow job for this annotation

GitHub Actions / EIP Walidator

the first match of the given pattern must be a link

error[markdown-link-first]: the first match of the given pattern must be a link --> ERCS/erc-321 | 19 | The advancement of blockchain technology and the proliferation of decentralized applications (dApps) underscore the need for a dynamic, interoperable protocol for managing smart contracts. A standardized mechanism for tokenization, exchange, and aggregation is necessary. This EIP, with its ERC-321Metadata extension, proposes a structured interface for lifecycle management of smart contracts within marketplaces. | = info: the pattern in question: `(?i)(?:eip|erc)-[0-9]+` = help: see https://ethereum.github.io/eipw/markdown-link-first/

Check failure on line 19 in ERCS/erc-321

View workflow job for this annotation

GitHub Actions / EIP Walidator

the first match of the given pattern must be a link

error[markdown-link-first]: the first match of the given pattern must be a link --> ERCS/erc-321 | 19 | The advancement of blockchain technology and the proliferation of decentralized applications (dApps) underscore the need for a dynamic, interoperable protocol for managing smart contracts. A standardized mechanism for tokenization, exchange, and aggregation is necessary. This EIP, with its ERC-321Metadata extension, proposes a structured interface for lifecycle management of smart contracts within marketplaces. | = info: the pattern in question: `(?i)(?:eip|erc)-[0-9]+` = help: see https://ethereum.github.io/eipw/markdown-link-first/


## Specification

```solidity
interface IERC321Metadata is IERC321 {
function tokenURI(uint256 contractId) external view returns (string memory);
}
```

## Rationale

This interface addresses the need for a systematic approach to smart contract tokenization, facilitating the safe sale and transfer of smart contracts on marketplaces. It lays the foundation for an acquisitions market and a legal framework for smart contract sales and trade.
Expand All @@ -35,7 +33,6 @@ This interface addresses the need for a systematic approach to smart contract to

ERC-321 is designed with backward compatibility in mind, ensuring seamless interaction with existing ERC standards and the broader Ethereum ecosystem.

Check failure on line 34 in ERCS/erc-321

View workflow job for this annotation

GitHub Actions / EIP Walidator

the first match of the given pattern must be a link

error[markdown-link-first]: the first match of the given pattern must be a link --> ERCS/erc-321 | 34 | ERC-321 is designed with backward compatibility in mind, ensuring seamless interaction with existing ERC standards and the broader Ethereum ecosystem. | = info: the pattern in question: `(?i)(?:eip|erc)-[0-9]+`

Check failure on line 34 in ERCS/erc-321

View workflow job for this annotation

GitHub Actions / EIP Walidator

the first match of the given pattern must be a link

error[markdown-link-first]: the first match of the given pattern must be a link --> ERCS/erc-321 | 34 | ERC-321 is designed with backward compatibility in mind, ensuring seamless interaction with existing ERC standards and the broader Ethereum ecosystem. | = info: the pattern in question: `(?i)(?:eip|erc)-[0-9]+`


## Reference Implementation

The reference implementation provided demonstrates the application of this EIP in creating and managing tokenized smart contracts with unique identifiers and metadata.
Expand All @@ -48,129 +45,69 @@ import "lib/openzeppelin-contracts/contracts/utils/Create2.sol";
import "../interfaces/IERC321Metadata.sol";
import "./templates/ERC721.sol";

/**
* @title ERC321 Marketplace
* @dev Implements ERC321 for the creation, management, and tokenization of smart contracts.
* Enables the creation of contract instances using either direct deployment or CREATE2 for deterministic addresses.
* Each instance is uniquely identified by a contractId, facilitating their management and interaction.
*/
contract ContractMarketplace is IERC321Metadata, Ownable {
/// @notice Next available contract ID
uint256 private _nextContractId;

/// @notice Mapping from contract ID to its deployed instance address
mapping(uint256 => address) private _contractInstances;

/// @notice Mapping from contract ID to its metadata URI
mapping(uint256 => string) private _metadataURIs;

/**
* @dev Sets the owner upon deployment and initializes contract IDs.
*/
constructor() Ownable(msg.sender) {
_nextContractId = 0;
}

/**
* @notice Creates a new contract instance with metadata, using a unique salt for deterministic deployment.
* @dev Uses the CREATE2 opcode for deploying contracts, allowing for predictable addresses.
* @param _metadata The metadata associated with the new contract instance.
* @param _salt A unique salt to determine the contract's address.
* @return contractId The ID assigned to the newly created contract instance.
*/
function createInstanceWithCreate2(
bytes calldata _metadata,
bytes32 _salt
)
function createInstanceWithCreate2(bytes calldata _metadata, bytes32 _salt)
external
returns (uint256 contractId)
{
require(_metadata.length > 0, "Invalid metadata: Metadata cannot be empty.");

bytes memory bytecode = abi.encodePacked(type(ERC721Example).creationCode);
address instance = Create2.deploy(0, _salt, bytecode);
require(instance != address(0), "Deployment failed: Contract instance could not be deployed.");

contractId = _nextContractId++;
_contractInstances[contractId] = instance;
_metadataURIs[contractId] = string(_metadata);

emit ContractInstanceCreated(instance, contractId);
}

/**
* @notice Retrieves the metadata URI for a specified contract ID.
* @dev Returns the metadata URI associated with the given contract ID.
* @param contractId The ID of the contract instance.
* @return The metadata URI of the specified contract instance.
*/
function tokenURI(uint256 contractId) external view override returns (string memory) {
require(contractId < _nextContractId, "Query for nonexistent contract: This contract ID does not exist.");
require(_contractInstances[contractId] != address(0), "Contract instance destroyed: The contract has been destroyed and is no longer available.");
return _metadataURIs[contractId];
}

/**
* @notice Retrieves the address of the contract instance associated with the given contract ID.
* @dev Returns the contract instance address for the specified contract ID.
* @param contractId The ID of the contract instance.
* @return The address of the contract instance.
*/
function instanceAddress(uint256 contractId) public view returns (address) {
require(contractId < _nextContractId, "Query for nonexistent contract: This contract ID does not exist.");
return _contractInstances[contractId];
}

/**
* @notice Updates the metadata URI for a specified contract ID.
* @dev Can only be called by the contract owner. Updates the metadata URI associated with a contract ID.
* @param contractId The ID of the contract instance to update.
* @param _newMetadataURI The new metadata URI to be associated with the contract ID.
*/
function updateMetadataURI(
uint256 contractId,
string calldata _newMetadataURI
) external onlyOwner {
function updateMetadataURI(uint256 contractId, string calldata _newMetadataURI) external onlyOwner {
require(contractId < _nextContractId, "Update for nonexistent contract: This contract ID does not exist.");
_metadataURIs[contractId] = _newMetadataURI;
}

/**
* @notice Destroys the contract instance associated with the given contract ID.
* @dev Can only be called by the contract owner. Removes the contract instance and its metadata URI from the mappings.
* @param contractId The ID of the contract instance to destroy.
*/
function destroyContractInstance(uint256 contractId) external onlyOwner {
require(contractId < _nextContractId, "Destruction of nonexistent contract: This contract ID does not exist.");
delete _contractInstances[contractId];
delete _metadataURIs[contractId];
}

/**
* @notice Creates a new contract instance directly with associated metadata.
* @dev Directly deploys a new contract instance and assigns it a unique contract ID.
* @param _metadata The metadata associated with the new contract instance.
* @return contractId The ID assigned to the newly created contract instance.
*/
function createInstance(bytes calldata _metadata) external returns (uint256 contractId) {
ERC721Example newContract = new ERC721Example(); // Assuming ERC721Example's constructor does not require parameters
ERC721Example newContract = new ERC721Example();
address newContractAddress = address(newContract);

contractId = _nextContractId++;
_contractInstances[contractId] = newContractAddress;
_metadataURIs[contractId] = string(_metadata);

emit ContractInstanceCreated(newContractAddress, contractId);
}
}
```


## Security Considerations

Securing the implementation of ERC-321 is crucial, focusing on managing contract ownership and metadata integrity. Adhering to smart contract security best practices and opting for decentralized storage solutions for metadata are essential to mitigate risks.

Check failure on line 106 in ERCS/erc-321

View workflow job for this annotation

GitHub Actions / EIP Walidator

the first match of the given pattern must be a link

error[markdown-link-first]: the first match of the given pattern must be a link --> ERCS/erc-321 | 106 | Securing the implementation of ERC-321 is crucial, focusing on managing contract ownership and metadata integrity. Adhering to smart contract security best practices and opting for decentralized storage solutions for metadata are essential to mitigate risks. | = info: the pattern in question: `(?i)(?:eip|erc)-[0-9]+`

Check failure on line 106 in ERCS/erc-321

View workflow job for this annotation

GitHub Actions / EIP Walidator

the first match of the given pattern must be a link

error[markdown-link-first]: the first match of the given pattern must be a link --> ERCS/erc-321 | 106 | Securing the implementation of ERC-321 is crucial, focusing on managing contract ownership and metadata integrity. Adhering to smart contract security best practices and opting for decentralized storage solutions for metadata are essential to mitigate risks. | = info: the pattern in question: `(?i)(?:eip|erc)-[0-9]+`


## Copyright

Copyright and related rights waived via CC0.
```

Please ensure that all links and references are correct and that the code snippets are accurate and compile without errors.

0 comments on commit e7ef36f

Please sign in to comment.