On this page

latest contributor to this doc

Last Edit:

@gcharang

Common Structures

overviewcommon_structures

The objects are in the request or response of multiple Komodo DeFi SDK methods have been grouped into the following sections:

  • Activation Common Structures: Details on activation modes, parameters, and server configurations for various coin types.
  • Enums: Enumerated values used across multiple methods, such as swap types, order statuses, and key policies.
  • Lightning Common Structures: Objects for Lightning Network operations, including channel and payment configurations.
  • NFT Common Structures: Structures for non-fungible token (NFT) operations, filters, and metadata.
  • Order Common Structures: Structures for orderbook entries, order data, and related parameters.
  • Swap Common Structures: Objects and events related to atomic swaps, including event types and swap status.
    • Maker Events: Step-by-step events and outcomes for atomic swaps from the maker's perspective.
    • Taker Events: Step-by-step events and outcomes for atomic swaps from the taker's perspective.
  • Wallet Common Structures: Structures for wallet operations, address derivation, balances, and key management.

Structures which are used in more than one section are listed below:

The EventStreamConfig object defines which events will be streamed to the client:

Parameter* = requiredTypeDescription
access_control_allow_origin
string
Optional. Defines CORS whitelist. Use "*" to allow from any origin.
worker_path
string
Optional. WASM only. Path to a custom worker.js file.

Configurable events, and how to enable them, is detailed in the streaming methods doc

An example of the event stream output can then be viewed in https://github.com/KomodoPlatform/komodo-defi-framework/blob/main/examples/sse/index.html?id=CLIENT_ID

The CLIENT_ID value used in the url must match the client_id value used when enabling streaming events. In the case of a single client only, defining the client_id is not required (it will default to 0).

{
    "access_control_allow_origin": "*",
    "worker_path": "index.js"
}

The 'FilterCriteria' object allows you to filter the results based on specific parameters.

Parameter* = requiredTypeDescription
denom*
string (numeric)
The denominator of the fractional value.
numer*
string (numeric)
The numerator of the fractional value.

{
  "filter": {
    "status": "completed",
    "date_from": "2024-01-01T00:00:00Z",
    "date_to": "2024-07-01T00:00:00Z",
    "my_coin": "BTC",
    "other_coin": "ETH",
    "from_timestamp": 1672531200,
    "to_timestamp": 1704067200
  }
}

The FractionalValue object includes a numerator and denominator values for a given price or amount:

Parameter* = requiredTypeDescription
decimal*
numeric string
A decimal number as a string.
fraction*
object
A standard FractionalValue object.
rational*
object
A standard RationalValue object.
{
    "numer": "4561782244811",
    "denom": "4000000"
}

The NumericFormatsValue returns a price or amount in three different formats: fraction, rational, and decimal.

Parameter* = requiredTypeDescription
from_uuid
string (or null)
default: null
Optional. Skips records until this UUID, excluding the record with this UUID. Convenient for infinite scrolling implementations.
limit
number
Optional. Limits the number of returned swaps.
page_number
number
Optional. Returns limit swaps from the selected page. This parameter is ignored if from_uuid is set.
{
  "decimal": "0.0001",
  "rational": [
    [1, [1]],
    [1, [10000]]
  ],
  "fraction": {
    "numer": "1",
    "denom": "10000"
  }
}

The PagingOptions object includes options of page selection to consult when looking for recent swaps:

Parameter* = requiredTypeDescription
FromId
integer
Optional. Ignores any results prior to this UUID
PageNumber
integer
default: 1
Optional. Offset for paginated results

{
  "paging_options": {
    "from_uuid": null,
    "limit": 10,
    "page_number": 1
  }
}

For requests which return many results, pagination offsets may be applied. ** Use either value, not both. **

Parameter* = requiredTypeDescription
always_send
boolean
default: false
Optional. stream::network::enable only. If true, network data will always be sent every stream_interval_seconds, even when there is no change. If false, network data will be sent regardless.
stream_interval_seconds
float
default: 10/5
Optional, defaults to 10/5. Interval in seconds between streaming event update requests. Defaults to 10 for stream::balance::enable and 5 for stream::network::enable/stream::heartbeat::enable

{
    "PageNumber": 1
}
{
    "FromId": 4
}

The Komodo DeFi SDK now offers the num-rational crate feature which allows for higher precision numeric values to represent order volumes and prices in a unique format as explained below:

[
  [1, [0, 1]],
  [1, [1]]
]

In the above unique format, the first item [1,[0,1]] is the numerator and the second item [1,[1]] is the denominator.

The numerator and denominator are BigInteger numbers represented as a sign and a uint32 array (where numbers are 32-bit parts of big integer in little-endian order).

[1,[0,1]] represents +0000000000000000000000000000000010000000000000000000000000000000 = 4294967296

[-1,[1,1]] represents -1000000000000000000000000000000010000000000000000000000000000000 = -4294967297

You can optionally apply more detailed configuration to event streaming methods.

Parameter* = requiredTypeDescription
estimate_every
float
default: 15
Optional. Interval in seconds between fee estimate updates.
estimate_type
string
default: Simple
Optional. If set to Provider, users must set the gas_api setting in their MM2.json file to source recommended fee values from third party providers Infura or Blocknative Used in get_eth_estimated_fee_per_gas only.

{
    "stream_interval_seconds": 33.3
}

Parameter* = requiredTypeDescription
additional_info*
object
A standard SyncStatusExtended object. Additional info that helps to track the progress; present for InProgress and Error states only.
state*
string
Current state of sync; possible values: NotEnabled, NotStarted, InProgress, Error, Finished

{
    "estimate_every": 33.3,
    "estimate_type": "Provider"
}

Parameter* = requiredTypeDescription
blocks_left
number
Optional. Present for ETH/ERC20 coins only; displays the number of blocks left to be processed for InProgress state
code
number
Optional. Displays the error code for Error state
message
number
Optional. Displays the error message for Error state
transactions_left
number
Optional. Present for UTXO coins only; displays the number of transactions left to be processed for InProgress state

Parameter* = requiredTypeDescription
chains*
list of strings
A list of chain IDs. For EIP155, refer to https://chainid.network/. For Cosmos, refer to https://cosmos.directory/
events*
list of strings
A list of events to track during the connection. For EIP155, refer to https://docs.reown.com/advanced/providers/ethereum#events. For Cosmos, refer to https://tutorials.cosmos.network/academy/2-cosmos-concepts/10-events.html
methods*
list of strings
A list of approved methods, usable while connected. For EIP155, refer to https://docs.reown.com/advanced/multichain/rpc-reference/ethereum-rpc. For Cosmos, refer to https://docs.reown.com/advanced/multichain/rpc-reference/cosmos-rpc

{
    "sync_status": {
      "state": "NotStarted"
    }
}
{
    "sync_status": {
      "additional_info": {
        "transactions_left": 126
      },
      "state": "InProgress"
    }
}
{
    "sync_status": {
      "state": "Finished"
    }
}

The WcConnNs object contains details of approved chains, methods and events while connected via WalletConnect.

Parameter* = requiredTypeDescription
expiry*
integer
A timestamp in unix epoch format indicating when the connection will expire if not otherwise closed.
metadata*
object
Arbitrary data returned from the external wallet/dapp on connection.
namespaces*
object
Contains the same two WcConnNs objects for Cosmos/EIP155 which were input when initialising the connection via wc_new_connection.
pairing_topic*
string
The pairing topic hex string, used for the initial external wallet/dapp connection.
topic*
string
The session topic hex string, used to identify the session for communications with the external wallet/dapp.

{
	"chains": [
		"eip155:1",      // ETH
		"eip155:56",     // BNB
		"eip155:137",    // POLYGON
		"eip155:43114"   // AVAX
	],
	"methods": [
		"eth_sendTransaction",
		"eth_signTransaction",
		"personal_sign"
	],
	"events": [
		"accountsChanged",
		"chainChanged"
	]
}

{
	"chains": [
		"cosmos:cosmoshub-4",
		"cosmos:osmosis-1",
		"cosmos:irishub-1"
	],
	"methods": [
	  	"cosmos_signDirect",
		  "cosmos_signAmino",
		  "cosmos_getAccounts"
	],
	"events": []
}

The WcSession object contains details of active WalletConnect sessions.

Parameter* = requiredTypeDescription
error*
string
A human-readable error message.
error_data*
object
Additional data related to the error.
error_path*
string
The path in the code where the error occurred.
error_trace*
string
A stack trace of the error.
error_type*
string
The type of the error.

Within each session object, there are a some values which are required as input in other WalletConnect methods:

  • pairing_topic: Only used when initally connecting with external wallets/dapps.
  • topic: Once connected, this is use for communications with the connected external wallet/dapp.

Parameter* = requiredTypeDescription
error*
string
A human-readable error message.
error_data*
object
Additional data related to the error.
error_path*
string
The path in the code where the error occurred.
error_trace*
string
A stack trace of the error.
error_type*
string
The type of the error.