Skip to content

Solidity API

TokenExchange1155

It is a trade contract to exchange an erc-1155 token with another erc-1155 token or with an off-chain settlement.

ExchangeType

Defines the type of Exchange

solidity
enum ExchangeType {
  TOKEN_FOR_TOKEN,
  FIAT_FOR_TOKEN
}

depositor

solidity
address depositor

exchangeType

solidity
enum TokenExchange1155.ExchangeType exchangeType

ratio

solidity
uint256 ratio

baseTokenAddress

solidity
address baseTokenAddress

baseTokenId

solidity
uint256 baseTokenId

quoteTokenAddress

solidity
address quoteTokenAddress

quoteTokenId

solidity
uint256 quoteTokenId

exchangeWindow

solidity
uint256 exchangeWindow

disputeResolver

solidity
address disputeResolver

exchangeRequests

solidity
mapping(uint256 => struct TokenExchange1155.ExchangeRequest) exchangeRequests

refutationWindow

solidity
uint256 refutationWindow

depositUnderExchange

solidity
uint256 depositUnderExchange

exchangeCallers

solidity
mapping(address => bool) exchangeCallers

attachments

solidity
mapping(string => address) attachments

Mapping to track IPFS Content Identifiers (CIDs) and their submitters Maps CID strings to the address that submitted them

ExchangeRequest

solidity
struct ExchangeRequest {
  address sender;
  uint256 value;
  uint256 timestamp;
  bool refuted;
}

DepositorSet

solidity
event DepositorSet(address depositor)

TokensDeposited

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

TokensWithdrawn

solidity
event TokensWithdrawn(address from, uint256 baseTokenId, uint256 value, address to)

TokensExchanged

solidity
event TokensExchanged(address caller, uint256 quoteToken, uint256 quoteValue, uint256 baseToken, uint256 baseValue)

ExchangeInitiated

solidity
event ExchangeInitiated(uint256 exchangeRequestId, address requester, address baseTokenAddress, uint256 baseTokenId, uint256 value)

ExchangeCompleted

solidity
event ExchangeCompleted(uint256 exchangeRequestId, address requester, address baseTokenAddress, uint256 baseTokenId, uint256 value)

ExchangeRefuted

solidity
event ExchangeRefuted(address depositor, uint256 exchangeRequestId)

ExchangeCallersSet

solidity
event ExchangeCallersSet(address[] _exchangeCallers)

RefutationNullified

solidity
event RefutationNullified(address sender, uint256 exchangeRequestId)

ExchangeNullified

solidity
event ExchangeNullified(address sender, uint256 exchangeRequestId)

AttachmentAdded

solidity
event AttachmentAdded(string cid, address submitter)

Emitted when a new attachment is added to the contract

Parameters

NameTypeDescription
cidstringIPFS Content Identifier of the attachment
submitteraddressAddress that submitted the attachment

ExchangeInfoSet

solidity
event ExchangeInfoSet(enum TokenExchange1155.ExchangeType exchangeType, uint256 ratio, address baseTokenAddress, uint256 baseTokenId, address quoteTokenAddress, uint256 quoteTokenId)

TokenExchange1155InvalidToken

solidity
error TokenExchange1155InvalidToken(address tokenAddress, string msg)

TokenExchange1155ActiveExchangeWindow

solidity
error TokenExchange1155ActiveExchangeWindow(uint256 exchangeWindowTill, uint256 requestTimestamp)

TokenExchange1155InactiveExchangeWindow

solidity
error TokenExchange1155InactiveExchangeWindow(uint256 exchangeWindowTill, uint256 requestTimestamp)

TokenExchange1155InsufficientBalance

solidity
error TokenExchange1155InsufficientBalance(uint256 balance, uint256 requested)

TokenExchange1155ApprovalNotGranted

solidity
error TokenExchange1155ApprovalNotGranted(address tokenAddress, address owner, address operator)

TokenExchange1155UnauthorizedDepositor

solidity
error TokenExchange1155UnauthorizedDepositor(address sender, address depositor)

TokenExchange1155InvalidExchangeType

solidity
error TokenExchange1155InvalidExchangeType(enum TokenExchange1155.ExchangeType expectedType)

TokenExchange1155InvalidRatio

solidity
error TokenExchange1155InvalidRatio(uint256 _ratio)

TokenExchange1155InvalidExchangeRequest

solidity
error TokenExchange1155InvalidExchangeRequest(uint256 requestId)

TokenExchange1155InactiveRefutationWindow

solidity
error TokenExchange1155InactiveRefutationWindow(uint256 refutationWindowTill, uint256 refuteTimestamp)

TokenExchange1155ActiveRefutationWindow

solidity
error TokenExchange1155ActiveRefutationWindow(uint256 refutationWindowTill, uint256 requestTimestamp)

TokenExchange1155InvalidRefutationWindow

solidity
error TokenExchange1155InvalidRefutationWindow(uint256 refutationWindowTill, uint256 requestTimestamp)

TokenExchange1155UnauthorizedResolver

solidity
error TokenExchange1155UnauthorizedResolver(address sender)

TokenExchange1155UnauthorizedRequester

solidity
error TokenExchange1155UnauthorizedRequester(address sender, address originalRequester)

TokenExchange1155InvalidRefutationStatus

solidity
error TokenExchange1155InvalidRefutationStatus(uint256 exchangeRequestId)

TokenExchange1155AttachmentAlreadyAdded

solidity
error TokenExchange1155AttachmentAlreadyAdded(string cid)

TokenExchange1155ExchangeInfoAlreadyAdded

solidity
error TokenExchange1155ExchangeInfoAlreadyAdded()

TokenExchange1155TransferFailed

solidity
error TokenExchange1155TransferFailed(address from, address to, address tokenAddress, uint256 tokenId, uint256 amount)

Error thrown when an erc-20 token transfer fails

TokenExchange1155UnauthorizedExchangeCaller

solidity
error TokenExchange1155UnauthorizedExchangeCaller(address caller)

constructor

solidity
constructor(address _initialOwner, address _initialDepositor, string _erc1155uri) public

setExchangeInfo

solidity
function setExchangeInfo(enum TokenExchange1155.ExchangeType _exchangeType, uint256 _ratio, address _baseTokenAddress, uint256 _baseTokenId, address _quoteTokenAddress, uint256 _quoteTokenId, address _disputeResolver, uint256 _exchangeWindow, uint256 _refutationWindow) external

Set the exchange information for the contract.

Can only be called by the depositor.

Parameters

NameTypeDescription
_exchangeTypeenum TokenExchange1155.ExchangeTypeThe type of exchange: 0 for token-for-token, 1 for fiat-for-token.
_ratiouint256The exchange ratio (scaled to 10^18). Required only for token-for-token exchange.
_baseTokenAddressaddressThe address of the token deposited by the depositor.
_baseTokenIduint256The id of the token to be deposited by the depositor.
_quoteTokenAddressaddressThe address of the token to be used in the exchange. Required only for token-for-token exchange.
_quoteTokenIduint256The id of the token to be used in the exchange. Required only for token-for-token exchange.
_disputeResolveraddressAddresses for account with authority to resolve refutations. Required only for fiat-for-token exchange.
_exchangeWindowuint256The Epoch time in seconds before which an exchange/exchangeCommence can be performed.
_refutationWindowuint256The Time in seconds from each exchangeCommence request when a depositor may refute the exchange. Required only for fiat-for-token exchange.

deposit

solidity
function deposit(uint256 _value) external

Allows the depositor to deposit ERC-1155 baseTokens and receive equivalent ERC-1155 tokens.

Parameters

NameTypeDescription
_valueuint256Amount of baseTokens to deposit.

withdraw

solidity
function withdraw(uint256 _value, address _to) external

Allows the depositor to withdraw baseTokens not undergoing an exchange. Allowed only once the exchange window has passed.

Parameters

NameTypeDescription
_valueuint256The amount of baseTokens to withdraw.
_toaddressThe address to credit the withdrawn ERC-1155 tokens.

addAttachment

solidity
function addAttachment(string _cid) external

Adds a new IPFS attachment to the contract

Parameters

NameTypeDescription
_cidstringIPFS Content Identifier for the attachment Requirements: - Caller must be the contract owner - CID must not already be registered

whitelistExchangeCallers

solidity
function whitelistExchangeCallers(address[] _exchangeCallers) external

Whitelists a list of exchange callers, enabling them to perform exchange-related operations.

Parameters

NameTypeDescription
_exchangeCallersaddress[]An array of addresses to be whitelisted as exchange callers. Requirements: - The caller must be the depositor (enforced by the onlyDepositor modifier). Emits: - ExchangeCallers event upon successful addition of exchange callers.

exchange

solidity
function exchange(uint256 _quoteValue) external

Allows users to perform token-for-token exchanges.

Parameters

NameTypeDescription
_quoteValueuint256Amount of the ERC-1155 quoteTokens to exchange from.

initiateExchange

solidity
function initiateExchange(uint256 _baseValue) external

initiates a fiat-for-token exchange and stores the exchange request.

Parameters

NameTypeDescription
_baseValueuint256Amount of tokens requested.

refuteExchange

solidity
function refuteExchange(uint256 _exchangeRequestId) external

Allows the depositor to refute a fiat-for-token exchange request.

Parameters

NameTypeDescription
_exchangeRequestIduint256The unique identifier for the exchange request.

nullifyRefutation

solidity
function nullifyRefutation(uint256 _exchangeRequestId) external

Nullify a refutation, marking the exchange request as unRefuted.

Can only be called by the depositor or a disputeResolver. The exchange request must exist and have been refuted.

Parameters

NameTypeDescription
_exchangeRequestIduint256The ID of the exchange request to nullify refutation.

nullifyExchange

solidity
function nullifyExchange(uint256 _exchangeRequestId) external

Nullifies a refuted exchange request, removing it and unlocking depositor's tokens.

Can only be called by a dispute resolver. The exchange request must exist and be refuted.

Parameters

NameTypeDescription
_exchangeRequestIduint256The ID of the exchange request to nullify.

completeExchange

solidity
function completeExchange(uint256 _exchangeRequestId) external

Completes a fiat-for-token exchange once the refuation window is passed and no active refuations are present.

Parameters

NameTypeDescription
_exchangeRequestIduint256Amount of tokens requested.

safeTransferFrom

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

See {IERC1155-safeTransferFrom}.

safeBatchTransferFrom

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

See {IERC1155-safeBatchTransferFrom}.

onERC1155Received

solidity
function onERC1155Received(address, address, uint256, uint256, bytes) external pure returns (bytes4)

onERC1155BatchReceived

solidity
function onERC1155BatchReceived(address, address, uint256[], uint256[], bytes) external pure returns (bytes4)

onlyDepositor

solidity
modifier onlyDepositor()

_isCompatibleERC1155

solidity
function _isCompatibleERC1155(address _token) internal view

Verifies if the given address is a valid ERC1155 token by checking the presence of the transfer, transferFrom, and allowance functions using staticcall.

Parameters

NameTypeDescription
_tokenaddressThe token address to verify.