ERC-5633 · Stagnant(停滞) · ERC · 2022-09-09
ERC-5633: Composable Soulbound NFT, EIP-1155 Extension
個々のトークン ID をソウルバウンド(譲渡不可)として指定できる ERC-1155 拡張。1 つのコントラクトで取引可能なアイテムと紐づけられたアイテムの両方を扱える。
何を解決するのか
ゲームやコミュニティのプロジェクトでは、アイテムを混在させたいことがよくあります。自由に取引できるものもあれば、World of Warcraft のソウルバウンドアイテムのように、獲得したアカウントに「紐づく」ものもあります。ERC-5192 のような単一トークンのソウルバウンド標準は ERC-721 を対象としており、そこではすべてのトークンがそれぞれ独立した NFT です。ERC-1155 では 1 つのコントラクトが多数のトークンタイプを管理するため、タイプごとのスイッチが必要です。
ERC-5633 はそのスイッチを追加します。各トークン ID をソウルバウンドにするかどうかを選べ、ウォレットは移動を試みる前に確認できます。
仕組み
この拡張は、ERC-1155 コントラクトに view 関数 1 つとイベント 1 つを追加します。
isSoulbound(uint256 id)は、トークンタイプidがソウルバウンドならtrueを返す。Soulbound(uint256 indexed id, bool bounded)は、トークンタイプがソウルバウンドに設定された(または解除された)ときに発行される。
ルールは単純です。isSoulbound(id) が true なら、そのトークンをあるアカウントから別のアカウントへ移動するすべての ERC-1155 関数は revert しなければなりません。ミント(ゼロアドレスから)とバーン(ゼロアドレスへ)は引き続き許可されるため、発行者は紐づけられたアイテムを付与したり削除したりできます。
コントラクトは ERC-165 を実装し、インターフェース ID 0x911ec470 に対して true を返さなければなりません。これにより、ウォレットやマーケットプレイスはサポートを検出し、紐づけられた ID の「転送」ボタンをグレーアウトできます。
コレクション内のすべてのトークンを紐づける意図であれば、仕様は isSoulbound がデフォルトで単に true を返すことを提案しています。
サンプルコード
OpenZeppelin v5 の ERC-1155 で、_update フックを使ってルールを強制する:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
interface IERC5633 {
event Soulbound(uint256 indexed id, bool bounded);
function isSoulbound(uint256 id) external view returns (bool);
}
contract GameItems is ERC1155, IERC5633 {
mapping(uint256 => bool) private _bound;
constructor() ERC1155("https://example.com/items/{id}.json") {}
function isSoulbound(uint256 id) public view returns (bool) {
return _bound[id];
}
function _setSoulbound(uint256 id, bool bounded) internal {
_bound[id] = bounded;
emit Soulbound(id, bounded);
}
function _update(address from, address to, uint256[] memory ids, uint256[] memory values)
internal override
{
if (from != address(0) && to != address(0)) {
for (uint256 i; i < ids.length; ++i) {
require(!_bound[ids[i]], "ERC5633: soulbound");
}
}
super._update(from, to, ids, values);
}
function supportsInterface(bytes4 interfaceId) public view override returns (bool) {
return interfaceId == type(IERC5633).interfaceId || super.supportsInterface(interfaceId);
}
}
(ミントと _setSoulbound のアクセス制御は簡略化のため省略しています。)