Skip to content

Solidity API

TokenExchange

Token Exchange is a smart contract facilitating users to trade digital assets i.e tokens for other tokens or fiat currency.

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

ExchangeCallers

solidity
event ExchangeCallers(address depositor, address[] exchangeCallers)

ExchangeInfoSet

solidity
event ExchangeInfoSet(enum AbstractTokenExchange.ExchangeType exchangeType, uint256 ratio, address baseToken, address quoteToken)

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

TokenExchangeUnauthorizedExchangeCaller

solidity
error TokenExchangeUnauthorizedExchangeCaller(address sender)

TokenExchangeAttachmentAlreadyAdded

solidity
error TokenExchangeAttachmentAlreadyAdded(string cid)

TokenExchangeExchangeInfoAlreadyAdded

solidity
error TokenExchangeExchangeInfoAlreadyAdded()

constructor

solidity
constructor(address _depositor, string _erc1155uri) public

setExchangeInfo

solidity
function setExchangeInfo(enum AbstractTokenExchange.ExchangeType _exchangeType, uint256 _ratio, address _baseToken, address _quoteToken, address[] _disputeResolvers, uint256 _exchangeWindow, uint256 _refutationWindow) external

Set the exchange information for the contract.

Can only be called by the depositor.

Parameters

NameTypeDescription
_exchangeTypeenum AbstractTokenExchange.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.
_baseTokenaddressThe address of the token to be exchanged to.
_quoteTokenaddressThe address of the token to be used in the exchange. Required only for token-for-token exchange.
_disputeResolversaddress[]Addresses 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-20 baseTokens and receive equivalent ERC-1155 tokens. Emits TokensDeposited event.

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. Emits TokensWithdrawn event.

Parameters

NameTypeDescription
_valueuint256The amount of baseTokens to withdraw.
_toaddressThe address to credit the withdrawn ERC-20 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. Emits Exchange event.

Parameters

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

exchangeCommence

solidity
function exchangeCommence(uint256 _baseValue) external

Commences a fiat-for-token exchange and stores the exchange request. Emits ExchangeCommenced event.

Parameters

NameTypeDescription
_baseValueuint256Amount 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

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. Emits RefutationNullified event.

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. Emits ExchangeNullified event.

Parameters

NameTypeDescription
_exchangeRequestIduint256The ID of the exchange request to nullify.

exchangeComplete

solidity
function exchangeComplete(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

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}.