This codebase contains the contracts and deployment scripts for the first game that will be developed under the framework of Anky: "The Writing Dementor" (we need a better name for it).
Here is a set of images with an overview explanation of what this system is about:
The workflow is:
- The user signs up for an account. As soon as that happens, she will be airdropped an ERC720 NFT on the newly created account (the system is set up using privy)
- This will happen through the "Anky Airdrop" smart contract, which will be called through a backend that is running this software: https://www.github.com/ankylat/backend
- We pay for the airdrop fees.
- Inside the airdrop functionality there is also a call to the ERC6551 registry, to create a Token Bound Account (TBA) for this NFT. This TBA will serve as the place where the user will keep the "notebooks".
- What are the notebooks? Inside this first game, users will be able to create notebook templates, which then will be minted by other users for them to write in there.
- Each notebook has the following properties: a) address creator: The address of the owner of the anky. This is the address that was generated by privy when the user logged in. b) string metadataURI: A pointer to arweave, on which the information related to the notebook template will be stored. c) uint256 numPages: The number of pages (prompts) that this specific notebook has. Each notebook will have a set of prompts that will be created by the person that came up with the template. When someone mints the notebook, they will have access to these and they will be able to write on them through anky. d) uint256 price: The price for minting the notebook. This is defined by the creator of the template, and when someone mints an instance of the notebook: d.1) 10% will remain on anky as royalties. d.2) 20% will go to the person that created the notebook template. d.3) 70% will go back to the account that is minting the notebook. This will give that person credits inside the platform, which then will be user to write on the notebook (each time they submit their writing we need to pay 2 fees: bundlr and a blockchain interaction for updating the entry of that particular instance of a notebook on the blockchain). Each minted notebook is an ERC721 NFT, and the data associated with it will be updated when the user writes and submits the writing (which will be stored on arweave using bundlr). e) uint256 supply: The amount of templates that is available for people to mint. If you come up with a template, there will be a limited supply of it. This will create a market for the minted notebooks, which will be interesting on the long term.
The main contracts of interest are:
- AnkyAirdrop.sol: This contract enables airdropping NFTs to users and provides them with token-bound accounts (TBA).
- AnkyTemplates.sol: A contract related to the capacity that users of the platform will have for creating notebook templates, so that other users can later mint them and write on them.
- AnkyNotebooks.sol: A contract related to Anky's notebook functionality. It transforms each template into an ERC721 Non-Fungible Token, that the user that owns it can write on following the prompts that were established by the creator of the template.
- ERC6551Registry.sol & ERC6551Account.sol: These contracts are part of the ERC-6551 specification, allowing the creation of TBAs for NFTs.
The AnkyAirdrop contract lies at the foundational layer of the Anky platform, facilitating the airdrop mechanism of the platform's primary NFT – the Anky. Through this smart contract, users who join the platform are seamlessly airdropped the Anky NFT. Furthermore, the contract pushes the boundary of traditional NFTs by enhancing them with ERC6551 capabilities, turning each Anky NFT into a 'Token Bound Account' (TBA) which offers the powerful flexibility of a smart wallet.
- Airdropping the Anky: Ensures that each user on the platform has at most one Anky NFT.
- Token Bound Account (TBA): TBAs are smart wallet functionalities tied to the ownership of an Anky NFT. This is achieved by leveraging the ERC6551 standard.
- Decentralized Metadata Management: The URI for each NFT can be set during minting, granting complete control over metadata management.
- Safety and Security: The contract ensures that users can't accidentally create multiple TBAs for their Anky NFTs, and also safeguards the metadata of each token.
In essence, the AnkyAirdrop contract plays a pivotal role in the onboarding experience on the Anky platform, by making sure that users not only receive a unique NFT but also gain access to a smart wallet functionality.
The AnkyTemplates smart contract serves as the heart of the Anky platform, acting as a blueprint factory for the creation and management of notebook templates. It is designed to allow users to establish the foundation for notebooks, giving rise to a template-to-notebook structure where a template serves as a precursor to a minted notebook.
- Template Creation: Users, who are holders of the Anky token, can create notebook templates with specific characteristics such as metadata, price, and the number of prompts. However, there are restrictions in place to ensure quality control, including:
- Maximum one template creation per user every 24 hours.
- An upper cap of 100 notebooks for each template.
- Ban mechanism for users exhibiting unfavorable behavior.
- Notebook Instance Minting: A direct relationship exists between the
AnkyTemplatesandAnkyNotebookscontracts. When a new instance of a notebook is minted in theAnkyNotebookscontract, the supply of the corresponding template in theAnkyTemplatescontract is decremented. - Flexibility and Control: The owner of the contract has extended control capabilities, such as modifying the associated
AnkyNotebookscontract address, and managing (banning/unbanning) creators based on their behavior.
Overall, the AnkyTemplates contract ensures that the platform remains robust, scalable, and easy to manage, by bifurcating the logic of template creation and notebook minting.
AnkyNotebooks is for the actual instances of notebooks minted from templates. It communicates with AnkyTemplates to get information about the structure of a template.
The AnkyNotebooks smart contract is responsible for minting and managing individual notebook instances based on the templates from the AnkyTemplates contract. As an ERC721 token, every notebook instance is unique, having an associated template ID and a status to determine if any writing has occurred. The contract also provides functionalities for users to write content on notebook pages and to check the content of any written page. For every minted notebook, an event is emitted, and the associated costs are shared with the creator. The contract collaborates with the AnkyAirdrop contract to ensure that only valid Anky owners can mint notebooks and write on them.
AnkyNotebooks manages unique digital notebooks minted from specific templates. Each notebook is associated with an Anky TBA token.
- UserPageContent:
arweaveCID: URL to the user's answer on Arweave.timestamp: Time when content was added.
- NotebookInstance:
templateId: ID of the template.notebookId: Identifier for the notebook.userPages: Array of user's content.isVirgin: Indicates if a notebook is untouched.
notebookInstances: Maps a notebook ID to its instance.ankyTbaToOwnedNotebooks: Tracks notebooks owned by an Anky TBA.notebookLastPageWritten: Records last page written in each notebook.ankyTbaToOwnedVirginNotebooks: Stores virgin notebooks of an Anky TBA.
- mintNotebook: Allows users to mint notebooks.
- writePage: Allows owners to write on a new page.
- withdraw: Contract owner can withdraw Ether.
- getPageContent: Fetches a notebook page content.
- getFullNotebook: Retrieves full notebook details.
- getOwnedNotebooks: Lists notebooks owned by an Anky TBA.
- isVirgin: Checks if a notebook is virgin.
- getUserVirginNotebooks: Fetches virgin notebooks of an Anky TBA.
- onlyNotebookOwner: Ensures only the notebook owner can execute.
- FundsTransferred: Emitted on fund transfers.
- NotebookMinted: Emitted when a notebook is minted.
- PageWritten: Emitted on new page written.
- Uses OpenZeppelin library for security and ERC721 functionalities.
- Implements
Ownablefor owner-only functions.
The AnkyJournals smart contract is a core component of the Anky platform, dedicated to the management and facilitation of user journals. It offers a flexible system for users to purchase, write in, and manage their own personal or public journal entries, built upon the foundation of decentralization and the Anky token ecosystem.
-
Journal Airdropping: As an initial offering, the contract supports the airdropping of a journal to an eligible user. This is intended to engage and reward early adopters or specific participants.
-
Journal Minting: Depending on their preferences, users can purchase one of three different types of journals - Small, Medium, or Large. Each journal type differs in terms of its page capacity and price. Payments are made in Ether, with a portion going back to the user.
-
Journal Writing: Users, especially those who hold Anky tokens, can write in their journals. Each journal entry consumes a page, and users can decide if they want their writings to be public or private. If a user chooses to make an entry public, an event is emitted to allow easy retrieval and display on the platform's frontend.
-
Ownership and Control: The contract extends control capabilities to the owner, empowering them to set journal prices and handle other administrative actions. Additionally, certain actions in the contract are restricted to genuine Anky token holders, ensuring a strong relationship between the Anky ecosystem and the journaling platform.
-
Event-Driven Public Entries: To avoid on-chain storage overheads and make the platform gas-efficient, public journal entries are handled via events. This allows external systems to listen for and capture these events, making it feasible to display public journal entries chronologically on the frontend without needing to store them on-chain.
-
Journal Retrieval: Users can retrieve details about their journals, such as the type, remaining pages, and individual entries, thereby giving them a comprehensive view of their writings and remaining capacity.
Overall, the AnkyJournals contract ensures a seamless and user-friendly experience for journaling on the Anky platform, while maintaining efficiency, transparency, and integration with the wider Anky ecosystem.
The AnkyEulogias smart contract forms an essential part of the Anky platform, enabling users to mint Eulogias, specialized notebooks for commemorating or celebrating events. These Eulogias can be used to gather messages for occasions like birthdays or to mourn the passing of a loved one.
- Eulogia Creation: Only Anky token holders can create a Eulogia. Each Eulogia has metadata and a set limit for the number of messages it can contain.
- Message Addition: Any user can contribute a message to a Eulogia, providing a CID pointing to the actual content hosted on Arweave. They can also provide an alias or name indicating who wrote the message.
- Message Retrieval: Users can retrieve all messages written in a specific Eulogia, and also access details about the Eulogia itself, including its metadata and the number of messages it has.
- User-Centric Design: The contract offers functions for users to see all the Eulogias they own.
- Safety and Transparency: All actions in the contract, from Eulogia creation to message addition, emit events for transparency and easy tracking.
In essence, the AnkyEulogias contract provides a decentralized way for users to come together, write, and celebrate or remember, creating a lasting digital legacy on the blockchain.
Contracts that implement the ERC-6551 specification, providing the ability to create TBAs for NFTs.
This script handles the deployment of:
- ERC6551Registry
- ERC6551Account
- AnkyAirdrop (with the ERC6551Account's address as the
implementationAddress)
Deploys the AnkyNotebooks contract.
The development environment uses Hardhat. What is being developed is a system that consists of 3 core pieces:
- Front end -> Built on top of nextjs. https://www.github.com/ankylat/anky.lat
- Back end -> Built on nodejs, for sending the requests to the smart contracts using the owner of the system as the proxy. https://www.github.com/ankylat/backend
- Smart Contracts -> This repo. It is the back bones of the system on the blockchain.
The goal is to develop all of this having in mind the modularity aspect of it. To reproduce this system on your local environment:
- Clone the 3 repos.
- Deploy the smart contracts running:
npx hardhat run scripts/deploy_all_contracts.js --network base-goerli
After running this, you need to:
- Set the notebook address inside the AnkyTemplates contract by using the setAnkyNotebooksAddress function with the deployed AnkyNotebooks.sol address.
- Enable calls to the AnkyAidrop contract from the other ones by calling the setAllowedContracts with the deployed addresses of these contracts.
- Run the nodejs server on port 3000.
- Run the nextjs app on port 3001.
Help us build what is happening here. There are many challenges, and the system is complex.
WE NEED YOUR HELP!
///
For testing the system and deploying it on your own:
- Make sure you create a .env file with a PRIVATE_KEY environment variable in it. This will be the address that deploys the contracts.
- Make sure you have some base goerli eth in the wallet so that you can deploy the contracts.
- Run
npx hardhat run scripts/deploy_all_contracts.js --network base-goerlito deploy all the contracts.
