Id smart contracts for CyberConnect ecosystem. The repo consists of 2 top-level and core smart contracts:
CyberId
- the contract that manages the.cyber
handle of a userRealmId
- the contract that manages the.moca
handle of a user
TODO
The RealmId
contract issues RealmId
for the realmverse network.
A RealmId
is a non-transferable ERC-721 token that represents a unique name like @alice. The mint rule is decided by programmable middleware. After minting, users can set/get arbitrary metadata to/from the token to provide a flexible and transparent mechanism for storing and managing associated information.
registerable
- the name can be minted by anyoneregistered
- the name is registered to an address
stateDiagram
direction LR
registerable --> registered: register
registered --> registerable: burn
The RealmId
state transitions when users take certain actions:
register
- mint a newRealmId
burn
- burn an owningRealmId
The contract follows the UUPSUpgradable design pattern. After deploying, there will be proxy
and implementation
contracts deployed. Users only need to interact with the proxy
contract. The contract owner can upgrade the contract by calling these methods to proxy
contract:
upgradeTo
- Upgrade the implementation of the proxy to a new implementation.upgradeToAndCall
- Upgrade the implementation of the proxy to a new implementation, and subsequently execute the function call encoded in data.
Each RealmId
has a metadata map attached to it. The metadata map can be set with arbitrary keys and values. The data type of keys and values are string
. Users or approved operators can
batchSetMetadatas
- overwrites metadata kv pairsclearMetadatas
- clears all metadata kv pairs without knowing keysgetMetadata
- gets a single metadata kv pair
When a RealmId
moves from registered
to registerable
, clearMetadatas
is performed for users.
The contract follows a middleware architecture to create more design space for customized logic. Middlewares are plug-and-play custom execution logic code that runs before and after register
. Developers can customize several rules:
- The
RealmId
pattern (e.g. Only allow 0-9 and lower cases) - Charge (e.g. Free or requires erc20 tokens based on
RealmId
length) - Permission (e.g. Only Signer or anyone can
register
) - …
The contract defines one owner address that has permission to operate:
setMiddleware
- overwrites middleware of the contractupgradeTo
- Upgrade the implementation of the proxy to a new implementation.upgradeToAndCall
- Upgrade the implementation of the proxy to a new implementation, and subsequently execute the function call encoded in data.setBaseTokenUri
- overwrites base token URI of the contract
-
Upgrade your foundry
foundryup
-
To enable husky pre-commit
yarn && yarn prepare
-
To install contract dependencies
forge install
-
To build
forge build
-
To test
forge test -vvv
-
(optional) To run static analysis
slither .
We use Create2Deployer to ensure proxy contracts are deployed deterministically. Take Deploying RealmId
on Polygon testnet(mumbai) as an example, the deployment process is:
-
Step 1-3 is one-time work. Go to step 4 if you have done it once.
-
Prepare a brand new EOA for deployment because the nonce of the EOA will influence the deployer address. The nonce should be 0 across chains.
-
Prepare
.env.mumbai
at the repo root directory. TheETHERSCAN_API_KEY
for mumbai can be obtained from here.RPC_URL=<mumbai RPC> PRIVATE_KEY=<your deployer EOA private key> ETHERSCAN_API_KEY=<your polygon testnet scan API key>
-
Deploy
Create2Deployer
and collect its addressyarn deploy_deployer:mumbai
-
Update the
deployerContract
in theMUMBAI
block in DeploySetting.sol -
Deploy
RealmId
yarn deploy_realmid:mumbai
Finally, you can write your yarn entry points in [package.json] to customize and repeat your deployment process.