Integration
Integrating Connect with Blockchain Applications
Connect is business-licensed software under the Business Source License (BSL). The source code is viewable; however, please reach out to us if you are interested in integrating. We are limiting the number of partnerships we engage with in 2024. We apologize in advance if we reach capacity and are unable to accommodate new integrations.
This document will guide you through integrating Connect in your application.
Requirements
- Go 1.23+
- Cosmos SDK v0.50+
Integrating Connect
Integrating Connect into your Cosmos SDK application requires a few simple steps.
Add Oracle Configuration
Add the oracle configuration to your application.
Add Modules
Import and add the x/marketmap
and x/oracle
Modules to your app.
Setup Oracle Client
Set up the Oracle client the application will use to get prices from the Connect oracle.
Set ABCI Method
Set the PreBlock ABCI method, which is responsible for aggregating prices and writing them to the application’s state.
Configure Vote Extensions
Configure vote extensions with compression and storage strategies.
Application Configuration
The application node’s configuration must be extended so the oracle configuration can be read into the node through app.toml
.
The application should contain a custom configuration struct with a "github.com/cosmos/cosmos-sdk/server/config"
embedded.
Note: application function and type names may vary. The names in the following steps are arbitrary for example purposes only.
Next, append the Oracle’s default config template to the custom application template.
Finally, add a default configuration.
The template and default configuration should be passed into server.InterceptConfigsPreRunHandler
in the application’s root command.
Example:
Keepers
Add x/marketmap and x/oracle keepers to the application.
Then, add them to the dependency injection system.
Finally, once the app is built with the appBuilder
, finish the initialization of the MarketMapKeeper
by setting the hooks.
Oracle Client
Create a method to construct and return the oracle client and metrics.
ABCI and Vote Extensions
Configure the ABCI methods and vote extensions.
Define a method to contain the logic where these will be configured.
Within this method, do the following:
- Setup Proposal Handler: This handler will be used in
PrepareProposal
andProcessProposal
to fill proposals with the oracle data. - Set PreBlocker: The application’s
PreBlocker
will be configured to write price data to state before transactions are executed. - Set Vote Extensions: Set the vote extension handlers on the application that will handle adding price data to the node’s consensus votes.
Start with setting up the proposal handler.
Next, set up the PreBlocker
. This involves:
- Aggregate Function: Setting the aggregator function that combines all reported prices into one final price per currency pair.
- Currency Pair Strategy: Setting the currency pair strategy. For this example, we will use the
DeltaCurrencyPairStrategy
which encodes/decodes the price as the difference between the current price and the previous price. While other strategies are available, we recommend this one for most applications. - Data Compression Codecs: Setting the compression strategy for vote extensions and extended commits.
Next, configure the vote extensions using the vote extension codec, extended commit codec, and aggregator function from the previous step.
Finally, call these methods back in app.go
, directly after setting the x/marketmap
hooks.
Initializing Modules
In order for the application to use Connect properly, the following is required:
- Set the consensus parameters to enable vote extensions
- Initialize
x/marketmap
with initial markets
For new chains, or to test the integration, the method above can be called in InitChainer
. Connect will begin posting prices to the chain once the VoteExtensionsEnabledHeight
is reached.
For live running chains, use an upgrade handler. Note: Connect will not post prices to the chain until the upgrade is executed.
Running the Node
Once the chain is properly configured, head over to the Quickstart guide to learn how to start the node with a Connect sidecar.
Need Help?
Need help with your integration? Feel free to reach out to us on Discord.