There are two needs for the accounts system of Citadef.
opening accounts must be very cheap. I can't imagine people opening blog accounts if it costs more than a few cents.
The account owners should manage Citadef like a DAO at some point in the future. This means, among others, that the owner of the accounts will manage the ENS name citadef.eth. That's why we call citadef a Decentralized Autonomous Platform.
Alas, those two needs contradict! For accounts to be cheap to open they must be on L2 (Polygon in Citadef), but ENS names are on Mainnet.
How can account owners on Polygon manage an ENS name on Mainnet? That's what I try to solve here.
High-level overview
There are three components of the system:
A smart contract on mainnet, CitadefDotETH_SC. This smart contract is the registrant and controller of citadef.eth ENS name.
A smart contract on Polygon, DAO_SC, that represents the Citadef DAO.
Basically, DAO_SC needs to tell CitadefDotETH_SC which actions to perform on the ENS name. The commands are given within the form of the third component:
- An ERC721 token, ENSActions_Token.
How does it work?
The tokens are minted on Polygon by DAO_SC.
Each token has metadata with an action to perform on the ENS name citadef.eth.
The tokens are bridged to Mainnet with Polygon bridge.
CitadefDotETH_SC reads the actions from the metadata of the tokens and executes them
Finally, CitadefDotETH_SC burns the token so that the same action won't be executed twice.
The ERC721 token ENSActions_Token
ENSActions_Token is used for communication between the two smart contracts. The token design affects how the smart contracts are built, so we begin by describing the token.
The tokens rules:
- Tokens can only be minted by DAO_SC.
- Tokens can only be burned by CitadefDotETH_SC.
Both the addresses of DAO_SC and CitadefDotETH_SC are set in the constructor of the contract for ENSActions_Token and can never be changed.
Each token has a "TokenURI" (that's how the ERC721 standard calls it) or a "TokenMetadata" field (that's how it's called in Polygon Bridge template code for ERC721 tokens).
The TokenMetadata is of type bytes, and can be set during minting.
How do we use this token? when DAO_SC mints an ENSActions_Token token, it will set the TokenMetadata to be some function (with parameters) of the ENS resolver. Then CitadefDotETH_SC will use this TokenMetadata to do the action on citadef.eth.
DAO_SC
The DAO_SC is on Polygon and is controlled by Citadef account holders.
The important function of DAO_SC for us is to mint ENSActions_Token tokens with TokenMetadata.
There should be an internal DAO process to approve which actions to perform on citadef.eth ENS name. Once an action is decided the DAO mints a token with the appropriate TokenMetadata, and bridges it to Mainnet.
CitadefDotETH_SC
The CitadefDotETH_SC contract is the registrant and controller of citadef.eth ENS name.
CitadefDotETH_SC has a function "ENSAction(tokenID)". Anyone can call this function.
This function does the following:
- Verifies there's an ENSActions_Token with ID tokenID.
- Verifies this token belongs to DAO_SC on mainnet.
- If this is true, CitadefDotETH_SC performs the action specified in the TokenMetadata of tokenID.
- Finally, CitadefDotETH_SC burns the token.