Skip to content

Commit

Permalink
Adds several utilities to catalog and catalog factory.
Browse files Browse the repository at this point in the history
  • Loading branch information
steven2308 committed Mar 1, 2024
1 parent 1717da0 commit 9b215cc
Show file tree
Hide file tree
Showing 9 changed files with 682 additions and 17 deletions.
7 changes: 3 additions & 4 deletions contracts/RMRK/catalog/RMRKCatalog.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ contract RMRKCatalog is IRMRKCatalog {
*/
mapping(uint64 => bool) private _isEquippableToAll;

uint64[] private _partIds;

string private _metadataURI;
string private _type;
uint64[] internal _partIds;
string internal _metadataURI;
string internal _type;

/**
* @notice Used to initialize the Catalog.
Expand Down
80 changes: 80 additions & 0 deletions contracts/implementations/RMRKCatalogFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.21;

import {RMRKCatalogImpl} from "./RMRKCatalogImpl.sol";

/**
* @title RMRKCatalogFactory
* @author RMRK team
* @notice Smart contract to deploy catalog implementations and keep track of deployers.
*/
contract RMRKCatalogFactory {
mapping(address deployer => address[] catalogs) private _deployerCatalogs;

event CatalogDeployed(address indexed deployer, address indexed catalog);

/**
* @notice Used to deploy a new RMRKCatalog implementation.
* @param metadataURI Base metadata URI of the catalog
* @param type_ The type of the catalog
* @return The address of the deployed catalog
*/
function deployCatalog(
string memory metadataURI,
string memory type_
) public returns (address) {
RMRKCatalogImpl catalog = new RMRKCatalogImpl(metadataURI, type_);
_deployerCatalogs[msg.sender].push(address(catalog));
emit CatalogDeployed(msg.sender, address(catalog));
return address(catalog);
}

/**
* @notice Used to get all catalogs deployed by a given deployer.
* @param deployer The address of the deployer
* @return An array of addresses of the catalogs deployed by the deployer
*/
function getDeployerCatalogs(
address deployer
) public view returns (address[] memory) {
return _deployerCatalogs[deployer];
}

/**
* @notice Used to get the total number of catalogs deployed by a given deployer.
* @param deployer The address of the deployer
* @return total The total number of catalogs deployed by the deployer
*/
function getTotalDeployerCatalogs(
address deployer
) public view returns (uint256 total) {
total = _deployerCatalogs[deployer].length;
}

/**
* @notice Used to get a catalog deployed by a given deployer at a given index.
* @param deployer The address of the deployer
* @param index The index of the catalog
* @return catalogAddress The address of the catalog
*/
function getDeployerCatalogAtIndex(
address deployer,
uint256 index
) public view returns (address catalogAddress) {
catalogAddress = _deployerCatalogs[deployer][index];
}

/**
* @notice Used to get the last catalog deployed by a given deployer.
* @param deployer The address of the deployer
* @return catalogAddress The address of the last catalog deployed by the deployer
*/
function getLastDeployerCatalog(
address deployer
) public view returns (address catalogAddress) {
catalogAddress = _deployerCatalogs[deployer][
_deployerCatalogs[deployer].length - 1
];
}
}
75 changes: 75 additions & 0 deletions contracts/implementations/RMRKCatalogImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ import {RMRKCatalog} from "../RMRK/catalog/RMRKCatalog.sol";
* catalog contract.
*/
contract RMRKCatalogImpl is OwnableLock, RMRKCatalog {
/**
* @notice From ERC7572 (Draft) Emitted when the contract-level metadata is updated
*/
event ContractURIUpdated();

/**
* @notice Emited when the type of the catalog is updated
* @param newType The new type of the catalog
*/
event TypeUpdated(string newType);

/**
* @notice Used to initialize the smart contract.
* @param metadataURI Base metadata URI of the contract
Expand Down Expand Up @@ -121,4 +132,68 @@ contract RMRKCatalogImpl is OwnableLock, RMRKCatalog {
) public virtual onlyOwnerOrContributor {
_resetEquippableAddresses(partId);
}

/**
* @notice Used to get all the part IDs in the catalog.
* @dev Can get at least 10k parts. Higher limits were not tested.
* @dev It may fail if there are too many parts, in that case use either `getPaginatedPartIds` or `getTotalParts` and `getPartByIndex`.
* @return partIds An array of all the part IDs in the catalog
*/
function getAllPartIds() public view returns (uint64[] memory partIds) {
partIds = _partIds;
}

/**
* @notice Used to get all the part IDs in the catalog.
* @param offset The offset to start from
* @param limit The maximum number of parts to return
* @return partIds An array of all the part IDs in the catalog
*/
function getPaginatedPartIds(
uint256 offset,
uint256 limit
) public view returns (uint64[] memory partIds) {
if (offset >= _partIds.length) limit = 0; // Could revert but UI would have to handle it
if (offset + limit > _partIds.length) limit = _partIds.length - offset;
partIds = new uint64[](limit);
for (uint256 i; i < limit; ) {
partIds[i] = _partIds[offset + i];
unchecked {
++i;
}
}
}

/**
* @notice Used to get the total number of parts in the catalog.
* @return totalParts The total number of parts in the catalog
*/
function getTotalParts() public view returns (uint256 totalParts) {
totalParts = _partIds.length;
}

/**
* @notice Used to get a single `Part` by the index of its `partId`.
* @param index The index of the `partId`.
* @return part The `Part` struct associated with the `partId` at the given index
*/
function getPartByIndex(
uint256 index
) public view returns (Part memory part) {
part = getPart(_partIds[index]);
}

function setMetadataURI(
string memory newContractURI
) public virtual onlyOwnerOrContributor {
_setMetadataURI(newContractURI);
emit ContractURIUpdated();
}

function setType(
string memory newType
) public virtual onlyOwnerOrContributor {
_setType(newType);
emit TypeUpdated(newType);
}
}
12 changes: 12 additions & 0 deletions docs/console.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# console











147 changes: 147 additions & 0 deletions docs/implementations/RMRKCatalogFactory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# RMRKCatalogFactory

*RMRK team*

> RMRKCatalogFactory
Smart contract to deploy catalog implementations and keep track of deployers.



## Methods

### deployCatalog

```solidity
function deployCatalog(string metadataURI, string type_) external nonpayable returns (address)
```

Used to deploy a new RMRKCatalog implementation.



#### Parameters

| Name | Type | Description |
|---|---|---|
| metadataURI | string | Base metadata URI of the catalog |
| type_ | string | The type of the catalog |

#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | address | The address of the deployed catalog |

### getDeployerCatalogAtIndex

```solidity
function getDeployerCatalogAtIndex(address deployer, uint256 index) external view returns (address catalogAddress)
```

Used to get a catalog deployed by a given deployer at a given index.



#### Parameters

| Name | Type | Description |
|---|---|---|
| deployer | address | The address of the deployer |
| index | uint256 | The index of the catalog |

#### Returns

| Name | Type | Description |
|---|---|---|
| catalogAddress | address | The address of the catalog |

### getDeployerCatalogs

```solidity
function getDeployerCatalogs(address deployer) external view returns (address[])
```

Used to get all catalogs deployed by a given deployer.



#### Parameters

| Name | Type | Description |
|---|---|---|
| deployer | address | The address of the deployer |

#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | address[] | An array of addresses of the catalogs deployed by the deployer |

### getLastDeployerCatalog

```solidity
function getLastDeployerCatalog(address deployer) external view returns (address catalogAddress)
```

Used to get the last catalog deployed by a given deployer.



#### Parameters

| Name | Type | Description |
|---|---|---|
| deployer | address | The address of the deployer |

#### Returns

| Name | Type | Description |
|---|---|---|
| catalogAddress | address | The address of the last catalog deployed by the deployer |

### getTotalDeployerCatalogs

```solidity
function getTotalDeployerCatalogs(address deployer) external view returns (uint256 total)
```

Used to get the total number of catalogs deployed by a given deployer.



#### Parameters

| Name | Type | Description |
|---|---|---|
| deployer | address | The address of the deployer |

#### Returns

| Name | Type | Description |
|---|---|---|
| total | uint256 | The total number of catalogs deployed by the deployer |



## Events

### CatalogDeployed

```solidity
event CatalogDeployed(address indexed deployer, address indexed catalog)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| deployer `indexed` | address | undefined |
| catalog `indexed` | address | undefined |



Loading

0 comments on commit 9b215cc

Please sign in to comment.