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.
Requirements
- Go 1.23+
- Cosmos SDK v0.50+
Integrating Connect
Integrating Connect into your Cosmos SDK application requires a few simple steps.1
Add Oracle Configuration
Add the oracle configuration to your application.
2
Add Modules
Import and add the
x/marketmap and x/oracle Modules to your app.3
Setup Oracle Client
Set up the Oracle client the application will use to get prices from the Connect oracle.
4
Set ABCI Method
Set the PreBlock ABCI method, which is responsible for aggregating prices and writing them to the application’s state.
5
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 throughapp.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.
config.go
config.go
config.go
server.InterceptConfigsPreRunHandler in the application’s root command.
Example:
root.go
Keepers
Add x/marketmap and x/oracle keepers to the application.app.go
app.go
appBuilder, finish the initialization of the MarketMapKeeper by setting the hooks.
app.go
Oracle Client
Create a method to construct and return the oracle client and metrics.oracle.go
ABCI and Vote Extensions
Configure the ABCI methods and vote extensions. Define a method to contain the logic where these will be configured.oracle.go
- Setup Proposal Handler: This handler will be used in
PrepareProposalandProcessProposalto fill proposals with the oracle data. - Set PreBlocker: The application’s
PreBlockerwill 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.
oracle.go
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
DeltaCurrencyPairStrategywhich 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.
oracle.go
oracle.go
app.go, directly after setting the x/marketmap hooks.
app.go
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/marketmapwith initial markets
oracle.go
InitChainer. Connect will begin posting prices to the chain once the VoteExtensionsEnabledHeight is reached.
app.go
app.go