---
eip: 6224
label: ERC-6224
title: Contracts Dependencies Registry
status: Last Call
type: Standards Track
category: ERC
created: 2022-12-27
requires: 1967, 5750
official: https://eips.ethereum.org/EIPS/eip-6224
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-6224.md
canonical: https://eips.huatuo.xyz/ko/eip-6224/
lang: ko
tldr: 표준 ContractsRegistry와 Dependant 믹스인을 통해, 프로토콜이 의존성 주입으로 자신의 컨트랙트를 등록, 업그레이드, 연결할 수 있는 온체인의 단일 장소를 제공한다.
tags: [registry, upgradeability, proxy, dependency-injection, architecture]
---

# ERC-6224: Contracts Dependencies Registry

> A registry for managing smart contracts with their dependencies.

**TL;DR:** 표준 ContractsRegistry와 Dependant 믹스인을 통해, 프로토콜이 의존성 주입으로 자신의 컨트랙트를 등록, 업그레이드, 연결할 수 있는 온체인의 단일 장소를 제공한다.

## 어떤 문제를 해결하나요?

실제 프로토콜은 서로를 가리키는 많은 컨트랙트로 이루어집니다. 볼트는 오라클이 필요하고, 오라클은 가격 피드가 필요하고, 이런 식입니다. 팀은 보통 이 주소들을 생성자나 초기화 함수에 하드코딩하고, 컨트랙트 하나가 교체되거나 업그레이드될 때 고생합니다. 그것에 의존하는 모든 컨트랙트를 손으로 업데이트해야 하기 때문입니다.

ERC-6224는 표준 아키텍처를 제안합니다. 프로토콜의 모든 컨트랙트를 아는 하나의 **ContractsRegistry**(선택적으로 이들을 위한 업그레이드 가능 프록시를 배포)와, 레지스트리가 필요할 때 각 컨트랙트에 의존성을 밀어 넣을 수 있게 하는 **Dependant** 기반 컨트랙트입니다.

## 어떻게 동작하나요?

**ContractsRegistry**(`IContractsRegistry`):

- 컨트랙트는 사람이 읽을 수 있는 `string` 이름으로 식별됩니다.
- `addContract(name, addr)`는 업그레이드할 수 없는 일반 컨트랙트를 등록합니다.
- `addProxyContract(name, impl)` / `addProxyContractAndCall(name, impl, data)`는 구현 위에 프록시를 배포하므로, 레지스트리가 나중에 `upgradeContract` / `upgradeContractAndCall`로 업그레이드할 수 있습니다.
- `justAddProxyContract(name, proxy)`는 기존 프록시를 넘겨받습니다(예: 새 레지스트리로 마이그레이션할 때. 이 경우 새 레지스트리가 업그레이드 권한을 가져야 합니다).
- `getContract(name)`는 등록된 것이 없으면 revert하고, `hasContract(name)`는 존재 여부를 확인하며, `removeContract(name)`는 삭제합니다.
- `address(0)`을 등록하면 revert해야 합니다.
- `injectDependencies(name)` / `injectDependenciesWithData(name, data)`는 해당 이름의 컨트랙트에 `setDependencies(address(this), data)`를 호출합니다.

**Dependant**(`IDependant`):

- 프로토콜의 모든 독립 컨트랙트가 이를 상속하며, 의존성을 생성자나 초기화 함수가 아니라 **`setDependencies` 안에서** 읽습니다.
- 현재 **injector**만 `setDependencies`와 `setInjector`를 호출할 수 있습니다. injector는 처음에는 0이므로 첫 호출은 허용되며, 레퍼런스 구현은 그 호출자를 injector로 기록합니다.
- injector 주소는 [ERC-1967](/eip-1967/) 방식의 스토리지 슬롯인 `bytes32(uint256(keccak256("eip6224.dependant.slot")) - 1)` 슬롯에 둘 수 있습니다.

추가 `bytes data` 인자는 확장 가능한 메서드 동작을 위한 [ERC-5750](/eip-5750/) 패턴을 따릅니다.

## 샘플 코드

레지스트리에서 두 개의 의존성을 가져오는 dependant 컨트랙트:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IContractsRegistry {
    function getContract(string memory name) external view returns (address);
}

/// `Dependant` as in the ERC's reference implementation (stores the injector,
/// exposes the `dependant` modifier that checks and then records msg.sender).
import {Dependant} from "./Dependant.sol";

contract Vault is Dependant {
    address public oracle;
    address public treasury;

    function setDependencies(address registry, bytes memory) public override dependant {
        IContractsRegistry r = IContractsRegistry(registry);
        oracle = r.getContract("ORACLE");
        treasury = r.getContract("TREASURY");
    }
}
```

배포 흐름(의사 코드):

```text
registry.addContract("ORACLE", oracleAddr)
registry.addProxyContract("TREASURY", treasuryImpl)
registry.addProxyContract("VAULT", vaultImpl)
registry.injectDependencies("VAULT")       // Vault reads ORACLE and TREASURY
// later: swap the oracle and re-inject
registry.addContract("ORACLE", newOracle)
registry.injectDependencies("VAULT")
```

## 알아둘 점

- 상태는 **Last Call**입니다. final에 가깝지만 세부 사항은 아직 바뀔 수 있습니다.
- 레지스트리 소유자가 모든 업그레이드를 제어합니다. 그 키를 잃거나 유출하면 프로토콜 전체가 위험해지므로 멀티시그나 거버넌스를 사용하세요.
- 레지스트리는 구현 간 호환성 검사를 하지 않습니다. 업그레이드 시 스토리지 레이아웃의 안전성은 여러분의 책임입니다.
- injector가 처음에는 0이므로 첫 `setDependencies` 호출은 프론트러닝될 수 있습니다. 배포 직후, 가능하면 같은 트랜잭션에서 의존성을 주입하세요.
- 이벤트는 필터링 편의성 대신 가독성을 택해 일부러 인덱싱되지 않은 `string` 이름을 사용합니다.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-6224
