Created
December 4, 2021 01:27
-
-
Save samkingco/13bfea37d65a065f9c8bccd80db89a70 to your computer and use it in GitHub Desktop.
CozyCoMembership
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //SPDX-License-Identifier: Unlicense | |
| /// @title: cozy co. membership | |
| /// @author: The Stitcher AKA samking.eth | |
| /* | |
| :-.:- .-:.=: -==. :- .=== .==: :-::- .--.-: | |
| *@%..=@--%@+ %@# .#%%@@#-+.-@@# #@@- +@@: -@*:%@# *@%. | |
| %@@: :.-@@% .@@@ ....:-: %@@: -@@# +@@= ::.@@@. %@@: | |
| %@@- -@@+ #@@--=*%#*++*.-@@%.:%@@: *@@+ ..@@# +@@=-%@* | |
| =*#*=: .+=.=+- ==..=*#+: .**+--@@+ -***=- .=+.-+- .**= | |
| +@%. .@@= | |
| :=..-: | |
| */ | |
| pragma solidity ^0.8.4; | |
| import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; | |
| import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol"; | |
| import "@openzeppelin/contracts/access/Ownable.sol"; | |
| import "./IMembershipTokenMetadata.sol"; | |
| contract CozyCoMembership is Ownable, ERC1155Burnable { | |
| mapping(uint256 => address) private _membershipMetadata; | |
| uint256[] private _membershipTypes; | |
| function uri(uint256 id) | |
| public | |
| view | |
| virtual | |
| override | |
| returns (string memory) | |
| { | |
| require( | |
| _membershipMetadata[id] != address(0), | |
| "CozyCoMembership: no metadata" | |
| ); | |
| return IMembershipTokenMetadata(_membershipMetadata[id]).getURI(id); | |
| } | |
| function issueMembership(address to, uint256 token) | |
| public | |
| virtual | |
| onlyOwner | |
| { | |
| require( | |
| _membershipMetadata[token] != address(0), | |
| "CozyCoMembership: no metadata" | |
| ); | |
| require(balanceOf(to, token) == 0, "Already has token"); | |
| _mint(to, token, 1, ""); | |
| } | |
| function issueMemberships(address[] memory _members, uint256 token) | |
| public | |
| virtual | |
| onlyOwner | |
| { | |
| for (uint256 i = 0; i < _members.length; i++) { | |
| issueMembership(_members[i], token); | |
| } | |
| } | |
| function issueCustomMembership( | |
| address to, | |
| uint256 token, | |
| address metadata | |
| ) public virtual onlyOwner { | |
| require( | |
| _membershipMetadata[token] == address(0), | |
| "CozyCoMembership: tokenId in use" | |
| ); | |
| require(balanceOf(to, token) == 0, "Already has token"); | |
| _membershipMetadata[token] = metadata; | |
| _mint(to, token, 1, ""); | |
| } | |
| function revokeMembership( | |
| address _address, | |
| uint256[] memory ids, | |
| uint256[] memory amounts | |
| ) public virtual onlyOwner { | |
| _burnBatch(_address, ids, amounts); | |
| } | |
| function addMembershipMetadataAddress( | |
| uint256 membershipId, | |
| address _address | |
| ) public onlyOwner { | |
| require( | |
| _membershipMetadata[membershipId] == address(0), | |
| "CozyCoMembership: tokenId in use" | |
| ); | |
| _membershipMetadata[membershipId] = _address; | |
| _membershipTypes.push(membershipId); | |
| } | |
| function updateMembershipMetadataAddress( | |
| uint256 membershipId, | |
| address _address | |
| ) public onlyOwner { | |
| _membershipMetadata[membershipId] = _address; | |
| } | |
| function getMembershipTypes() | |
| public | |
| view | |
| returns (uint256[] memory membershipTypes) | |
| { | |
| return _membershipTypes; | |
| } | |
| function getMembershipMetadataAddress(uint256 membershipId) | |
| public | |
| view | |
| returns (address) | |
| { | |
| return _membershipMetadata[membershipId]; | |
| } | |
| function supportsInterface(bytes4 interfaceId) | |
| public | |
| view | |
| virtual | |
| override(ERC1155) | |
| returns (bool) | |
| { | |
| return super.supportsInterface(interfaceId); | |
| } | |
| constructor() ERC1155("") {} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //SPDX-License-Identifier: Unlicense | |
| /// @title: Friends of cozy co. metadata | |
| /// @author: The Stitcher AKA samking.eth | |
| /* | |
| :-.:- .-:.=: -==. :- .=== .==: :-::- .--.-: | |
| *@%..=@--%@+ %@# .#%%@@#-+.-@@# #@@- +@@: -@*:%@# *@%. | |
| %@@: :.-@@% .@@@ ....:-: %@@: -@@# +@@= ::.@@@. %@@: | |
| %@@- -@@+ #@@--=*%#*++*.-@@%.:%@@: *@@+ ..@@# +@@=-%@* | |
| =*#*=: .+=.=+- ==..=*#+: .**+--@@+ -***=- .=+.-+- .**= | |
| +@%. .@@= | |
| :=..-: | |
| */ | |
| pragma solidity ^0.8.4; | |
| import "@openzeppelin/contracts/access/Ownable.sol"; | |
| import "./Base64.sol"; | |
| import "./IMembershipTokenMetadata.sol"; | |
| contract FriendsOfCozyCoMetadata is Ownable, IMembershipTokenMetadata { | |
| string public name; | |
| string public description; | |
| string public imageURI; | |
| constructor( | |
| string memory _name, | |
| string memory _desc, | |
| string memory _imageURI | |
| ) Ownable() { | |
| name = _name; | |
| description = _desc; | |
| imageURI = _imageURI; | |
| } | |
| function getURI(uint256) public view override returns (string memory) { | |
| string memory json = Base64.encode( | |
| bytes( | |
| string( | |
| abi.encodePacked( | |
| '{"name": "', | |
| name, | |
| '", "description": "', | |
| description, | |
| '", "image": "', | |
| imageURI, | |
| '", "attributes": [{ "trait_type": "Membership", "value": "', | |
| name, | |
| '" }]}' | |
| ) | |
| ) | |
| ) | |
| ); | |
| return string(abi.encodePacked("data:application/json;base64,", json)); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: MIT | |
| pragma solidity ^0.8.4; | |
| interface IMembershipTokenMetadata { | |
| function getURI(uint256 id) external view returns (string memory); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment