Moving ENS names to ENSv2
ENSv2 replaces the contracts ENS names have lived in for years. Every existing .eth name has to move across, and only its owner can move it. I worked on the feature that does that in the ENS Manager: the Upgrade button. This is what I learned building it.
Every name is already reserved
The first thing I had to understand was that the upgrade doesn't create anything. Before anyone presses Upgrade, ENS reserves every active .eth name in ENSv2. A reservation has no owner yet, and it falls back to ENSv1, so a name keeps resolving whether or not it upgrades. Upgrading means claiming that reservation by giving up the ENSv1 token.
Expiry was the first edge case I hit. The reservation runs 62 days past the ENSv1 expiry, and both grace periods end on the same day:
ENSv1 lease: Registered
ENSv2 reservation: Reserved
A name in grace can't be transferred, so I made the Manager renew it first and then upgrade it.
One kind of name, one receiver
You upgrade a name by sending its token to an ENSv2 migration contract. That contract does the migration as it receives the token, or rejects it, and then nothing moves at all.
ENSv1 names come in a few kinds: plain .eth names, wrapped ones, and locked ones whose permissions can never be loosened. Each kind has exactly one contract that will accept it, so the Manager has to work out the kind before it sends anything. I came to like this design: a wrong guess fails instead of half-migrating a name.
- From: BaseRegistrar
- Accepted by: UnlockedMigrationController
- Ends up in: ETHRegistry
- The old token goes to the Graveyard, a contract that never gives it back.
- The name is registered to you in ENSv2, keeping its reserved expiry.
Locked names took the most care. Their fuses become ENSv2 roles, so anything the owner promised in ENSv1, like never changing the resolver, still holds afterwards. I had the Manager check those roles after every upgrade rather than trust that they landed.
Subnames come along, or hold you back
Subnames were the hardest part, because they can belong to anyone. Locked subnames move themselves once their parent has. Simpler ones are copied into a new registry for the parent, still owned by whoever owned them. Anything the Manager can't carry blocks the parent: I'd rather refuse an upgrade than strand someone's live subname.
- alice.ethheld backUnwrapped · yours
- pay.alice.ethwill be copiedRegistry subname · owned by bob
- blog.alice.ethwill be copiedWrapped, no fuses · yours
- old.blog.alice.ethblocks the parentRegistry subname · too deep to copy
One transaction for everything
I didn't want a half-finished upgrade if one step failed. So the Manager gives each wallet a small smart account and sends every upgrade through it as a single transaction: a batch of names either all move or none do. Here is one name inside that transaction:
6 stepsOne name upgrading inside the transaction. Play it, step through, or pick a step.
The same transaction also copies the name's records into its new resolver, so addresses and profile text don't go missing along the way.
Checking the result
The rule I leaned on most: a sent transaction isn't proof that the right thing happened. After each batch, the Manager reads the new state at that exact block and checks it: owner, resolver, expiry, roles and every record.
People close tabs, so I planned for that too. Before opening the wallet, the Manager saves which batch it is sending. When you come back, it looks that transaction up on-chain and picks up from what actually landed, not from what it hoped would.