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
Name | Type | Description |
---|---|---|
_name | string | The name of the token |
_symbol | string | The symbol of the token |
_maxBlockWindow | uint256 | The 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
Name | Type | Description |
---|---|---|
_chipId | address | Chip ID (address) |
_to | address | Address to transfer the chip ownership to |
_payload | bytes | Encoded payload containing data required to execute transfer. Data structure will be dependent on implementation of TransferPolicy |
_signature | bytes | Signature of the payload signed by the chip |
_useSafeTransfer | bool |
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
Name | Type | Description |
---|---|---|
_chipId | address | The chipId to set the transfer policy for |
_newPolicy | contract ITransferPolicy | The address of the new transfer policy. We allow the zero address in case owner doesn't want to allow xfers. |
_commitBlock | uint256 | The block the signature is tied to (used to put a time limit on the signature) |
_signature | bytes | The 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
Name | Type | Description |
---|---|---|
_chipId | address | The chipId to set the owner for |
_newOwner | address | The address of the new chip owner |
_commitBlock | uint256 | The block the signature is tied to (used to put a time limit on the signature) |
_signature | bytes | The 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
Name | Type | Description |
---|---|---|
_chipId | address | The chipId to check the signature for |
_payload | bytes | The payload to check the signature for |
_signature | bytes | The signature to check |
Return Values
Name | Type | Description |
---|---|---|
[0] | bool | bool 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
Name | Type | Description |
---|---|---|
_tokenId | uint256 | The tokenId to get the tokenURI for |
Return Values
Name | Type | Description |
---|---|---|
[0] | string | string 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
Name | Type | Description |
---|---|---|
_chipId | address | The tokenId to get the tokenURI for |
Return Values
Name | Type | Description |
---|---|---|
[0] | string | string The tokenURI for the given tokenId |
tokenIdFor
function tokenIdFor(address _chipId) public view returns (uint256 tokenId)
Returns the tokenId for a given chipId
Parameters
Name | Type | Description |
---|---|---|
_chipId | address | The chipId to get the tokenId for |
Return Values
Name | Type | Description |
---|---|---|
tokenId | uint256 | The tokenId for the given chipId |
ownerOf
function ownerOf(address _chipId) public view returns (address)
Returns the owner of a given chipId
Parameters
Name | Type | Description |
---|---|---|
_chipId | address | The chipId to get the owner for |
Return Values
Name | Type | Description |
---|---|---|
[0] | address | address 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
Name | Type | Description |
---|---|---|
_to | address | The address to mint the token to |
_chipId | address | The chipId to mint the token for |
_chipInfo | struct ClaimedPBT.ChipInfo | The ChipInfo struct to add to the chipTable (tokenId is modified in this function) |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 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
Name | Type | Description |
---|---|---|
_chipId | address | The chipId to check |
Return Values
Name | Type | Description |
---|---|---|
[0] | bool | bool True if the chipId has been claimed, false otherwise |