Skip to content

Solidity API

AbstractTokenExchange

This contract provides the base for exchanges, refutations, and balances management for such processes. It expects to be implemented by further fine-tuned trade contracts and remains abstract itself.

ExchangeType

Defines the type of Exchange

solidity
enum ExchangeType {
  TOKEN_FOR_TOKEN,
  FIAT_FOR_TOKEN
}

DEPOSITOR

solidity
address DEPOSITOR

exchangeType

solidity
enum AbstractTokenExchange.ExchangeType exchangeType

ratio

solidity
uint256 ratio

baseToken

solidity
address baseToken

quoteToken

solidity
address quoteToken

exchangeWindow

solidity
uint256 exchangeWindow

refutationWindow

solidity
uint256 refutationWindow

depositUnderExchange

solidity
uint256 depositUnderExchange

disputeResolvers

solidity
mapping(address => bool) disputeResolvers

exchangeRequests

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

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 token, uint256 value, uint256 tokenId)

TokensWithdrawn

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

TokensExchanged

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

ExchangeCommenced

solidity
event ExchangeCommenced(uint256 exchangeRequestId, address requester, address baseToken, uint256 value)

ExchangeCompleted

solidity
event ExchangeCompleted(uint256 exchangeRequestId, address requester, address baseToken, uint256 value)

ExchangeRefuted

solidity
event ExchangeRefuted(address depositor, uint256 exchangeRequestId)

RefutationNullified

solidity
event RefutationNullified(address sender, uint256 exchangeRequestId)

ExchangeNullified

solidity
event ExchangeNullified(address sender, uint256 exchangeRequestId)

TokenExchangeInvalidToken

solidity
error TokenExchangeInvalidToken(address tokenAddress, string msg)

TokenExchangeActiveExchangeWindow

solidity
error TokenExchangeActiveExchangeWindow(uint256 exchangeWindowTill, uint256 requestTimestamp)

TokenExchangeInactiveExchangeWindow

solidity
error TokenExchangeInactiveExchangeWindow(uint256 exchangeWindowTill, uint256 requestTimestamp)

TokenExchangeInsufficientBalance

solidity
error TokenExchangeInsufficientBalance(uint256 balance, uint256 requested)

TokenExchangeInsufficientAllowance

solidity
error TokenExchangeInsufficientAllowance(uint256 allowance, uint256 required)

TokenExchangeUnauthorizedDepositor

solidity
error TokenExchangeUnauthorizedDepositor(address sender, address depositor)

TokenExchangeInvalidExchangeRequest

solidity
error TokenExchangeInvalidExchangeRequest(uint256 requestId)

TokenExchangeInactiveRefutationWindow

solidity
error TokenExchangeInactiveRefutationWindow(uint256 refutationWindowTill, uint256 refuteTimestamp)

TokenExchangeActiveRefutationWindow

solidity
error TokenExchangeActiveRefutationWindow(uint256 refutationWindowTill, uint256 requestTimestamp)

TokenExchangeInvalidRefutationWindow

solidity
error TokenExchangeInvalidRefutationWindow(uint256 refutationWindowTill, uint256 requestTimestamp)

TokenExchangeUnauthorizedResolver

solidity
error TokenExchangeUnauthorizedResolver(address sender)

TokenExchangeUnauthorizedRequester

solidity
error TokenExchangeUnauthorizedRequester(address sender, address originalRequester)

TokenExchangeInvalidRefutationStatus

solidity
error TokenExchangeInvalidRefutationStatus(uint256 exchangeRequestId)

TokenExchangeTransferFailed

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

_setDepositor

solidity
function _setDepositor(address _depositor) internal

getDepositor

solidity
function getDepositor() public view virtual returns (address)

getExchangeType

solidity
function getExchangeType() public view virtual returns (enum AbstractTokenExchange.ExchangeType)

_setExchangeType

solidity
function _setExchangeType(enum AbstractTokenExchange.ExchangeType _exchangeType) internal

getRatio

solidity
function getRatio() public view virtual returns (uint256)

_setRatio

solidity
function _setRatio(uint256 _newRatio) internal

getBaseToken

solidity
function getBaseToken() public view virtual returns (address)

getQuoteToken

solidity
function getQuoteToken() public view virtual returns (address)

getExchangeWindow

solidity
function getExchangeWindow() public view virtual returns (uint256)

_setExchangeWindow

solidity
function _setExchangeWindow(uint256 _newExchangeWindow) internal

isDisputeResolver

solidity
function isDisputeResolver(address resolver) public view virtual returns (bool)

_setDisputeResolver

solidity
function _setDisputeResolver(address _resolver, bool _allow) internal

getExchangeRequest

solidity
function getExchangeRequest(uint256 requestId) public view virtual returns (struct AbstractTokenExchange.ExchangeRequest exchangeRequest)

getRefutationWindow

solidity
function getRefutationWindow() public view virtual returns (uint256)

_setRefutationWindow

solidity
function _setRefutationWindow(uint256 _newRefutationWindow) internal

_setBaseToken

solidity
function _setBaseToken(address _baseToken) internal

_setQuoteToken

solidity
function _setQuoteToken(address _quoteToken) internal

getDepositUnderExchange

solidity
function getDepositUnderExchange() public view virtual returns (uint256)

constructor

solidity
constructor(string _erc1155uri) internal

_deposit

solidity
function _deposit(address _to, address _token, uint256 _value) internal

Deposit ERC-20 baseTokens to an address into the contract and mint corresponding ERC-1155 tokens.

Caller must have approved the contract to spend value amount of the ERC-20 token provided.

Parameters

NameTypeDescription
_toaddressRecepient Address
_tokenaddressToken ID
_valueuint256The amount of tokens to deposit

_withdraw

solidity
function _withdraw(address _from, address _to, address _token, uint256 _value) internal

Withdraw deposited ERC-20 tokens from the contract.

The caller must own equivalent ERC-1155 tokens for the same ERC-20 contract being withdrawn.

Parameters

NameTypeDescription
_fromaddressAddress of the account on erc-1155 balances to withdraw from.
_toaddressThe address to credit the withdrawn ERC-20 tokens.
_tokenaddressThe address ERC-20 to be withdrawn from ERC-1155 deposited balances.
_valueuint256The amount of tokens to withdraw.

_exchange

solidity
function _exchange(uint256 _quoteValue) internal

Single-step exchange for token-for-token exchange.

The caller must approve the contract for sufficient quoteToken ERC-20 tokens, and the contract will exchange quoteToken for baseToken based on the established ratio. This function can only be called during the exchangeWindow.

Parameters

NameTypeDescription
_quoteValueuint256The value of ERC-20 quoteToken to be exchanged.

_initiateExchange

solidity
function _initiateExchange(uint256 _baseValue, address _exchangeCaller, uint256 _exchangeRequestId) internal

Commences a refutable fiat-for-token exchange process.

This function allows users to initiate an exchange request during the exchange window. The request will be recorded and can be refuted by the depositor within the refutation window.

Parameters

NameTypeDescription
_baseValueuint256The value of ERC-20 baseToken to be exchanged.
_exchangeCalleraddressSender's Address
_exchangeRequestIduint256Exchange Request ID

_refuteExchange

solidity
function _refuteExchange(uint256 _exchangeRequestId) internal

Refute an exchange request by the depositor.

The caller must be the depositor and the exchange request should be available and within the refutable time frame.

Parameters

NameTypeDescription
_exchangeRequestIduint256The ID of the exchange request to be refuted.

_nullifyRefutation

solidity
function _nullifyRefutation(uint256 _exchangeRequestId) internal

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) internal

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) internal

Completes an exchange request by transferring tokens to the original request sender. Ensures the refutation window has elapsed, and the request is not refuted.

Parameters

NameTypeDescription
_exchangeRequestIduint256The unique ID of the exchange request to be completed. Requirements: - The caller must be the original exchange request sender. - The refutation window must have elapsed. - The exchange request must not be refuted. - The baseToken must have sufficient balance and approval for transfer. Emits: - ExchangeCompleted event upon successful completion of the exchange.

onlyDepositor

solidity
modifier onlyDepositor()

_isCompatibleERC20

solidity
function _isCompatibleERC20(address token) internal returns (bool, string)

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

Parameters

NameTypeDescription
tokenaddressThe token address to verify.

Return Values

NameTypeDescription
[0]bool_isCompatibleERC20 True if the address is a valid ERC20 token (with the required functions).
[1]string