Appearance
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
Name | Type | Description |
---|---|---|
cid | string | IPFS Content Identifier of the attachment |
submitter | address | Address 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
Name | Type | Description |
---|---|---|
_exchangeType | enum TokenExchange1155.ExchangeType | The type of exchange: 0 for token-for-token, 1 for fiat-for-token. |
_ratio | uint256 | The exchange ratio (scaled to 10^18). Required only for token-for-token exchange. |
_baseTokenAddress | address | The address of the token deposited by the depositor. |
_baseTokenId | uint256 | The id of the token to be deposited by the depositor. |
_quoteTokenAddress | address | The address of the token to be used in the exchange. Required only for token-for-token exchange. |
_quoteTokenId | uint256 | The id of the token to be used in the exchange. Required only for token-for-token exchange. |
_disputeResolver | address | Addresses for account with authority to resolve refutations. Required only for fiat-for-token exchange. |
_exchangeWindow | uint256 | The Epoch time in seconds before which an exchange/exchangeCommence can be performed. |
_refutationWindow | uint256 | The 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. Emits TokensDeposited
event.
Parameters
Name | Type | Description |
---|---|---|
_value | uint256 | Amount 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. Emits TokensWithdrawn
event.
Parameters
Name | Type | Description |
---|---|---|
_value | uint256 | The amount of baseTokens to withdraw. |
_to | address | The address to credit the withdrawn ERC-1155 tokens. |
addAttachment
solidity
function addAttachment(string _cid) external
Adds a new IPFS attachment to the contract
Parameters
Name | Type | Description |
---|---|---|
_cid | string | IPFS 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
Name | Type | Description |
---|---|---|
_exchangeCallers | address[] | 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. Emits Exchange
event.
Parameters
Name | Type | Description |
---|---|---|
_quoteValue | uint256 | Amount 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. Emits ExchangeInitiaed
event.
Parameters
Name | Type | Description |
---|---|---|
_baseValue | uint256 | Amount of tokens requested. |
refute
solidity
function refute(uint256 _exchangeRequestId) external
Allows the depositor to refute a fiat-for-token exchange request. Emits ExchangeRefuted
event.
Parameters
Name | Type | Description |
---|---|---|
_exchangeRequestId | uint256 | The 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. Emits RefutationNullified
event.
Parameters
Name | Type | Description |
---|---|---|
_exchangeRequestId | uint256 | The 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. Emits ExchangeNullified
event.
Parameters
Name | Type | Description |
---|---|---|
_exchangeRequestId | uint256 | The 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. Emits ExchangeCompleted
event.
Parameters
Name | Type | Description |
---|---|---|
_exchangeRequestId | uint256 | Amount 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
Name | Type | Description |
---|---|---|
_token | address | The token address to verify. |