Cosmos Ecosystem Blog

Cosmos is the internet of blockchains - an ever-expanding ecosystem of interconnected, blockchain-based apps and services. Powered by the Interchain Stack, Cosmos boasts over 100 IBC-enabled chains.

Follow publication

Introducing: Microtick on Cosmos, powered by Tendermint

--

Microtick is a decentralized price oracle for Cosmos / Tendermint that will supply free real-time price feeds to any Dapp that needs real-world price data over the IBC protocol. It does this through decentralized market-based trading — and in the process, provides a novel method for achieving price discovery on nearly any asset. All of the important details behind Microtick can be found at www.microtick.com.

During our journey building the DApp on Cosmos, we’ve uncovered some lessons that may helpful for the broader ecosystem. But first, a brief bit of context on what Microtick is. (We’ll be providing a much more in-depth overview in the near future).

Decentralized Price Discovery

Microtick is a decentralized price oracle. Its pricing data stems from a marketplace for short-term options. The roles you play on the Microtick zone vary depending on your objectives:

1. MARKET MAKER

Your Incentive: As a market maker you can make money by providing accurate and real-time price estimates and keeping them updated.

Benefit: You will help the global network achieve a more accurate price estimate by adding your token backing and unique information to the consensus estimates.

2. TRADER

Your Incentive: As a trader you can make money by identifying short-term trading or hedging opportunities and trading malicious, misplaced, or neglected data quotes off the market and collecting their token backing.

Benefit: You help the global network by removing stale market maker quotes and rapidly responding to inaccurate ones in order to lock in short-term profit.

3. AS A VALIDATOR

Your Incentive: As a Cosmos validator you make money by collecting the commissions market makers and traders pay for quotes and trades.

Benefit: Help the global network by contributing to Tendermint / Cosmos BFT consensus and providing Cosmos IBC data access to others in the Cosmos ecosystem.

The Microtick marketplace generates a large number of transactions and quotes, it represents a challenge to implement a scalable product in the blockchain space. For example, Ethereum can’t come close to handling the number of transactions per second that Microtick would generate with even a small amount of price markets operating. In addition, a large amount of transactional state changes comes blockchain bloat, leading to high resource costs for nodes on the chain.

Tendermint was a perfect fit for Microtick because of two properties: fast finality and chain sovereignty. The Cosmos SDK adds important features necessary for Dapps: transaction authentication, state management and state export. These are important topics to cover but are also out of scope for this post.

Client / Server API Architecture

OK — now that you have some context, let’s focus on how we designed and built an API layer for Microtick to create a toolkit for automated market makers and traders to access the backend Microtick Dapp. This is all possible without exposing Tendermint ports or internal data structures and hopefully creates a more robust and scalable system architecture.

Figure 1. Microtick Client / Server Architecture

Figure 1 shows the system diagram for a single Tendermint node running on the Microtick chain. The Microtick Dapp (1) runs on the Cosmos SDK and communicates with Tendermint Core (2) over ABCI in the standard manner. The Dapp inherits most of the standard Cosmos SDK modules (auth, staking, distribution, etc.) and implements a set of custom queries as well as transactions specific to Microtick.

When a transaction is handled by the Cosmos SDK, the Dapp has the option of tagging the results, as well as attaching data to the transaction result. These transactions and results are passed to Tendermint in what looks at first like base64 encoded data, but are actually encoded using an encoder / decoder called Amino. We won’t cover the Amino encoding format here, but there’s an active project that can build an encoder / decoder for custom transactions for Dapps written with Cosmos SDK here: https://github.com/cosmos/amino-js.

An example Microtick transaction with the Tx, tags and results is shown below. The Result Tags fields are what allows a Tendermint search to work. By searching for a specific tag or set of tags, for example mtm.MarketTick=’ATOMUSD’, all transactions in the blockchain history that match that tag will come up in the search results. Searches in Tendermint are flexible, but can take some time depending on the node’s load and other factors.

In addition to searches, Result Tags are what allows a Tendermint client to subscribe to transaction events. However, because subscription events are asynchronous (they can happen at any time), a different connection type is necessary. Tendermint uses a websocket connection for subscriptions.

Finally, a Cosmos SDK based Dapp like Microtick implements custom queries. An example Microtick query is shown below.

Note that a client submitting Tx’s or issuing queries does not talk to the Cosmos SDK Dapp directly. Tendermint has an RPC interface, usually on port 26657, for handling this. Specifically:

  • Transactions are broadcast using the broadcast_tx calls
  • Dapp queries are handled with the abci_query call
  • History searches are handled with the tx_search call
  • Events are handled over a websocket connected to with the websocket call

It is considered bad security practice to open up the Tendermint RPC port to the outside world, so for the Microtick API we needed to create a new functional piece of the system to handle external connections. In the diagram of Figure 1, the API server (3) and API client (4) that runs inside a browser or market maker or trader bot combine to create a communication protocol to handle external connections.

The API client running in the browser presents a uniform API that handles an abstraction layer that makes it easy to work with the various calls necessary to interface with the Microtick Dapp. These API calls are transmitted to the API server over a custom protocol (in the future we may use a standard like JSON-RPC). The API server then connects to the Tendermint node to handle internal communication.

The Microtick API client also includes a Javascript Cosmos wallet implementation (5) that originated here https://github.com/okwme/js-cosmos-wallet but is slightly modified to use javascript instead of typescript. The API client developer can easily create a new wallet or reuse an existing wallet using API calls. Note that the developer, not the API, is responsible for handling private keys, including encryption and storage.

The API client / server topology offers the following advantages:

  • Tendermint RPC (a) and websocket (b) communication are isolated from outside calls.
  • ABCI queries to the Microtick Dapp © are isolated as well.
  • Queries are cached on a per-block basis, so common calls like getBlockNumber() can use cached results if the block number has not changed. The API server handles a per-block cache that gets emptied with each new block.
  • Similarly, websocket events can be multiplexed over the same connection and event subscriptions are managed so if multiple browser clients each subscribe to the same event, only a single Tendermint subscription is issued.
  • For now each subscription is issued to Tendermint over its own websocket because if an error happens and the subscription is dropped, there is no subscription number in the error message so there is no way to know which subscription got dropped if you have more than one subscription on a websocket. The API server isolates these implementation specific issues from the client.

One final advantage adding an additional layer between Tendermint and the outside world is we can now implement transaction caching. We include an interface to a Mongo database server (6 — supplied separately) that allows transactions to be processed and stored in a manner that is much more scalable and UX friendly.

If the database is not synced to the blockchain when the API server is started, a sync process is started in the background that accesses historical blocks and continues until the current block height is reached (d). Once synced, standard queries can be processed much more rapidly and without loading the Tendermint node (e).

In the system architecture diagram of Figure 1, the system components in gray (API Server, the API Client portion of the browser GUI, and the browser-based Cosmos wallet code for Tx signing) are implemented in javascript and open sourced under the MIT License at https://gitlab.com/microtick/mtapi.

About Microtick

Microtick was originally founded in 2003. The founders had an idea for a new option product standardized in a unique manner to allow for market-based execution of shorter-term at-the-money options — at the expense of having a secondary market available to close positions.

With the advent of blockchain technology and starting originally with Ethereum, Microtick was pivoted to create a decentralized oracle:

  • Option premiums (with uncertainty built in) are a great fit for blockchain technology where transaction timing can be unpredictable and tiny geographic differences in prices give rise to front running in traditional order books.
  • The market mechanics and real-time implied underlying price we originally envisioned is actually an excellent system for importing a price feed to a blockchain in a decentralized fashion.
  • Decoupling price discovery from actual trade execution has benefits that reach far beyond blockchain technology.

Microtick is now running exclusively on Tendermint using Cosmos SDK. For more information on Microtick see our website at microtick.com or try out the testnet at microtick.zone. Our telegram channel is https://t.me/microtick_general.

The views and details expressed in this blog post are those of All In Bits Inc (dba Tendermint Inc), and do not necessarily represent the opinions or actions of the Interchain Foundation.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in Cosmos Ecosystem Blog

Cosmos is the internet of blockchains - an ever-expanding ecosystem of interconnected, blockchain-based apps and services. Powered by the Interchain Stack, Cosmos boasts over 100 IBC-enabled chains.

Written by Microtick

Decentralized price discovery + short-term options marketplace = trustless, free, and hedgeable blockchain oracle: microtick.com

No responses yet

Write a response