Ethereum Name Service 백서

Ethereum Name Service

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 14쪽

owner); } ``` Internally, the contract replaces the standard ERC1155 nested balance mapping (`id → address → balance`) with a flat `id → address` ownership mapping. The [Permissioned Registry](/ensv2/permissioned-registry) overrides `ownerOf` to add expiry and version validation on top of raw ownership, returning `address(0)` for expired names or stale token IDs. Unlike the standard ERC1155 which has a `_uri` storage variable, ERC1155Singleton makes `uri()` abstract with no built-in storage. The [Permissioned Registry](/ensv2/permissioned-registry) overrides it with a two-mode implementation: a static URI string, or delegation to an [`IRegistryURIRenderer`](/ensv2/permissioned-registry#token-metadata) contract for dynamic per-token metadata. The contract emits all standard ERC1155 events (`TransferSingle`, `TransferBatch`, `ApprovalForAll`, `URI`). import { FrenCallout } from '../../components/ensv2/FrenCallout' import { ContractReference } from '../../components/ensv2/ContractReference' import { Card } from '../../components/ui/Card' ## ETH Registrar The ETH Registrar manages the registration and renewal of `.eth` names in ENSv2. It retains the proven [commit-reveal pattern from ENSv1](/registry/eth#registering-a-name) while adding multi-year registration discounts, ERC20 payment support, and integration with the [Permissioned Registry](/ensv2/permissioned-registry). ### What Changed from ENSv1 | Feature | ENSv1 | ENSv2 | | -------------- | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | | Grace period | 90-day grace period after expiry | **28-day grace period** | | Payment | ETH only | ERC20 tokens via `safeTransferFrom` | | Pricing | USD-denominated, no duration discounts | USD-denominated, multi-year duration discounts | | Name ownership | ERC721 on BaseRegistrar (optionally wrapped to ERC1155 via [NameWrapper](/wrapper/overview)) | [ERC1155Singleton](/ensv2/erc1155-singleton) token on Permissioned Registry | | Permissions | Owner has full control; no granular roles | Registrant receives a fixed set of [EAC](/ensv2/enhanced-access-control) roles | ### Pricing #### Base Rate Names are priced annually by character count: | Name Length | Annual Price | | ------------- | ------------ | | 3 characters | $640/yr | | 4 characters | $160/yr | | 5+ characters | $8/yr | #### Multi-Year Discounts Longer registrations (and renewals) receive a discount applied to the entire duration. The discount is determined by the total term in a single transaction: | Term | Discount | 5+ char /yr | 5+ char total | 4-char /yr | 4-char total | 3-char /yr | 3-char total | | ---- | -------- | ----------- | ------------- | ---------- | ------------ | ---------- | ------------ | | 1 yr | 0% | $8.00 | $8.00 | $160 | $160 | $640 | $640 | | 2 yr | 12.5% | $7.00 | $14.00 | $140 | $280 | $560 | $1,120 | | 3 yr | \~31% | $5.50 | $16.50 | $110 | $330 | $440 | $1,320 | | 4 yr | \~31% | $5.50 | $22.00 | $110 | $440 | $440 | $1,760 | | 5 yr | \~31% | $5.50 | $27.50 | $110 | $550 | $440 | $2,200 | | 6 yr | \~44% | $4.50 | $27.00 | $90 | $540 | $360 | $2,160 | Because the discount rate increases at six years, the total cost for six years is lower than for five. For example, renewing a 5+ character name for one year always costs $8 regardless of the existing expiration; renewing the same name for six years costs $27 ($4.50/yr). Pricing parameters (base rates and discount tiers) are immutable per oracle deployment. Changing them requires deploying a new oracle and calling `setRentPriceOracle()`. #### Expiry Premium After the 28-day grace period, recently-expired names enter a 21-day temporary premium period to prevent sniping. The premium starts at \~$100M and decays exponentially (halving every day), reaching zero at the end of the window. <Card> <div className="mx-auto h-40"> <svg className="h-full w-full" viewBox="0 0 200 100" preserveAspectRatio="xMidYMid meet"> <text x="100" y="10" textAnchor="middle" fontSize="6" fill="currentColor" opacity="0.5">Premium (USD)</text> <text x="100" y="98" textAnchor="middle" fontSize="6" fill="currentColor" opacity="0.5">Days after grace period ends</text> <text x="18" y="22" textAnchor="end" fontSize="5" fill="currentColor" opacity="0.4">$100M</text> <text x="18" y="82" textAnchor="end" fontSize="5" fill="currentColor" opacity="0.4">$0</text> <text x="20" y="92" textAnchor="start" fontSize="5" fill="currentColor" opacity="0.4">0</text> <text x="180" y="92" textAnchor="end" fontSize="5" fill="currentColor" opacity="0.4">21</text> <line x1="20" y1="15" x2="20" y2="82" stroke="currentColor" opacity="0.2" strokeWidth="0.5" /> <line x1="20" y1="82" x2="180" y2="82" stroke="currentColor" opacity="0.2" strokeWidth="0.5" /> <path d="M 20 18 Q 22 78 180 80" stroke="#3889FF" fill="transparent" strokeWidth="1.5" /> </svg> </div> </Card> #### Querying Prices Both the registrar and the oracle expose `getRegisterPrice` and `getRenewPrice`, but they serve different purposes: * **Registrar** (stateful): `getRegisterPrice(label, duration, paymentToken)` returns the actual cost for a specific name right now. It reads registry state to determine how long the name has been available, then forwards to the oracle. Reverts if the name is not available or the duration is below the minimum. * **Oracle** (stateless): `getRegisterPrice(label, available, duration, paymentToken)` takes a fully parameterized `available` duration and returns what the price would be for any hypothetical scenario. It has no knowledge of registry state or minimums. <FrenCallout fren="bittu"> Use the registrar's version when you need the true price for a specific name (e.g., before calling `register()`). Use the oracle directly when you need hypothetical pricing (e.g., a pricing calculator or "what would this cost?" UI). </FrenCallout> ### Multi-Token Payments Unlike ENSv1 which only accepted ETH, the ENSv2 registrar supports payment in multiple ERC20 tokens. The `StandardRentPriceOracle` maintains exchange rate ratios for each accepted token. Check accepted tokens via `isPaymentToken(token)` on the `StandardRentPriceOracle`. Payment is collected via `safeTransferFrom` to an immutable beneficiary address. The caller must approve the registrar for the payment token before calling `register()` or `renew()`. ### Registering a Name Like [ENSv1](/registry/eth#registering-a-name), the ETH Registrar uses a commit-reveal scheme to prevent front-running registrations. You first call `commit` with an opaque commitment hash, wait at least `MIN_COMMITMENT_AGE` (60 seconds), then call `register` to reveal the parameters and complete registration. #### Commit-Reveal Generate a commitment hash using `makeCommitment`: ```solidity ETHRegistrar.makeCommitment( label string, // "alice" for alice.eth (label only, not full name) owner address, // The address that will own the name secret bytes32, // A randomly generated 32-byte secret subregistry IRegistry, // Child registry to set (or address(0) for none) resolver address, // Resolver contract to set duration uint64, // Registration duration in seconds referrer bytes32 // Referral identifier (or bytes32(0)) ) // For example makeCommitment( "alice", 0x1234..., 0xabcd..., // Random secret, generate off-chain address(0), // No subregistry 0x5678..., // Resolver address 31536000, // 1 year in seconds bytes32(0) // No referrer ); ``` Once you have calculated the commitment hash, submit it on-chain: ```solidity ETHRegistrar.commit(commitment bytes32) ``` After committing, wait at least `MIN_COMMITMENT_AGE` (60 seconds) before calling `register`. The commitment expires after `MAX_COMMITMENT_AGE` (typically 24 hours). #### Registering Before initiating registration, ensure that: * `isAvailable(label)` returns `true` * `duration` >= `MIN_REGISTER_DURATION` * The commitment is between `MIN_COMMITMENT_AGE` and `MAX_COMMITMENT_AGE` old * The payment token is approved for `base + premium` (query via `getRegisterPrice`) ```solidity ETHRegistrar.register( label string, // Same label used in makeCommitment owner address, // Same owner used in makeCommitment secret bytes32, // Same secret used in makeCommitment subregistry IRegistry, // Same subregistry used in makeCommitment resolver address, // Same resolver used in makeCommitment duration uint64, // Same duration used in makeCommitment paymentToken IERC20, // ERC20 token to pay with (must be approved) referrer bytes32 // Same referrer used in makeCommitment ) returns (uint256 tokenId) // For example register( "alice", 0x1234..., 0xabcd..., // Same secret as in commit step address(0), 0x5678..., 31536000, 0x9abc..., // USDC token address bytes32(0) ); ``` ##### Roles Granted at Registration The registration grants the owner a fixed set of roles defined by `REGISTRATION_ROLE_BITMAP`: * `ROLE_SET_SUBREGISTRY`: change the name's child registry * `ROLE_SET_SUBREGISTRY_ADMIN`: delegate `ROLE_SET_SUBREGISTRY` to others * `ROLE_SET_RESOLVER`: change the name's resolver * `ROLE_SET_RESOLVER_ADMIN`: delegate `ROLE_SET_RESOLVER` to others * `ROLE_CAN_TRANSFER_ADMIN`: controls whether the token owner can transfer the name (admin-only; there is no non-admin `ROLE_CAN_TRANSFER`) Unlike ENSv1, the role set is not configurable per registration; it is hardcoded in the registrar. See [Enhanced Access Control](/ensv2/enhanced-access-control) for details on the role system. ### Renewing a Name Any account can renew any name, not just the owner. Renewal extends the expiry without changing ownership or permissions. Only the base rate is charged (no premium). ```solidity struct RenewData { string label; // The label to renew uint64 duration; // Duration to extend by (in seconds) bytes32 referrer; // Referral identifier } ETHRegistrar.renew( rd RenewData, // The renewal data paymentToken IERC20 // ERC20 token to pay with (must be approved) ) ``` #### Batch Renewals Multiple names can be renewed in a single transaction via `renewBatch(RenewData[] rds, IERC20 paymentToken)`. Every renewal in the batch is paid with the same payment token. ### BatchRegistrar The **BatchRegistrar** is a companion contract used during migration from ENSv1. It has a single owner-only function, `batchRegister(registry, resolver, labels, expires)`: * `AVAILABLE` names: registered as `RESERVED` (no owner, no payment) * `RESERVED` names where the target expiry exceeds the current expiry: extended via `ETH_REGISTRY.renew()` directly (no payment, absolute timestamp) * `REGISTERED` names: silently skipped This contract is intended for pre-migration use, not for general public registration. ### EAC Integration #### Registrar Governance The ETH Registrar uses OpenZeppelin `Ownable` for its own governance. The owner can call `setRentPriceOracle()` to replace the pricing oracle. Ownership is transferable via `transferOwnership()`. #### Roles on the ETH Registry To register and renew names, the ETH Registrar needs roles on the `.eth` [Permissioned Registry](/ensv2/permissioned-registry). At deployment it is granted two [registry roles](/ensv2/permissioned-registry#roles) on `ROOT_RESOURCE`: | Role | Purpose | | ------------------------------------------------------ | ------------------------------------------------------ | | [`ROLE_REGISTRAR`](/ensv2/permissioned-registry#roles) | Allows calling `register()` to create new `.eth` names | | [`ROLE_RENEW`](/ensv2/permissioned-registry#roles) | Allows calling `renew()` on any `.eth` name | Because these are granted at `ROOT_RESOURCE`, they apply to all names (the EAC [checks both root and token-level roles](/ensv2/enhanced-access-control#roles)). The registrar does not hold admin variants of these roles, so it cannot delegate its own authority to other contracts. ### Code Examples #### Full Registration Flow ```ts [Viem] import { createPublicClient, createWalletClient, erc20Abi, http, keccak256, toHex, } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http() }) const wallet = createWalletClient({ chain: mainnet, transport: http() }) const label = 'alice' const owner = '0x...' // Your address const duration = 31536000n // 1 year in seconds const secret = keccak256(toHex(crypto.randomUUID())) // Random secret const resolver = '0x...' // Resolver address const subregistry = '0x0000000000000000000000000000000000000000' const paymentToken = '0x...' // ERC20 token address const referrer = '0x0000000000000000000000000000000000000000000000000000000000000000' // 1. Check availability const available = await client.readContract({ address: ethRegistrarAddress, abi: ethRegistrarAbi, functionName: 'isAvailable', args: [label], }) if (!available) throw new Error('Name not available') // 2. Get the price const [base, premium] = await client.readContract({ address: ethRegistrarAddress, abi: ethRegistrarAbi, functionName: 'getRegisterPrice', args: [label, duration, paymentToken], }) // 3. Approve the registrar to spend the payment token const totalCost = base + premium await wallet.writeContract({ address: paymentToken, abi: erc20Abi, functionName: 'approve', args: [ethRegistrarAddress, totalCost], }) // 4. Create and submit commitment const commitment = await client.readContract({ address: ethRegistrarAddress, abi: ethRegistrarAbi, functionName: 'makeCommitment', args: [label, owner, secret, subregistry, resolver, duration, referrer], }) await wallet.writeContract({ address: ethRegistrarAddress, abi: ethRegistrarAbi, functionName: 'commit', args: [commitment], }) // 5. Wait at least MIN_COMMITMENT_AGE (e.g., 60 seconds) // ... wait ... // 6. Register await wallet.writeContract({ address: ethRegistrarAddress, abi: ethRegistrarAbi, functionName: 'register', args: [ label, owner, secret, subregistry, resolver, duration, paymentToken, referrer, ], }) ``` #### Renewing a Name ```ts [Viem] const renewPrice = await client.readContract({ address: ethRegistrarAddress, abi: ethRegistrarAbi, functionName: 'getRenewPrice', args: [label, duration, paymentToken], }) // Approve the registrar to spend the payment token await wallet.writeContract({ address: paymentToken, abi: erc20Abi, functionName: 'approve', args: [ethRegistrarAddress, renewPrice], }) await wallet.writeContract({ address: ethRegistrarAddress, abi: ethRegistrarAbi, functionName: 'renew', args: [{ label, duration, referrer }, paymentToken], }) ``` ### Reference #### Write Functions <ContractReference functions={[ { name: 'commit', description: 'Record a commitment hash on-chain.', params: [ { name: 'commitment', type: 'bytes32', description: 'The commitment hash from makeCommitment' }, ], }, { name: 'register', description: 'Register a name (consumes a prior commitment).', params: [ { name: 'label', type: 'string', description: 'The label to register (e.g. "alice")' }, { name: 'owner', type: 'address', description: 'Address that will own the name' }, { name: 'secret', type: 'bytes32', description: 'Secret used in the commitment' }, { name: 'subregistry', type: 'IRegistry', description: 'Child registry to set, or address(0)' }, { name: 'resolver', type: 'address', description: 'Resolver to set' }, { name: 'duration', type: 'uint64', description: 'Registration duration in seconds' }, { name: 'paymentToken', type: 'IERC20', description: 'ERC20 token to pay with' }, { name: 'referrer', type: 'bytes32', description: 'Referral identifier, or bytes32(0)' }, ], returns: [ { name: 'tokenId', type: 'uint256', description: 'Token ID of the registered name' }, ], }, { name: 'renew', description: "Extend a name's expiry. Any account can renew any name.", params: [ { name: 'rd', type: 'RenewData', description: 'Renewal data: (label, duration, referrer)' }, { name: 'paymentToken', type: 'IERC20', description: 'ERC20 token to pay with' }, ], }, { name: 'renewBatch', description: 'Renew multiple names in one transaction, paid with a single token.', params: [ { name: 'rds', type: 'RenewData[]', description: 'Renewal data per name: (label, duration, referrer)' }, { name: 'paymentToken', type: 'IERC20', description: 'ERC20 token to pay with' }, ], }, { name: 'setRentPriceOracle', description: 'Change the pricing oracle. Callable by the contract owner only.', params: [ { name: 'oracle', type: 'IRentPriceOracle', description: 'New pricing oracle' }, ], }, ]} /> #### View Functions <ContractReference functions={[ { name: 'makeCommitment', description: 'Compute a commitment hash for the given parameters (pure, no state read).', params: [ { name: 'label', type: 'string', description: 'The label to register' }, { name: 'owner', type: 'address', description: 'Address that will own the name' }, { name: 'secret', type: 'bytes32', description: 'Random secret for front-running protection' }, { name: 'subregistry', type: 'IRegistry', description: 'Child registry to set, or address(0)' }, { name: 'resolver', type: 'address', description: 'Resolver to set' }, { name: 'duration', type: 'uint64', description: 'Registration duration in seconds' }, { name: 'referrer', type: 'bytes32', description: 'Referral identifier' }, ], returns: [ { name: 'commitment', type: 'bytes32', description: 'Commitment hash' }, ], }, { name: 'getRegisterPrice', description: 'Get the registration price for a name.', params: [ { name: 'label', type: 'string', description: 'The label to price' }, { name: 'duration', type: 'uint64', description: 'Duration in seconds' }, { name: 'paymentToken', type: 'IERC20', description: 'Token to price in' }, ], returns: [ { name: 'base', type: 'uint256', description: 'Base price' }, { name: 'premium', type: 'uint256', description: 'Premium for recently expired names' }, ], }, { name: 'isAvailable', description: 'Check whether a name can be registered.', params: [ { name: 'label', type: 'string', description: 'The label to check' }, ], returns: [ { name: 'available', type: 'bool', description: 'True if the name can be registered' }, ], }, { name: 'commitmentAt', description: 'Get the timestamp when a commitment was recorded.', params: [ { name: 'commitment', type: 'bytes32', description: 'The commitment hash' }, ], returns: [ { name: 'commitTime', type: 'uint64', description: 'Timestamp, or 0 if not found' }, ], }, { name: 'getRenewPrice', description: 'Get the renewal price for a name (base rate only, no premium). Reverts NameNotRenewable if the name is not currently renewable.', params: [ { name: 'label', type: 'string', description: 'The label to price' }, { name: 'duration', type: 'uint64', description: 'Duration in seconds' }, { name: 'paymentToken', type: 'IERC20', description: 'Token to price in' }, ], returns: [ { name: 'amount', type: 'uint256', description: 'Amount of payment token required' }, ], }, { name: 'isRenewable', description: 'Check whether a name can be renewed (registered or within grace period).', params: [ { name: 'label', type: 'string', description: 'The label to check' }, ], returns: [ { name: 'renewable', type: 'bool', description: 'True if the name can be renewed' }, ], }, { name: 'getRemainingGracePeriod', description: 'Get the remaining grace period for an expired name.', params: [ { name: 'label', type: 'string', description: 'The label to check' }, ], returns: [ { name: 'remaining', type: 'uint64', description: 'Seconds remaining in the grace period, or 0' }, ], }, ]} /> #### Constants <ContractReference functions={[ { name: 'ETH_REGISTRY', description: 'The Permissioned Registry this registrar writes to.', }, { name: 'BENEFICIARY', description: 'Address that receives all registration and renewal payments.', }, { name: 'MIN_COMMITMENT_AGE', description: 'Minimum seconds before a commit
프로젝트로 돌아가기