ODCdataobjectsomnichain

OmnichainNonFungibleTokenDO

DataObject with base functionality of a non-fungible cross-chain token

_This contract exposes base functionality of a omnichain non-fungible token, allowing to mint, burn, transfer (locally and cross-chain), check balances and owners.

 NOTE: This contract does not emit token events, it is expected that the DataManager contract will
 emit the events for the token operations

 This implementation only allow minting tokens with chainId in the highest 32 bits to prevent duplicate token ids
 on different chains.
 The owner of the token is set to address(1) when the token is transferred to another chain to prevent double
 minting of the token on origin chain._

ExpectedAndActualRequestIdDoNotMatch

error ExpectedAndActualRequestIdDoNotMatch(bytes32 expectedRequestId, bytes32 actualRequestId)

Error thrown when the expected and actual request IDs do not match

Parameters

NameTypeDescription
expectedRequestIdbytes32The expected request ID (GUID)
actualRequestIdbytes32The actual request ID (GUID)

InvalidRequestId

error InvalidRequestId(bytes32 rid)

Error thrown when a call to retry omnichain increase balance is provided with wrong or already deleted request id

Parameters

NameTypeDescription
ridbytes32The request ID (GUID) to retry

IncreaseBalanceCallbackHandlerFailed

error IncreaseBalanceCallbackHandlerFailed(address handler, address receiver, uint256 tokenId)

Error thrown when call to handler failed

Parameters

NameTypeDescription
handleraddressAddress of the handler
receiveraddressAddress of the receiver of token
tokenIduint256Id of token

NotEnoughGasForBalanceHandlers

error NotEnoughGasForBalanceHandlers()

Error thrown when we do not have enough gas left to call Balance Handler Callbacks

ZeroAddressHandler

error ZeroAddressHandler()

Error thrown when the handler is the zero address

HandlerAlreadyRegistered

error HandlerAlreadyRegistered()

Error thrown when handler couldn't be added.

HandlerNotRemoved

error HandlerNotRemoved()

Error thrown when handler couldn't be removed.

OmnichainTransferRefund

event OmnichainTransferRefund(bytes32 rid, DataPoint dp, OmnichainAddress from, address to, uint256 tokenId)

Event emitted when an omnichain transfer is refunded

Parameters

NameTypeDescription
ridbytes32The request ID (GUID)
dpDataPointDataPoint identifier
fromOmnichainAddressAddress where tokens were taken from
toaddressAddress which received refund (refund address provided with original transaction)
tokenIduint256Id of token refunded

OmnichainTransferFailedRefund

event OmnichainTransferFailedRefund(bytes32 rid, DataPoint dp, OmnichainAddress from, address to, uint256 tokenId, address actualRefundTarget, bool refundAccepted)

Event emitted when an omnichain transfer refunded is required but was not accepted by provided refundAddress

if refundAccepted is false, that means ERC-721 was formally violated, some actions by DM (actualRefundTarget) are probably required to handle this correctly

Parameters

NameTypeDescription
ridbytes32The request ID (GUID)
dpDataPointDataPoint identifier
fromOmnichainAddressAddress where tokens were taken from
toaddressAddress which should have received refund (refund address provided with original transaction)
tokenIduint256Id of the token refunded
actualRefundTargetaddressAddress finally used for refund (its balance was actually increased)
refundAcceptedboolIf actualRefundTarget accepted refund, if false - it means balance was increased but no Transfer event emitted and onERC1155Received call was reverted

OmnichainTransferSent

event OmnichainTransferSent(bytes32 rid, uint32 chainid, address target, uint256 tokenId)

Event emitted when an omnichain transfer is sent

Data (rid) from this event can be used for retry

Parameters

NameTypeDescription
ridbytes32The request ID (GUID)
chainiduint32The target chain ID
targetaddressThe target address
tokenIduint256Id of token sent

OmnichainRetryIncompleteOmnichainIncreaseBalanceSent

event OmnichainRetryIncompleteOmnichainIncreaseBalanceSent(bytes32 originalRid, bytes32 retryRequestRid)

Event emitted when an incomplete omnichain increase balance request is retried

Parameters

NameTypeDescription
originalRidbytes32The original request ID (GUID)
retryRequestRidbytes32The retry request ID (GUID)

OmnichainIncreaseBalanceHandlerRegistered

event OmnichainIncreaseBalanceHandlerRegistered(address handler, bool added)

Event emitted when an omnichain increase balance handler is registered

Parameters

NameTypeDescription
handleraddressThe handler address
addedboolTrue if the handler was added, false if removed

CallResult

Enum for call result

Parameters

NameTypeDescription
enum CallResult {
  NONE,
  SUCCESS,
  FAILURE
}

DpData2

Data structure for storing omnichain increase balance handlers

Parameters

NameTypeDescription
struct DpData2 {
  struct EnumerableSet.AddressSet omnichainIncreaseBalanceHandlers;
}

PendingOmnichainTransfer

Data structure for storing pending omnichain transfers for retry or refund

Parameters

NameTypeDescription
struct PendingOmnichainTransfer {
  DataPoint dp;
  OmnichainAddress from;
  OmnichainAddress to;
  uint256 tokenId;
  address refundAddress;
}

IncreaseBalanceQueryParams

Data structure for storing parameters for increase balance query

Parameters

NameTypeDescription
struct IncreaseBalanceQueryParams {
  DataPoint dp;
  OmnichainAddress from;
  OmnichainAddress to;
  uint256 tokenId;
  address payable refundAddress;
  bytes32 nextRequestId;
  uint32 toChainId;
}

retryIncompleteOmnichainIncreaseBalance

function retryIncompleteOmnichainIncreaseBalance(bytes32 rid, address payable refundAddress) external payable

Retry sending incomplete omnichain increase balance request

Parameters

NameTypeDescription
ridbytes32Request ID of failed message (GUID)
refundAddressaddress payableWhere to send refund

buildTokenId

function buildTokenId(uint32 chainId, uint224 tokenId) public pure returns (OmnichainIdentifier)

Function to build the Omnichain Identifier

Parameters

NameTypeDescription
chainIduint32Chain ID
tokenIduint224Token ID

Return Values

NameTypeDescription
[0]OmnichainIdentifierOmnichain Identifier

callIncreaseBalanceHandlersAndRevertOnFail

function callIncreaseBalanceHandlersAndRevertOnFail(DataPoint dp, OmnichainAddress from, address toAddress, uint256 tokenId) external

Function only callable by the same contract to call increase balance handlers and revert on fail

_dispatchWrite

function _dispatchWrite(DataPoint dp, bytes4 operation, bytes data) internal virtual returns (bytes)

_mint

function _mint(DataPoint dp, address to, uint256 tokenId) internal

Operation used to mint new token

Overridden to prevent minting tokens with wrong chainId in the highest 32 bits

Parameters

NameTypeDescription
dpDataPointDataPoint identifier
toaddressThe account address to mint the token to
tokenIduint256The tokenId of token to mint

_registerOmnichainIncreaseBalanceHandler

function _registerOmnichainIncreaseBalanceHandler(DataPoint dp, address handler) internal

Internal operation to register an omnichain increase balance handler

Parameters

NameTypeDescription
dpDataPointDataPoint identifier
handleraddressAddress of the handler to register NOTE: The handler MUST implement the IOmnichainNonFungibleTokenIncreaseBalanceCallback interface

_unregisterOmnichainIncreaseBalanceHandler

function _unregisterOmnichainIncreaseBalanceHandler(DataPoint dp, address handler) internal

Internal operation to unregister an omnichain increase balance handler

Parameters

NameTypeDescription
dpDataPointDataPoint identifier
handleraddressAddress of the handler to unregister

_omnichainTransfer

function _omnichainTransfer(DataPoint dp, OmnichainAddress from, OmnichainAddress to, uint256 tokenId, address payable refundAddress) internal returns (bytes32)

Internal operation used to transfer tokens to another chain

Parameters

NameTypeDescription
dpDataPointDataPoint identifier
fromOmnichainAddressAddress where to take token from (on current chain)
toOmnichainAddressAddress to send token to
tokenIduint256Id of token to send
refundAddressaddress payableWhere to send refund NOTE: Native Coin payment for sending omnichain tx should be sent with the call

_omnichainIncreaseBalance

function _omnichainIncreaseBalance(DataPoint dp, bytes32 rid, OmnichainAddress from, OmnichainAddress to, uint256 tokenId) internal returns (bytes)

Internal operation used to increase the balance of a target account

Parameters

NameTypeDescription
dpDataPointDataPoint identifier
ridbytes32Request ID (GUID)
fromOmnichainAddressOmnichain Address token transferred from (used to emit correct event)
toOmnichainAddressOmnichain Address to send token to
tokenIduint256Id of the token NOTE: This function SHOULD be called only by the other-chain DataObject to transfer tokens to someone on this chain which MUST decrease the balance of the user in the origin chain and increase the balance of the target account in the current chain

_omnichainCallback

function _omnichainCallback(bytes32 rid, bytes data) internal

Callback function for omnichain operations

Parameters

NameTypeDescription
ridbytes32Request ID of the message (GUID)
databytesData received in the callback

_increaseOmnichainBalance

function _increaseOmnichainBalance(DataPoint dp, OmnichainAddress from, OmnichainAddress to, uint256 tokenId, address payable refundAddress) internal returns (bytes32)

Function used to increase balance on another chain

_retryIncreaseOmnichainBalance

function _retryIncreaseOmnichainBalance(bytes32 rid, address payable refundAddress) internal

_handleNativePaymentInWrite

function _handleNativePaymentInWrite() internal

Empty to allow native coin payment in write()

_dpData2

function _dpData2(DataPoint dp) internal returns (struct OmnichainNonFungibleTokenDO.DpData2)