概要

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

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

コード

text
/**
 * 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

text
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

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

EIP712の domain.version に返されるバージョン文字列を返す関数。

  • EIP712準拠の署名ドメインにおいて、バージョンを識別する目的で "2" を返します。

戻り値

  • string
    • "2"
      • このバージョンの識別子。