Contracts
PBT
ClaimedPBT

Solidity API

ClaimedPBT

Implementation of PBT where tokenIds are assigned to chip addresses as the chips are claimed by their owners. Each chip has its own transfer policy, which can be set by the chip owner and allows the owner to specify how the chip can be transferred to another party. This enables more flexibility for secondary services to facilitate the transfer of chips. Additionally, chip owners can directly transfer their chips by calling setOwner, this function is only callable by the chip owner whereas the transfer function is callable by anyone (assuming transfer policy conditions have been met). Since there is often other metadata associated with a chip we provide a tokenData field that can be written to by inheriting contracts.

TransferPolicyChanged

event TransferPolicyChanged(address chipId, address transferPolicy)

ChipInfo

struct ChipInfo {
  uint256 tokenId;
  contract ITransferPolicy transferPolicy;
  string tokenUri;
  bytes tokenData;
}

onlyChipOwner

modifier onlyChipOwner(address _chipId)

onlyClaimedChip

modifier onlyClaimedChip(address _chipId)

maxBlockWindow

uint256 maxBlockWindow

chipTable

mapping(address => struct ClaimedPBT.ChipInfo) chipTable

tokenIdToChipId

mapping(uint256 => address) tokenIdToChipId

tokenIdCounter

uint256 tokenIdCounter

constructor

constructor(string _name, string _symbol, uint256 _maxBlockWindow) public

Constructor for ClaimedPBT. Sets the name and symbol for the token.

Parameters

NameTypeDescription
_namestringThe name of the token
_symbolstringThe symbol of the token
_maxBlockWindowuint256The maximum amount of blocks a signature used for updating chip table is valid for

transferTokenWithChip

function transferTokenWithChip(address _chipId, address _to, bytes _payload, bytes _signature, bool _useSafeTransfer) public virtual

Allow a user to transfer a chip to a new owner. A transfer policy must be set in order for transfer to go through. The data contained in _payload will be dependent on the implementation of the transfer policy, however the signature should be signed by the chip. EIP-1271 compatibility should be implemented in the chip's TransferPolicy contract.

Parameters

NameTypeDescription
_chipIdaddressChip ID (address)
_toaddressAddress to transfer the chip ownership to
_payloadbytesEncoded payload containing data required to execute transfer. Data structure will be dependent on implementation of TransferPolicy
_signaturebytesSignature of the payload signed by the chip
_useSafeTransferbool

setTransferPolicy

function setTransferPolicy(address _chipId, contract ITransferPolicy _newPolicy, uint256 _commitBlock, bytes _signature) public virtual

ONLY CHIP OWNER: Sets the transfer policy for a chip. Chip owner must submit transaction along with a signature from the chipId commiting to a block the signature was generated. This is to prevent any replay attacks. If the transaction isn't submitted within the MAX_BLOCK_WINDOW from the commited block this function will revert.

Parameters

NameTypeDescription
_chipIdaddressThe chipId to set the transfer policy for
_newPolicycontract ITransferPolicyThe address of the new transfer policy. We allow the zero address in case owner doesn't want to allow xfers.
_commitBlockuint256The block the signature is tied to (used to put a time limit on the signature)
_signaturebytesThe signature generated by the chipId (should just be a signature of the commitBlock)

setOwner

function setOwner(address _chipId, address _newOwner, uint256 _commitBlock, bytes _signature) public virtual

ONLY CHIP OWNER: Sets the owner for a chip. Chip owner must submit transaction along with a signature from the chipId commiting to a block the signature was generated. This is to prevent any replay attacks. If the transaction isn't submitted within the MAX_BLOCK_WINDOW from the commited block this function will revert.

Parameters

NameTypeDescription
_chipIdaddressThe chipId to set the owner for
_newOwneraddressThe address of the new chip owner
_commitBlockuint256The block the signature is tied to (used to put a time limit on the signature)
_signaturebytesThe signature generated by the chipId (should just be a signature of the commitBlock)

isChipSignatureForToken

function isChipSignatureForToken(address _chipId, bytes _payload, bytes _signature) public view returns (bool)

Using OpenZeppelin's SignatureChecker library, checks if the signature is valid for the payload. Library is ERC-1271 compatible, so it will check if the chipId is a contract and if so, if it implements the isValidSignature.

Parameters

NameTypeDescription
_chipIdaddressThe chipId to check the signature for
_payloadbytesThe payload to check the signature for
_signaturebytesThe signature to check

Return Values

NameTypeDescription
[0]boolbool If the signature is valid, false otherwise

tokenURI

function tokenURI(uint256 _tokenId) public view virtual returns (string)

Returns the tokenURI for a given tokenId. Token must have been minted / chip claimed.

Parameters

NameTypeDescription
_tokenIduint256The tokenId to get the tokenURI for

Return Values

NameTypeDescription
[0]stringstring The tokenURI for the given tokenId

tokenURI

function tokenURI(address _chipId) public view virtual returns (string)

Returns the tokenURI for a given chipId. Chip must have been claimed / token minted.

Parameters

NameTypeDescription
_chipIdaddressThe tokenId to get the tokenURI for

Return Values

NameTypeDescription
[0]stringstring The tokenURI for the given tokenId

tokenIdFor

function tokenIdFor(address _chipId) public view returns (uint256 tokenId)

Returns the tokenId for a given chipId

Parameters

NameTypeDescription
_chipIdaddressThe chipId to get the tokenId for

Return Values

NameTypeDescription
tokenIduint256The tokenId for the given chipId

ownerOf

function ownerOf(address _chipId) public view returns (address)

Returns the owner of a given chipId

Parameters

NameTypeDescription
_chipIdaddressThe chipId to get the owner for

Return Values

NameTypeDescription
[0]addressaddress The owner of the given chipId

supportsInterface

function supportsInterface(bytes4 _interfaceId) public view virtual returns (bool)

_mint

function _mint(address _to, address _chipId, struct ClaimedPBT.ChipInfo _chipInfo) internal virtual returns (uint256)

Mints a new token and assigns it to the given address. Also adds the chipId to the tokenIdToChipId mapping, adds the ChipInfo to the chipTable, and increments the tokenIdCounter.

Parameters

NameTypeDescription
_toaddressThe address to mint the token to
_chipIdaddressThe chipId to mint the token for
_chipInfostruct ClaimedPBT.ChipInfoThe ChipInfo struct to add to the chipTable (tokenId is modified in this function)

Return Values

NameTypeDescription
[0]uint256uint256 The tokenId of the newly minted token

_exists

function _exists(address _chipId) internal view returns (bool)

Indicates whether the chipId has been claimed or not

Parameters

NameTypeDescription
_chipIdaddressThe chipId to check

Return Values

NameTypeDescription
[0]boolbool True if the chipId has been claimed, false otherwise