Skip to content

Commit

Permalink
Add short and long description to space owner metadata (#276)
Browse files Browse the repository at this point in the history
Proposals:

**Update Space Factory with upgraded Architect Facet for Space Owner
Metadata changes**
- https://testnets.llama.xyz/orgs/river/base-sepolia/actions/150

**Upgrade SpaceOwner Facet on Space Owner Diamond**
- https://testnets.llama.xyz/orgs/river/base-sepolia/actions/151

**Add Space Owner Diamond Proxy to Governance**
- Mainnet: https://app.llama.xyz/orgs/river/base/actions/75
- Testnet:
https://testnets.llama.xyz/orgs/river/base-sepolia/actions/149

---------

Co-authored-by: Tak Wai Wong <[email protected]>
  • Loading branch information
giuseppecrj and tak-hntlabs authored Jul 8, 2024
1 parent 50cd0a3 commit 2d59dda
Show file tree
Hide file tree
Showing 38 changed files with 634 additions and 162 deletions.
20 changes: 4 additions & 16 deletions contracts/scripts/deployments/DeploySpaceOwner.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {IDiamond, Diamond} from "contracts/src/diamond/Diamond.sol";
import {DiamondDeployer} from "../common/DiamondDeployer.s.sol";

// facets
import {SpaceOwner} from "contracts/src/spaces/facets/owner/SpaceOwner.sol";
import {GuardianFacet} from "contracts/src/spaces/facets/guardian/GuardianFacet.sol";

// helpers
Expand All @@ -19,29 +18,21 @@ import {DeployDiamondCut} from "contracts/scripts/deployments/facets/DeployDiamo
import {DeployDiamondLoupe} from "contracts/scripts/deployments/facets/DeployDiamondLoupe.s.sol";
import {DeployIntrospection} from "contracts/scripts/deployments/facets/DeployIntrospection.s.sol";
import {DeployMetadata} from "contracts/scripts/deployments/facets/DeployMetadata.s.sol";
import {DeploySpaceOwnerFacet} from "contracts/scripts/deployments/facets/DeploySpaceOwnerFacet.s.sol";
import {DeployMultiInit, MultiInit} from "contracts/scripts/deployments/DeployMultiInit.s.sol";

import {GuardianHelper} from "contracts/test/spaces/guardian/GuardianSetup.sol";
import {SpaceOwnerHelper} from "contracts/test/spaces/owner/SpaceOwnerHelper.sol";
import {IntrospectionHelper} from "contracts/test/diamond/introspection/IntrospectionSetup.sol";
import {ERC721AHelper} from "contracts/test/diamond/erc721a/ERC721ASetup.sol";
import {VotesHelper} from "contracts/test/governance/votes/VotesSetup.sol";

import {MultiInit} from "contracts/src/diamond/initializers/MultiInit.sol";

import {DeployMultiInit} from "contracts/scripts/deployments/DeployMultiInit.s.sol";

contract DeploySpaceOwner is DiamondDeployer {
DeployDiamondCut diamondCutHelper = new DeployDiamondCut();
DeployDiamondLoupe diamondLoupeHelper = new DeployDiamondLoupe();
DeployOwnable ownableHelper = new DeployOwnable();
DeployIntrospection introspectionHelper = new DeployIntrospection();
DeploySpaceOwnerFacet spaceOwnerHelper = new DeploySpaceOwnerFacet();
DeployMetadata metadataHelper = new DeployMetadata();
DeployMultiInit multiInitHelper = new DeployMultiInit();

GuardianHelper guardianHelper = new GuardianHelper();
ERC721AHelper erc721aHelper = new ERC721AHelper();
VotesHelper votesHelper = new VotesHelper();
SpaceOwnerHelper spaceOwnerHelper = new SpaceOwnerHelper();

function versionName() public pure override returns (string memory) {
return "spaceOwner";
Expand All @@ -55,16 +46,13 @@ contract DeploySpaceOwner is DiamondDeployer {
address introspection = introspectionHelper.deploy();
address ownable = ownableHelper.deploy();
address metadata = metadataHelper.deploy();
address spaceOwner = spaceOwnerHelper.deploy();
address multiInit = multiInitHelper.deploy();

vm.startBroadcast(deployer);
address spaceOwner = address(new SpaceOwner());
address guardian = address(new GuardianFacet());
vm.stopBroadcast();

spaceOwnerHelper.addSelectors(erc721aHelper.selectors());
spaceOwnerHelper.addSelectors(votesHelper.selectors());

addFacet(
diamondCutHelper.makeCut(diamondCut, IDiamond.FacetCutAction.Add),
diamondCut,
Expand Down
53 changes: 53 additions & 0 deletions contracts/scripts/deployments/facets/DeploySpaceOwnerFacet.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

//interfaces

//libraries

//contracts
import {Deployer} from "contracts/scripts/common/Deployer.s.sol";
import {FacetHelper} from "contracts/test/diamond/Facet.t.sol";

import {SpaceOwner} from "contracts/src/spaces/facets/owner/SpaceOwner.sol";
import {ERC721AHelper} from "contracts/test/diamond/erc721a/ERC721ASetup.sol";
import {VotesHelper} from "contracts/test/governance/votes/VotesSetup.sol";

contract DeploySpaceOwnerFacet is FacetHelper, Deployer {
ERC721AHelper erc721aHelper = new ERC721AHelper();
VotesHelper votesHelper = new VotesHelper();

constructor() {
addSelector(SpaceOwner.setFactory.selector);
addSelector(SpaceOwner.getFactory.selector);
addSelector(SpaceOwner.nextTokenId.selector);
addSelector(SpaceOwner.mintSpace.selector);
addSelector(SpaceOwner.getSpaceInfo.selector);
addSelector(SpaceOwner.updateSpaceInfo.selector);
addSelectors(erc721aHelper.selectors());
addSelectors(votesHelper.selectors());
}

function initializer() public pure override returns (bytes4) {
return SpaceOwner.__SpaceOwner_init.selector;
}

function makeInitData(
string memory name,
string memory symbol,
string memory version
) public pure returns (bytes memory) {
return abi.encodeWithSelector(initializer(), name, symbol, version);
}

function versionName() public pure override returns (string memory) {
return "spaceOwnerFacet";
}

function __deploy(address deployer) public override returns (address) {
vm.startBroadcast(deployer);
SpaceOwner facet = new SpaceOwner();
vm.stopBroadcast();
return address(facet);
}
}
8 changes: 7 additions & 1 deletion contracts/src/factory/facets/architect/ArchitectBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ abstract contract ArchitectBase is Factory, IArchitectBase {
ds.tokenIdBySpace[spaceAddress] = spaceTokenId;

// mint token to and transfer to Architect
ims.spaceToken.mintSpace(spaceInfo.name, spaceInfo.uri, spaceAddress);
ims.spaceToken.mintSpace(
spaceInfo.name,
spaceInfo.uri,
spaceAddress,
spaceInfo.shortDescription,
spaceInfo.longDescription
);

// deploy user entitlement
IUserEntitlement userEntitlement = IUserEntitlement(
Expand Down
2 changes: 2 additions & 0 deletions contracts/src/factory/facets/architect/IArchitect.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ interface IArchitectBase {
string uri;
Membership membership;
ChannelInfo channel;
string shortDescription;
string longDescription;
}

// =============================================================
Expand Down
14 changes: 12 additions & 2 deletions contracts/src/spaces/facets/owner/ISpaceOwner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface ISpaceOwnerBase {
string uri;
uint256 tokenId;
uint256 createdAt;
string shortDescription;
string longDescription;
}

error SpaceOwner__OnlyFactoryAllowed();
Expand All @@ -36,11 +38,15 @@ interface ISpaceOwner is ISpaceOwnerBase {
/// @param name The name of the space
/// @param uri The URI of the space
/// @param space The address of the space
/// @param shortDescription The short description of the space
/// @param longDescription The long description of the space
/// @return tokenId The token id of the minted space
function mintSpace(
string memory name,
string memory uri,
address space
address space,
string memory shortDescription,
string memory longDescription
) external returns (uint256 tokenId);

/// @notice Get the space info
Expand All @@ -53,9 +59,13 @@ interface ISpaceOwner is ISpaceOwnerBase {
/// @param space The address of the space
/// @param name The name of the space
/// @param uri The URI of the space
/// @param shortDescription The short description of the space
/// @param longDescription The long description of the space
function updateSpaceInfo(
address space,
string memory name,
string memory uri
string memory uri,
string memory shortDescription,
string memory longDescription
) external;
}
12 changes: 8 additions & 4 deletions contracts/src/spaces/facets/owner/SpaceOwner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ contract SpaceOwner is
function mintSpace(
string memory name,
string memory uri,
address space
address space,
string memory shortDescription,
string memory longDescription
) external onlyFactory returns (uint256 tokenId) {
tokenId = _nextTokenId();
_mintSpace(name, uri, tokenId, space);
_mintSpace(name, uri, tokenId, space, shortDescription, longDescription);
_mint(msg.sender, 1);
}

Expand All @@ -76,10 +78,12 @@ contract SpaceOwner is
function updateSpaceInfo(
address space,
string memory name,
string memory uri
string memory uri,
string memory shortDescription,
string memory longDescription
) external {
_onlySpaceOwner(space);
_updateSpace(space, name, uri);
_updateSpace(space, name, uri, shortDescription, longDescription);
}

function nonces(address owner) external view returns (uint256 result) {
Expand Down
39 changes: 33 additions & 6 deletions contracts/src/spaces/facets/owner/SpaceOwnerBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ abstract contract SpaceOwnerBase is ISpaceOwnerBase {
string memory name,
string memory uri,
uint256 tokenId,
address space
address space,
string memory shortDescription,
string memory longDescription
) internal {
Validator.checkLength(name, 2);
Validator.checkLength(uri, 0);
Expand All @@ -52,33 +54,58 @@ abstract contract SpaceOwnerBase is ISpaceOwnerBase {
SpaceOwnerStorage.Layout storage ds = SpaceOwnerStorage.layout();

ds.spaceByTokenId[tokenId] = space;
ds.spaceByAddress[space] = Space({
ds.spaceByAddress[space] = SpaceOwnerStorage.Space({
name: name,
uri: uri,
tokenId: tokenId,
createdAt: block.timestamp
});
ds.spaceMetadata[space] = SpaceOwnerStorage.SpaceMetadata({
shortDescription: shortDescription,
longDescription: longDescription
});
}

function _updateSpace(
address space,
string memory name,
string memory uri
string memory uri,
string memory shortDescription,
string memory longDescription
) internal {
Validator.checkLength(name, 2);
Validator.checkLength(uri, 1);

SpaceOwnerStorage.Layout storage ds = SpaceOwnerStorage.layout();

Space storage spaceInfo = ds.spaceByAddress[space];
SpaceOwnerStorage.Space storage spaceInfo = ds.spaceByAddress[space];
spaceInfo.name = name;
spaceInfo.uri = uri;

SpaceOwnerStorage.SpaceMetadata storage metadata = ds.spaceMetadata[space];
metadata.shortDescription = shortDescription;
metadata.longDescription = longDescription;

emit SpaceOwner__UpdateSpace(space);
}

function _getSpace(address space) internal view returns (Space memory) {
SpaceOwnerStorage.Layout storage ds = SpaceOwnerStorage.layout();
return ds.spaceByAddress[space];
SpaceOwnerStorage.Space storage spaceInfo = SpaceOwnerStorage
.layout()
.spaceByAddress[space];

SpaceOwnerStorage.SpaceMetadata storage metadata = SpaceOwnerStorage
.layout()
.spaceMetadata[space];

return
Space({
name: spaceInfo.name,
uri: spaceInfo.uri,
tokenId: spaceInfo.tokenId,
createdAt: spaceInfo.createdAt,
shortDescription: metadata.shortDescription,
longDescription: metadata.longDescription
});
}
}
16 changes: 14 additions & 2 deletions contracts/src/spaces/facets/owner/SpaceOwnerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.23;

// interfaces
import {ISpaceOwnerBase} from "./ISpaceOwner.sol";

// libraries

Expand All @@ -13,10 +12,23 @@ library SpaceOwnerStorage {
bytes32 internal constant STORAGE_SLOT =
0x7fc24c9500f4388b797f8975c0991ad4ffd0338c2cbf5335b2bf5b7fe5747700;

struct Space {
string name;
string uri;
uint256 tokenId;
uint256 createdAt;
}

struct SpaceMetadata {
string shortDescription;
string longDescription;
}

struct Layout {
address factory;
mapping(uint256 => address) spaceByTokenId;
mapping(address => ISpaceOwnerBase.Space) spaceByAddress;
mapping(address => Space) spaceByAddress;
mapping(address => SpaceMetadata) spaceMetadata;
}

function layout() internal pure returns (Layout storage l) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/spaces/facets/owner/SpaceOwnerUriBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract contract SpaceOwnerUriBase is ISpaceOwnerBase {

if (spaceAddress == address(0)) return "";

Space memory space = ds.spaceByAddress[spaceAddress];
SpaceOwnerStorage.Space memory space = ds.spaceByAddress[spaceAddress];

return
string(
Expand Down
Loading

0 comments on commit 2d59dda

Please sign in to comment.