ERC-5633 · Stagnant(정체) · ERC · 2022-09-09
ERC-5633: Composable Soulbound NFT, EIP-1155 Extension
개별 토큰 ID를 소울바운드(양도 불가)로 표시하는 ERC-1155 확장. 하나의 컨트랙트에 거래 가능한 아이템과 바인딩된 아이템을 함께 둘 수 있다.
어떤 문제를 해결하나요?
게임과 커뮤니티 프로젝트는 여러 종류의 아이템을 섞고 싶어 하는 경우가 많습니다. 어떤 것은 자유롭게 거래할 수 있고, 어떤 것은 월드 오브 워크래프트(World of Warcraft)의 귀속 아이템처럼 획득한 계정에 "바인딩"됩니다. ERC-5192 같은 단일 토큰 소울바운드 표준은 모든 토큰이 각각 독립된 NFT인 ERC-721을 대상으로 합니다. ERC-1155에서는 하나의 컨트랙트가 여러 토큰 타입을 관리하므로 타입별 스위치가 필요합니다.
ERC-5633은 그 스위치를 추가합니다. 각 토큰 ID는 소울바운드일 수도 아닐 수도 있고, 지갑은 이동을 시도하기 전에 이를 확인할 수 있습니다.
어떻게 동작하나요?
이 확장은 ERC-1155 컨트랙트에 view 함수 하나와 이벤트 하나를 추가합니다.
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의 접근 제어는 간결함을 위해 생략했습니다.)