ODCdataobjectsomnichain

OmnichainFungibleTokenDO

DataObject with base functionality of a fungible cross-chain token

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

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

InsufficientBalance

error InsufficientBalance(bytes32 diid, uint256 balance, uint256 amount)

Error thrown when the balance is insufficient

Parameters

NameTypeDescription
diidbytes32The owner identifier
balanceuint256The current balance
amountuint256The requested amount

InsufficientTotalSupply

error InsufficientTotalSupply(uint256 totalSupply, uint256 amount)

Error thrown when the total supply is insufficient

Parameters

NameTypeDescription
totalSupplyuint256The current total supply
amountuint256The requested amount NOTE: This should never happen because we've already checked "from" balance

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)

NativePaymentNotAllowed

error NativePaymentNotAllowed()

Error thrown when the native payment is not allowed for the operation

HandlerAlreadyRegistered

error HandlerAlreadyRegistered()

Error thrown when handler couldn't be added.

HandlerNotRemoved

error HandlerNotRemoved()

Error thrown when handler couldn't be removed.

ZeroAddressHandler

error ZeroAddressHandler()

Error thrown when the handler is the zero address

IncreaseBalanceCallbackHandlerFailed

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

Error thrown when call to handler failed

Parameters

NameTypeDescription
handleraddressAddress of the handler
receiveraddressAddress of the receiver of the tokens
amountuint256Amount of tokens

OmnichainTransferRefund

event OmnichainTransferRefund(bytes32 rid, DataPoint dp, address from, uint256 amount)

Event emitted when an omnichain transfer is refunded

Parameters

NameTypeDescription
ridbytes32The request ID (GUID)
dpDataPointDataPoint identifier
fromaddressAddress where tokens were taken from
amountuint256The amounts of tokens refunded

OmnichainTransferSent

event OmnichainTransferSent(bytes32 rid, OmnichainAddress to, uint256 amount)

Event emitted when an omnichain transfer is sent

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

Parameters

NameTypeDescription
ridbytes32The request ID (GUID)
toOmnichainAddressThe target Omnichain Address
amountuint256The amount 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
}

PendingOmnichainTransfer

Data structure for pending omnichain transfer

Parameters

NameTypeDescription
struct PendingOmnichainTransfer {
  DataPoint dp;
  OmnichainAddress from;
  OmnichainAddress to;
  uint256 amount;
}

DpData

Data structure for Fungible Token data

Parameters

NameTypeDescription
struct DpData {
  uint256 localTotalSupply;
  struct EnumerableSet.AddressSet omnichainIncreaseBalanceHandlers;
}

DiidData

Data structure for Data Index id data

Parameters

NameTypeDescription
struct DiidData {
  uint256 balance;
}

constructor

constructor() public

onDataPointTransfer

function onDataPointTransfer(DataPoint dp, bytes32 fromDiid, bytes32 toDiid) external

Transfers data from one id to another

onDataPointTransfer in this implementation does nothing

Parameters

NameTypeDescription
dpDataPointIdentifier of the DataPoint
fromDiidbytes32ID to transfer from
toDiidbytes32ID to transfer to

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

callIncreaseBalanceHandlersAndRevertOnFail

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

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

_dispatchRead

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

_dispatchWrite

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

_balanceOf

function _balanceOf(DataPoint dp, address account) internal view returns (uint256)

Function used to get the balance of an account

Parameters

NameTypeDescription
dpDataPointDataPoint identifier
accountaddressThe account address

Return Values

NameTypeDescription
[0]uint256The balance of the account

_totalSupply

function _totalSupply(DataPoint dp) internal view returns (uint256)

Function used to get the total supply of the token

Parameters

NameTypeDescription
dpDataPointDataPoint identifier

Return Values

NameTypeDescription
[0]uint256The total supply of the token

_mint

function _mint(DataPoint dp, address to, uint256 amount) internal virtual

Function used to mint new tokens

Parameters

NameTypeDescription
dpDataPointDataPoint identifier
toaddressThe account address to mint the tokens to
amountuint256The amount of tokens to mint

_burn

function _burn(DataPoint dp, address from, uint256 amount) internal virtual

Function used to burn tokens

Parameters

NameTypeDescription
dpDataPointDataPoint identifier
fromaddressThe account address to burn the tokens from
amountuint256The amount of tokens to burn

_transfer

function _transfer(DataPoint dp, address from, address to, uint256 amount) internal virtual

Function used to transfer tokens

Parameters

NameTypeDescription
dpDataPointDataPoint identifier
fromaddressThe account address to transfer the tokens from
toaddressThe account address to transfer the tokens to
amountuint256The amount of tokens to transfer

_registerOmnichainIncreaseBalanceHandler

function _registerOmnichainIncreaseBalanceHandler(DataPoint dp, address handler) internal

Function to register an omnichain increase balance handler

Parameters

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

_unregisterOmnichainIncreaseBalanceHandler

function _unregisterOmnichainIncreaseBalanceHandler(DataPoint dp, address handler) internal

Function to unregister an omnichain increase balance handler

Parameters

NameTypeDescription
dpDataPointDataPoint identifier
handleraddressAddress of the handler to unregister

_omnichainTransfer

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

Operation used to transfer tokens to another chain

Parameters

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

_increaseOmnichainBalance

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

Function used to increase balance on another 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

_retryIncreaseOmnichainBalance

function _retryIncreaseOmnichainBalance(bytes32 rid, address payable refundAddress) internal

_omnichainIncreaseBalance

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

Internal operation used to increase the balance of a target account

Parameters

NameTypeDescription
dpDataPointDataPoint identifier
ridbytes32Request ID (GUID)
fromOmnichainAddressOmnichain Address tokens transferred from (used to emit correct event)
toOmnichainAddressOmnichain Address to send tokens to
amountuint256Amount of tokens to send 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

_handleNativePaymentInWrite

function _handleNativePaymentInWrite() internal

Empty to allow native coin payment in write()

_dpData

function _dpData(DataPoint dp) internal returns (struct OmnichainFungibleTokenDO.DpData)

_diidData

function _diidData(DataPoint dp, bytes32 diid) internal returns (struct OmnichainFungibleTokenDO.DiidData)

_tryDpData

function _tryDpData(DataPoint dp) internal view returns (bool success, struct OmnichainFungibleTokenDO.DpData)

_tryDiidData

function _tryDiidData(DataPoint dp, bytes32 diid) internal view returns (bool success, struct OmnichainFungibleTokenDO.DiidData)