# FiatTokenV2_1.sol

> FiatTokenV2_1は、FiatTokenV2コントラクトを継承して作られた、Circleのフィアット担保型トークン（USDCなど）のバージョン2.1のアップグレード用コントラクトです。

- URL: https://cardene.dev/books/usdc/f00ab9
- 本: USDC (https://cardene.dev/books/usdc.md)
- 章: 10 / 13
- 前の章: https://cardene.dev/books/usdc/c1a082.md
- 次の章: https://cardene.dev/books/usdc/e3dc90.md
- 公開日: 2025-07-08
- 更新日: 2025-07-08
- トピック: Blockchain
- タグ: ブロックチェーン, solidity, ethereum, smartcontract

## 概要

**FiatTokenV2_1**は、**FiatTokenV2**コントラクトを継承して作られた、Circleのフィアット担保型トークン（USDCなど）のバージョン2.1のアップグレード用コントラクトです。
バージョン2.1では、以下のような処理が追加されています。

* コントラクト内に残っているトークン残高の送付（`lostAndFound` へ送金）。
* コントラクト自信のブラックリスト化（誤送金防止）。
* **EIP712**のドメインバージョン文字列の更新。

## コード

https://github.com/circlefin/stablecoin-evm/blob/master/contracts/v2/FiatTokenV2_1.sol

```sol
/**
 * Copyright 2023 Circle Internet Group, Inc. All rights reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

pragma solidity 0.6.12;

import { FiatTokenV2 } from "./FiatTokenV2.sol";

// solhint-disable func-name-mixedcase

/**
 * @title FiatToken V2.1
 * @notice ERC20 Token backed by fiat reserves, version 2.1
 */
contract FiatTokenV2_1 is FiatTokenV2 {
    /**
     * @notice Initialize v2.1
     * @param lostAndFound  The address to which the locked funds are sent
     */
    function initializeV2_1(address lostAndFound) external {
        // solhint-disable-next-line reason-string
        require(_initializedVersion == 1);

        uint256 lockedAmount = _balanceOf(address(this));
        if (lockedAmount > 0) {
            _transfer(address(this), lostAndFound, lockedAmount);
        }
        _blacklist(address(this));

        _initializedVersion = 2;
    }

    /**
     * @notice Version string for the EIP712 domain separator
     * @return Version string
     */
    function version() external pure returns (string memory) {
        return "2";
    }
}
```

## 関数

### `initializeV2_1`

```sol
function initializeV2_1(address lostAndFound) external {
    // solhint-disable-next-line reason-string
    require(_initializedVersion == 1);

    uint256 lockedAmount = _balanceOf(address(this));
    if (lockedAmount > 0) {
        _transfer(address(this), lostAndFound, lockedAmount);
    }
    _blacklist(address(this));

    _initializedVersion = 2;
}
```

バージョン2.1の初期化を実行する関数。
* 初期化前提バージョンがv2であることを確認（`_initializedVersion == 1`）。
* コントラクト自身が保持している残高があれば、それを `lostAndFound` アドレスに送金。
* 誤送金や再利用防止のために、コントラクト自身のアドレスをブラックリストに登録。
* `_initializedVersion` を `2` に更新し、二重初期化を防止

**引数**

* `lostAndFound`
    - コントラクト自身にロックされていたトークンを送るアドレス。

### `version`

```sol
function version() external pure returns (string memory) {
    return "2";
}
```

**EIP712**の `domain.version` に返されるバージョン文字列を返す関数。
* **EIP712**準拠の署名ドメインにおいて、バージョンを識別する目的で `"2"` を返します。

**戻り値**

* `string`
    - `"2"`
        - このバージョンの識別子。
