# ComplianceServiceDataStore.sol

> ComplianceServiceDataStoreは、DSプロトコルのComplianceService（コンプライアンスサービス）コントラクトが使用する変数を一元的に定義しているコントラクトです。

- URL: https://cardene.dev/books/blackrock-buidl/1dd419
- 本: BlackRock BUIDL (https://cardene.dev/books/blackrock-buidl.md)
- 章: 18 / 24
- 前の章: https://cardene.dev/books/blackrock-buidl/61d62f.md
- 次の章: https://cardene.dev/books/blackrock-buidl/9fbcf7.md
- 公開日: 2025-07-12
- 更新日: 2025-07-12
- トピック: Blockchain
- タグ: ブロックチェーン, solidity, ethereum, smartcontract

## 概要

**ComplianceServiceDataStore**は、DSプロトコルの**ComplianceService**（コンプライアンスサービス）コントラクトが使用する変数を一元的に定義しているコントラクトです。
主に、規制遵守のために追跡が必要な各種「**投資家カウンター**」と、特定のロックアップルールを適用するための発行履歴データを保持します。

例えば、新しい投資家がトークンを取得すると、**ComplianceServiceRegulated**コントラクト内の`totalInvestors`カウンターや、国籍に応じた`usInvestorsCount`などのカウンターが加算されます。
また、`issuances...`というマッピング群は、Reg S（米国外投資家向けルール）などで要求される、発行ごとのロックアップ期間を計算するために、どの投資家がいつ、どれだけの量のトークンを発行されたかを記録するために使用されます。

## 機能

* **投資家カウンターの保管**
    * 総投資家数、適格投資家数、国・地域別（米国、日本、EU）の投資家数など、規制遵守のために必要なカウンターを保持します。
* **発行履歴の保管**
    * 投資家ごとの発行回数、発行量、発行日時を記録し、特定のコンプライアンスルール（例：ロックアップ期間）を適用するためのデータ基盤を提供します。
 
## コード

```sol
pragma solidity ^0.8.13;

import "./ServiceConsumerDataStore.sol";

//SPDX-License-Identifier: UNLICENSED
contract ComplianceServiceDataStore is ServiceConsumerDataStore {
    uint256 internal totalInvestors;
    uint256 internal accreditedInvestorsCount;
    uint256 internal usAccreditedInvestorsCount;
    uint256 internal usInvestorsCount;
    uint256 internal jpInvestorsCount;
    mapping(string => uint256) internal euRetailInvestorsCount;
    mapping(string => uint256) internal issuancesCounters;
    mapping(string => mapping(uint256 => uint256)) issuancesValues;
    mapping(string => mapping(uint256 => uint256)) issuancesTimestamps;
}
```

## 変数

### `totalInvestors`

```sol
uint256 internal totalInvestors;
```

このトークンを保有している総投資家（ユニークな投資家IDの数）の総数を格納するカウンター。

### `accreditedInvestorsCount`

```sol
uint256 internal accreditedInvestorsCount;
```

総投資家のうち、「**Accredited Investor（適格投資家）**」として分類される投資家の総数を格納するカウンター。
米国の証券法などで定義される、一定の資産や収入を持つ投資家を指します。

### `usAccreditedInvestorsCount`

```sol
uint256 internal usAccreditedInvestorsCount;
```

米国の「**Accredited Investor（適格投資家）**」の総数を格納するカウンター。

### `usInvestorsCount`

```sol
uint256 internal usInvestorsCount;
```

国籍が米国である投資家の総数を格納するカウンター。

### `jpInvestorsCount`

```sol
uint256 internal jpInvestorsCount;
```

国籍が日本である投資家の総数を格納するカウンター。

### `euRetailInvestorsCount`

```sol
mapping(string => uint256) internal euRetailInvestorsCount;
```

EU（欧州連合）内の国ごとのリテール投資家（非適格投資家）の数を格納するマッピング。

- **キー (`string`)**
    - EU加盟国の国コード（例："DE"、"FR"など）。
- **値 (`uint256`)**
    - 対応する国のリテール投資家の総数。

### `issuancesCounters`

```sol
mapping(string => uint256) internal issuancesCounters;
```

投資家ごとに、これまでに何回の発行操作が行われたかを記録するカウンター。
以下の`issuancesValues`と`issuancesTimestamps`のマッピングで、各発行履歴にアクセスするためのインデックスとして使用されます。

- **キー (`string`)**
    - 投資家を一意に識別するためのID。
- **値 (`uint256`)**
    - その投資家に対する発行操作の回数。

### `issuancesValues`

```sol
mapping(string => mapping(uint256 => uint256)) issuancesValues;
```

投資家ごとの各発行操作における発行量を記録する二重マッピング。

- **第一のキー (`string`)**
    - 投資家ID。
- **第二のキー (`uint256`)**
    - 発行のインデックス番号（0から`issuancesCounters[投資家ID] - 1`まで）。
- **値 (`uint256`)**
    -   その発行操作で発行されたトークンの量。

### `issuancesTimestamps`

```sol
mapping(string => mapping(uint256 => uint256)) issuancesTimestamps;
```

投資家ごとの各発行操作における、発行日時（Unixタイムスタンプ）を記録する二重マッピング。
このデータは、特定のロックアップ期間（例：発行から1年間は送付不可）を計算するために使用されます。

- **第一のキー (`string`)**
    - 投資家ID。
- **第二のキー (`uint256`)**
    - 発行のインデックス番号。
- **値 (`uint256`)**
    - その発行操作が行われた日時（Unixタイムスタンプ）。
