Appearance
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
Name | Type | Description |
---|---|---|
cid | string | IPFS Content Identifier of the attachment |
submitter | address | Address that submitted the attachment |
TokenExchangeUnauthorizedExchangeCaller
solidity
error TokenExchangeUnauthorizedExchangeCaller(address sender)
TokenExchangeAttachmentAlreadyAdded
solidity
error TokenExchangeAttachmentAlreadyAdded(string cid)
TokenExchangeExchangeInfoAlreadyAdded
solidity
error TokenExchangeExchangeInfoAlreadyAdded()
InvalidCid
solidity
error InvalidCid()
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
Name | Type | Description |
---|---|---|
_exchangeType | enum AbstractTokenExchange.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. |
_baseToken | address | The address of the token to be exchanged to. |
_quoteToken | address | The address of the token to be used in the exchange. Required only for token-for-token exchange. |
_disputeResolvers | 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-20 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.
Parameters
Name | Type | Description |
---|---|---|
_value | uint256 | The amount of baseTokens to withdraw. |
_to | address | The address to credit the withdrawn ERC-20 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-20 quoteTokens to exchange from. |
initiateExchange
solidity
function initiateExchange(uint256 _baseValue) external
Commences a fiat-for-token exchange and stores the exchange request. Emits ExchangeCommenced
event.
Parameters
Name | Type | Description |
---|---|---|
_baseValue | uint256 | Amount of tokens requested. |
refuteExchange
solidity
function refuteExchange(uint256 _exchangeRequestId) external
Allows the depositor to refute a fiat-for-token exchange request.
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.
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.
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.
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}.