Appearance
Solidity API
TokenExchange1155
A contract template for exchanging ERC-1155 tokens with other ERC-1155 tokens, enabling secure trades.
_Trade contract for exchanging ERC-1155 tokens with either another ERC-1155 token or an off-chain settlement.
Inherits:
ERC1155
: Implements the ERC-1155 multi-token standard.IERC1155Receiver
: Allows the contract to safely receive ERC-1155 tokens.Ownable
: Provides access control for ownership-based functions.ReentrancyGuard
: Protects against reentrancy attacks._
ExchangeType
_Represents the type of exchange facilitated by the contract.
TOKEN_FOR_TOKEN
- An ERC-1155 token is exchanged for another ERC-1155 token.FIAT_FOR_TOKEN
- An ERC-1155 token is exchanged for fiat currency or involves an off-chain settlement._
solidity
enum ExchangeType {
TOKEN_FOR_TOKEN,
FIAT_FOR_TOKEN
}
ExchangeRequest
Represents the details of an exchange request.
_Structure to represent an exchange request. Contains:
sender
: The address initiating the exchange request.value
: The amount of tokens or fiat involved in the exchange.timestamp
: The time at which the request was created.refuted
: A flag indicating if the exchange request has been refuted._
solidity
struct ExchangeRequest {
address sender;
uint256 value;
uint256 timestamp;
bool refuted;
}
depositor
solidity
address depositor
The address of the depositor.
Deposits base tokens in the contracts.
exchangeType
solidity
enum TokenExchange1155.ExchangeType exchangeType
The type of exchange to be executed via the contract.
This governs the exchange info requirements and the subsequent exchange process to be followed - 0: TOKEN_FOR_TOKEN - 1: FIAT_FOR_TOKEN
ratio
solidity
uint256 ratio
Exchange ratio (only for token-for-token exchange type).
_Represents the exchange ratio, applicable only for TOKEN_FOR_TOKEN
exchange type. The ratio is scaled to 10^18
for precision and determines the amount of quote tokens required for the exchange.
Formula: quoteTokensToApprove = baseTokensToWithdraw * ratio
Example:
- If 100 base tokens are to be exchanged, and the ratio is 10 (scaled as
10^18
), the user must approve 1000 quote tokens for the exchange._
baseTokenAddress
solidity
address baseTokenAddress
The address of the erc-20 token deposited by the depositor.
This token is the one that an exchange caller will receive in exchange for their approved fiat or tokens, depending on the ExchangeType
.
baseTokenId
solidity
uint256 baseTokenId
Token ID of the base token used in exchanges.
quoteTokenAddress
solidity
address quoteTokenAddress
Address of the erc-1155 token used for the exchange type token-for-token
The caller of the exchange gives away quoteToken to obtain baseTokens of value according to the ratio set for exchange.
quoteTokenId
solidity
uint256 quoteTokenId
Token ID of the quote token used in exchanges.
exchangeWindow
solidity
uint256 exchangeWindow
Epoch time (in seconds) before which exchanges can be initiated.
Epoch time in seconds before which an exchange/exchangeCommence can be performed. Once passed,it allows for the depositor to withdraw their funds
disputeResolver
solidity
address disputeResolver
Address of the account responsible for resolving disputes in fiat-for-token exchanges.
The account with authority to resolve refutations over fiat-for-token exchanges
exchangeRequests
solidity
mapping(uint256 => struct TokenExchange1155.ExchangeRequest) exchangeRequests
Mapping of open exchange requests initiated through exchangeCommence
.
Open exchange requests recorded for exchangeCommence calls
refutationWindow
solidity
uint256 refutationWindow
Time (in seconds) allowed for depositors to refute an exchange after it has been initiated.
Time in seconds from each exchangeCommence request in which the depositor may refute and prevent the exchange
depositUnderExchange
solidity
uint256 depositUnderExchange
Tracks the total amount of tokens deposited for ongoing fiat-to-token exchanges.
Counter to track the amount of deposited tokens undergoing a fiat-to-token exchange. Helps ensure that funds not involved in an ongoing exchange can be withdrawn after the exchangeWindow
. Prevents overlapping exchange requests on the same deposit.
exchangeCallers
solidity
mapping(address => bool) exchangeCallers
Mapping of accounts authorized to perform exchange operations.
Mapping of authorized accounts for performing exchange operations. Address mapped to true
signifies the account is an authorized exchange caller.
attachments
solidity
mapping(string => address) attachments
Mapping of IPFS Content Identifiers (CIDs) to their submitters.
Mapping to track IPFS Content Identifiers (CIDs) and their submitters. Stores the address of the sender who submitted the attachment (cid => sender address).
DepositorSet
solidity
event DepositorSet(address depositor)
Logs the address of the new depositor.
Triggered when a depositor is set for the contract.
TokensDeposited
solidity
event TokensDeposited(address depositor, address tokenAddress, uint256 tokenId, uint256 value)
Logs the depositor's address, the token's address, the token ID, and the value of tokens deposited.
Triggered when tokens are deposited by a depositor.
TokensWithdrawn
solidity
event TokensWithdrawn(address from, uint256 baseTokenId, uint256 value, address to)
Logs the address of the sender, the base token ID, the value of tokens withdrawn, and the recipient's address.
Triggered when tokens are withdrawn by a depositor.
TokensExchanged
solidity
event TokensExchanged(address caller, uint256 quoteToken, uint256 quoteValue, uint256 baseToken, uint256 baseValue)
Logs the caller's address, the quote token address, quote token value, base token address, and base token value.
Indicates the execution of a token exchange operation.
ExchangeInitiated
solidity
event ExchangeInitiated(uint256 exchangeRequestId, address requester, address baseTokenAddress, uint256 baseTokenId, uint256 value)
Logs the exchange request ID, the requester's address, the base token address, the base token ID, and the value of tokens involved.
Represents the start of an exchange process.
ExchangeCompleted
solidity
event ExchangeCompleted(uint256 exchangeRequestId, address requester, address baseTokenAddress, uint256 baseTokenId, uint256 value)
Logs the exchange request ID, the requester's address, the base token address, the base token ID, and the value of tokens exchanged.
Represents the completion of an exchange operation.
ExchangeRefuted
solidity
event ExchangeRefuted(address depositor, uint256 exchangeRequestId)
Logs the address of the depositor and the ID of the exchange request being refuted.
Indicates the depositor's objection to an exchange request.
ExchangeCallersSet
solidity
event ExchangeCallersSet(address[] _exchangeCallers)
Logs the list of addresses authorized as exchange callers.
Updates the permissions for callers authorized to execute exchanges.
RefutationNullified
solidity
event RefutationNullified(address sender, uint256 exchangeRequestId)
Logs the sender's address and the ID of the exchange request being nullified.
Represents the cancellation of a refutation.
ExchangeNullified
solidity
event ExchangeNullified(address sender, uint256 exchangeRequestId)
Logs the sender's address and the ID of the exchange request being nullified.
Represents the cancellation of an exchange operation.
AttachmentAdded
solidity
event AttachmentAdded(string cid, address submitter)
Logs the IPFS Content Identifier (CID) of the attachment and the address of the submitter.
Allows attachments to be added as additional information for exchanges.
ExchangeInfoSet
solidity
event ExchangeInfoSet(enum TokenExchange1155.ExchangeType exchangeType, uint256 ratio, address baseTokenAddress, uint256 baseTokenId, address quoteTokenAddress, uint256 quoteTokenId)
Logs the exchange type, the exchange ratio, the base token's address and ID, and the quote token's address and ID.
Configures or modifies exchange-related information.
TokenExchange1155InvalidToken
solidity
error TokenExchange1155InvalidToken(address tokenAddress, string msg)
Logs the invalid token address and an accompanying error message.
Indicates that the provided token address is not valid for the exchange.
TokenExchange1155ActiveExchangeWindow
solidity
error TokenExchange1155ActiveExchangeWindow(uint256 exchangeWindowTill, uint256 requestTimestamp)
Logs the exchange window expiry time and the timestamp of the request.
Prevents exchanges within the defined active window.
TokenExchange1155InactiveExchangeWindow
solidity
error TokenExchange1155InactiveExchangeWindow(uint256 exchangeWindowTill, uint256 requestTimestamp)
Logs the exchange window expiry time and the timestamp of the request.
Prevents exchanges outside the active exchange window.
TokenExchange1155InsufficientBalance
solidity
error TokenExchange1155InsufficientBalance(uint256 balance, uint256 requested)
Logs the available balance and the requested amount.
Ensures adequate balance is available for exchanges.
TokenExchange1155ApprovalNotGranted
solidity
error TokenExchange1155ApprovalNotGranted(address tokenAddress, address owner, address operator)
Logs the token address, the owner's address, and the operator's address.
Requires approval for the operator to execute transactions.
TokenExchange1155UnauthorizedDepositor
solidity
error TokenExchange1155UnauthorizedDepositor(address sender, address depositor)
Logs the sender's address and the expected depositor's address.
Restricts token deposits to authorized depositors only.
TokenExchange1155InvalidExchangeType
solidity
error TokenExchange1155InvalidExchangeType(enum TokenExchange1155.ExchangeType expectedType)
Logs the expected exchange type.
Ensures exchanges are conducted with a valid type.
TokenExchange1155InvalidRatio
solidity
error TokenExchange1155InvalidRatio(uint256 _ratio)
Logs the invalid ratio value.
Validates the ratio parameter for exchanges.
TokenExchange1155InvalidExchangeRequest
solidity
error TokenExchange1155InvalidExchangeRequest(uint256 requestId)
Logs the invalid request ID.
Avoids duplicate or invalid exchange requests.
TokenExchange1155InactiveRefutationWindow
solidity
error TokenExchange1155InactiveRefutationWindow(uint256 refutationWindowTill, uint256 refuteTimestamp)
Logs the refutation window expiry time and the timestamp of the refutation attempt.
Ensures refutations occur within the valid window.
TokenExchange1155ActiveRefutationWindow
solidity
error TokenExchange1155ActiveRefutationWindow(uint256 refutationWindowTill, uint256 requestTimestamp)
Logs the refutation window expiry time and the timestamp of the request.
Prevents premature refutations during an active window.
TokenExchange1155InvalidRefutationWindow
solidity
error TokenExchange1155InvalidRefutationWindow(uint256 refutationWindowTill, uint256 requestTimestamp)
Logs the refutation window expiry time and the timestamp of the request.
Validates the configuration of the refutation window.
TokenExchange1155UnauthorizedResolver
solidity
error TokenExchange1155UnauthorizedResolver(address sender)
Logs the unauthorized sender's address.
Restricts resolution to authorized resolvers.
TokenExchange1155UnauthorizedRequester
solidity
error TokenExchange1155UnauthorizedRequester(address sender, address originalRequester)
Logs the sender's address and the original requester's address.
Restricts access to exchange requests to the original requester.
TokenExchange1155InvalidRefutationStatus
solidity
error TokenExchange1155InvalidRefutationStatus(uint256 exchangeRequestId)
Logs the ID of the exchange request.
Validates the refutation status before proceeding.
TokenExchange1155AttachmentAlreadyAdded
solidity
error TokenExchange1155AttachmentAlreadyAdded(string cid)
Logs the duplicate CID.
Ensures attachments are unique for exchanges.
TokenExchange1155ExchangeInfoAlreadyAdded
solidity
error TokenExchange1155ExchangeInfoAlreadyAdded()
Prevents duplicate setting of exchange information.
Ensures exchange information is not set more than once.
TokenExchange1155TransferFailed
solidity
error TokenExchange1155TransferFailed(address from, address to, address tokenAddress, uint256 tokenId, uint256 amount)
Logs the sender's address, the recipient's address, the token address, the token ID, and the amount attempted to transfer.
Indicates a failure during token transfer operations.
TokenExchange1155UnauthorizedExchangeCaller
solidity
error TokenExchange1155UnauthorizedExchangeCaller(address caller)
Logs the caller's address.
Restricts exchange operations to authorized callers only.
constructor
solidity
constructor(address _initialOwner, address _initialDepositor, string _erc1155Uri) public
Constructor to initialize the depositor and ERC-1155 URI.
This constructor initializes the contract with the initial owner and depositor. It also sets the ERC-1155 URI for the token, which contains metadata related to the token and its properties.
Parameters
Name | Type | Description |
---|---|---|
_initialOwner | address | Address of the initial owner of the contract. |
_initialDepositor | address | Address of the initial depositor. |
_erc1155Uri | string | URI for the ERC-1155 token metadata. Emits: - DepositorSet Emitted upon successfull setting depositor's address. |
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.
This function can only be called by the contract owner (depositor). It sets the parameters for both token-for-token and fiat-for-token exchange types, and validates the provided information before setting it.
Parameters
Name | Type | Description |
---|---|---|
_exchangeType | enum TokenExchange1155.ExchangeType | The type of exchange to be used: 0 for Token-for-token, 1 for Fiat-for-token. |
_ratio | uint256 | The exchange ratio, scaled to 10^18. This is required only for token-for-token exchange. |
_baseTokenAddress | address | The address of the base token, which is deposited by the depositor. |
_baseTokenId | uint256 | The ID of the base token to be deposited by the depositor. |
_quoteTokenAddress | address | The address of the quote token, which is used in the exchange. Required only for token-for-token exchanges. |
_quoteTokenId | uint256 | The ID of the quote token to be used in the exchange. Required only for token-for-token exchanges. |
_disputeResolver | address | The address of the account authorized to resolve refutations. Required only for fiat-for-token exchanges. |
_exchangeWindow | uint256 | The epoch time (in seconds) before which an exchange or exchange commencement can be initiated. |
_refutationWindow | uint256 | The time window (in seconds) during which the depositor can refute an exchange after it has commenced. Required only for fiat-for-token exchanges. Error: - TokenExchange1155ExchangeInfoAlreadyAdded : Reverted if token exchange info is already set. - TokenExchange1155InvalidRatio : Reverted if exchange ratio is set to zero(0). Emits: - ExchangeInfoSet : Emitted upon successfully setting up exchange information. |
deposit
solidity
function deposit(uint256 _value) external
Deposits ERC-1155 baseTokens into the contract and mints equivalent ERC-1155 tokens for the depositor.
This function allows the depositor to deposit ERC-1155 baseTokens into the contract. In return, the depositor receives an equivalent amount of minted ERC-1155 tokens.
Parameters
Name | Type | Description |
---|---|---|
_value | uint256 | The amount of the baseTokens (ERC-1155 tokens) to be deposited. Emits: - TokensDeposited : Emitted upon successful deposit of ERC-1155 baseTokens. |
withdraw
solidity
function withdraw(uint256 _value, address _to) external
Withdraws ERC-1155 baseTokens not undergoing an exchange after the exchange window has passed.
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-1155 tokens. Error: - TokenExchange1155ActiveExchangeWindow: Reverted if the withdrawal request is made before the exchange window has closed. - TokenExchange1155InsufficientBalance: Reverted if the requested withdrawal exceeds the available balance. Emits: - TokensWithdrawn: Emitted once the withdrawal is successful. |
addAttachment
solidity
function addAttachment(string _cid) external
Adds a new attachment to the contract.
_Adds a new attachment to the contract, associating a content identifier (CID) with the owner
Requirements:
- Only callable by depositor
- CID must not already exist_
Parameters
Name | Type | Description |
---|---|---|
_cid | string | Content identifier for the attachment Error: - TokenExchangeAttachmentAlreadyAdded : Reverted if there's an attempt to add an attachment that already exists. Emits: - AttachmentAdded : Emitted upon successful addition of attachment to the contract. |
whitelistExchangeCallers
solidity
function whitelistExchangeCallers(address[] _exchangeCallers) external
Whitelists a list of exchange callers, allowing them to perform exchange-related operations.
_This function allows the depositor to whitelist multiple addresses as exchange callers. The addresses added to the whitelist will be able to perform operations related to the exchange.
Requirements:
- The caller must be the owner of the contract._
Parameters
Name | Type | Description |
---|---|---|
_exchangeCallers | address[] | An array of addresses to be whitelisted as exchange callers. Emits: - ExchangeCallers : Emitted upon successful addition of exchange callers. |
exchange
solidity
function exchange(uint256 _quoteValue) external
Facilitates the exchange of quote tokens for base tokens according to the specified exchange ratio.
This function allows users to perform token-for-token exchanges. It checks that the exchange type is set to TOKEN_FOR_TOKEN
and verifies that the caller is whitelisted to perform the exchange. The function also ensures that the exchange is performed within the specified exchange window. Additionally, it verifies that the caller has granted the necessary approval for the contract to transfer quote tokens on their behalf. The amount of ERC-1155 base tokens to be exchanged is calculated based on the provided quote token amount and the exchange ratio.
Parameters
Name | Type | Description |
---|---|---|
_quoteValue | uint256 | Amount of the ERC-1155 quoteTokens to exchange from. Error: - TokenExchange1155InvalidExchangeType : Reverted if exchange type is not TOKEN_FOR_TOKEN. - TokenExchange1155UnauthorizedExchangeCaller : Reverted if caller is not whitelisted to perform the exchange. - TokenExchange1155InactiveExchangeWindow : Reverted if exchange is called after the exchange window is elapsed. - TokenExchange1155ApprovalNotGranted : Reverted if caller has not approved enough quoteToken for this exchange. Emits: - TokensExchanged : Emitted when the exchange is successful. |
initiateExchange
solidity
function initiateExchange(uint256 _baseValue) external
Initiates an exchange request for base tokens.
This function initiates a fiat-for-token exchange and stores the exchange request. It first checks that the caller is whitelisted to perform the exchange. The function also ensures that the exchange is initiated within the valid exchange window. It then checks if the depositor has sufficient available balance of the base tokens, excluding tokens already undergoing exchange. The request is stored in the exchangeRequests
mapping, and the depositUnderExchange
counter is updated accordingly.
Parameters
Name | Type | Description |
---|---|---|
_baseValue | uint256 | The amount of base tokens requested for exchange. Error: - TokenExchange1155UnauthorizedExchangeCaller : Reverted if caller is not whitelisted to perform exchange. - TokenExchange1155InactiveExchangeWindow : Reverted if exchange is called after the exchange window is elapsed. - TokenExchange1155InsufficientBalance : Reverted if available balance is less than calculated baseToken. - TokenExchange1155InvalidExchangeRequest : Reverted if the request id is invalid or not present. Emits: - ExchangeInitiated : Emitted when the exchange request is successfully initiated. |
refuteExchange
solidity
function refuteExchange(uint256 _exchangeRequestId) external
Allows the depositor to refute an exchange request.
Allows the depositor to refute a fiat-for-token exchange request.
Parameters
Name | Type | Description |
---|---|---|
_exchangeRequestId | uint256 | The unique identifier for the exchange request. Error: - TokenExchange1155InvalidExchangeRequest : Reverted if exchange request id does not exists. - TokenExchange1155InactiveRefutationWindow : Reverted if refutation window is elapsed. Emits: - ExchangeRefuted : Emitted when the exchange is succussfully refutated. |
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. Error: - TokenExchange1155UnauthorizedResolver : Reverted if the caller is neither depositor nor disputeResolver. - TokenExchange1155InvalidExchangeRequest : Reverted if exchange request id does not exists. - TokenExchange1155InvalidRefutationStatus : Reverted if exhcnage request is not refuted. Emits: - RefutationNullified : Emitted when the refutation of exchange is succussfully nullified. |
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. Error: - TokenExchange1155UnauthorizedResolver : Reverted if caller is not the disputeResolver. - TokenExchange1155InvalidExchangeRequest : Reverted if exchange request id does not exists. - TokenExchange1155InvalidRefutationStatus : Reverted if exchange is not already refuted. Emits: - ExchangeNullified : Emitted when the exchange is succussfully nullified. |
completeExchange
solidity
function completeExchange(uint256 _exchangeRequestId) external
Completes an exchange request by transferring the specified amount of baseToken
to the requester.
This function completes a fiat-for-token exchange once the refutation window has passed, and no active refutations are present. The exchange request is validated to ensure it exists, and is being completed by the original requester. The function ensures that the refutation window has elapsed. Upon successful completion, the exchange request is removed from storage, the depositUnderExchange
counter is updated, and the specified amount of baseToken
is transferred to the requester.
Parameters
Name | Type | Description |
---|---|---|
_exchangeRequestId | uint256 | The ID of the exchange request to be completed. Error: - TokenExchange1155InvalidExchangeRequest : Reverted if exchange request id does not exists. - TokenExchange1155UnauthorizedRequester : Reverted if caller is not the original request sender. - TokenExchange1155ActiveRefutationWindow : Reverted if refutation window has not elapsed. - TokenExchange1155InvalidRefutationStatus : Reverted if request is still refuted. Emits - ExchangeCompleted : Emitted when the exchange is successfully completed. |
safeTransferFrom
solidity
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes data) public
Safely transfers a single ERC-1155 token from one address to another, ensuring contract conditions are met.
This function overrides the safeTransferFrom
function from the ERC1155 standard. It performs the transfer and applies non-reentrancy checks for added security. The transfer only succeeds if the caller passes all necessary conditions. This is essential to maintain security in functions where reentrancy could lead to errors. The function internally calls the safeTransferFrom
function of the parent ERC1155 contract.
Parameters
Name | Type | Description |
---|---|---|
from | address | The address from which to transfer the token. |
to | address | The address to which the token will be transferred. |
id | uint256 | The ID of the token to transfer. |
value | uint256 | The amount of tokens to transfer. |
data | bytes | Additional data passed with the transfer (unused in this implementation). Error: - PaymentCommitmentUnauthorizedCollateralTransfer : Reverted if the transfer is unauthorized based on the contract's state. |
safeBatchTransferFrom
solidity
function safeBatchTransferFrom(address from, address to, uint256[] ids, uint256[] values, bytes data) public
Safely transfers a batch of ERC-1155 tokens from one address to another.
This function overrides the safeBatchTransferFrom
function from the ERC1155 standard. It transfers multiple tokens in a single transaction and ensures that the contract's conditions are respected. Non-reentrancy checks are applied to prevent reentrancy attacks during token transfer. The function calls the safeBatchTransferFrom
function from the parent ERC1155 contract to process the batch transfer.
Parameters
Name | Type | Description |
---|---|---|
from | address | The address from which to transfer the tokens. |
to | address | The address to which the tokens will be transferred. |
ids | uint256[] | The IDs of the tokens to transfer. |
values | uint256[] | The amounts of tokens to transfer. |
data | bytes | Additional data passed with the transfer (unused in this implementation). Error: - PaymentCommitmentUnauthorizedCollateralTransfer : Reverted if any token transfer is unauthorized based on the contract's state. |
onERC1155Received
solidity
function onERC1155Received(address, address, uint256, uint256, bytes) external pure returns (bytes4)
Handles the receipt of a single ERC-1155 token transfer. This function is called when a single ERC-1155 token is transferred to an address that implements this interface.
This function simply returns the function selector to confirm receipt of the ERC-1155 token. It is called by the ERC1155 contract to confirm whether the receiving contract can accept the transfer. This implementation does not perform any additional actions (no-op).
Parameters
Name | Type | Description |
---|---|---|
address | ||
address | ||
uint256 | ||
uint256 | ||
bytes |
Return Values
Name | Type | Description |
---|---|---|
[0] | bytes4 | bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)")) if transfer is allowed |
onERC1155BatchReceived
solidity
function onERC1155BatchReceived(address, address, uint256[], uint256[], bytes) external pure returns (bytes4)
Handles the receipt of a batch of ERC-1155 token transfers. This function is called when a batch of ERC-1155 tokens is transferred to an address that implements this interface.
This function simply returns the function selector to confirm receipt of the ERC-1155 token batch. It is called by the ERC1155 contract to confirm whether the receiving contract can accept the batch transfer. This implementation does not perform any additional actions (no-op).
Parameters
Name | Type | Description |
---|---|---|
address | ||
address | ||
uint256[] | ||
uint256[] | ||
bytes |
Return Values
Name | Type | Description |
---|---|---|
[0] | bytes4 | bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)")) if transfer is allowed |
onlyDepositor
solidity
modifier onlyDepositor()
Ensures that only the depositor can interact with the function.
_This modifier restricts access to functions by checking that the sender of the transaction is the depositor of the contract.
Error:
TokenExchange1155UnauthorizedDepositor
: Reverted if sender is not the depositor_
_isCompatibleERC1155
solidity
function _isCompatibleERC1155(address _token) internal
Validates whether the provided token address is a compatible ERC-1155 contract.
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. Error: - TokenExchange1155InvalidToken : Reverted if - address is not a contract - missing allowance function - missing safeTransferFrom function |