Skip to content

Solidity API

TokenCustody

The Token Custody smart contract is designed to manage and maintain the custody of ERC-20 tokens in a locked state under the ownership of a single contract. The contract supports ERC-1155-style ledger management to track ownership and balances for various tokens.

attachments

solidity
mapping(string => address) attachments

Mapping to track CID attachments and their submitters

AttachmentAdded

solidity
event AttachmentAdded(string cid, address submitter)

Emitted when a new attachment is added to the contract

TokensDeposited

solidity
event TokensDeposited(address depositor, address token, uint256 value, uint256 tokenId)

Emitted when ERC20 tokens are deposited into the contract

ERC20Withdrawn

solidity
event ERC20Withdrawn(address sender, address token, uint256 value, address to)

Emitted when ERC20 tokens are withdrawn from the contract

TokenCustodyInvalidTokenId

solidity
error TokenCustodyInvalidTokenId(uint256 value)

Error thrown when an invalid token ID is provided

TokenCustodyTransferFailed

solidity
error TokenCustodyTransferFailed(address from, address to, uint256 amount)

Error thrown when an erc-20 token transfer fails

TokenCustodyAttachmentAlreadyAdded

solidity
error TokenCustodyAttachmentAlreadyAdded(string cid)

Error thrown when attempting to add a duplicate attachment

constructor

solidity
constructor(address _initialOwner, string _erc1155uri) public

deposit

solidity
function deposit(uint256 _value, address _token) external

Deposit ERC-20 baseTokens for exchange into the contract and mint corresponding ERC-1155 tokens.

Caller must be the depositor and have approved the contract to spend value amount of the ERC-20 baseTokens.

Parameters

NameTypeDescription
_valueuint256The amount of baseTokens to deposit.
_tokenaddress

withdraw

solidity
function withdraw(uint256 id, uint256 value, address to) external

_Allows withdrawal of deposited ERC20 tokens by burning ERC1155 tokens

Requirements:

  • The contract must not be paused
  • The sender must be owner of the contract
  • The transfer must succeed_

Parameters

NameTypeDescription
iduint256Token ID to withdraw
valueuint256Amount to withdraw
toaddressAddress to receive the tokens

addAttachment

solidity
function addAttachment(string cid) external

_Adds a new attachment to the contract

Requirements:

  • Only callable by owner
  • CID must not already exist_

Parameters

NameTypeDescription
cidstringContent identifier for the attachment

safeTransferFrom

solidity
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes data) public virtual

See {IERC1155-safeTransferFrom}.

safeBatchTransferFrom

solidity
function safeBatchTransferFrom(address from, address to, uint256[] ids, uint256[] values, bytes data) public virtual

See {IERC1155-safeBatchTransferFrom}.

_tokenIdFromAddress

solidity
function _tokenIdFromAddress(address token) internal pure returns (uint256)

_uint256ToAddress

solidity
function _uint256ToAddress(uint256 value) internal pure returns (address)

Converts a uint256 to an Ethereum address.

Parameters

NameTypeDescription
valueuint256The uint256 value to be converted.

Return Values

NameTypeDescription
[0]addressaddress The Ethereum address corresponding to the uint256 value.