Ojo
Search
K
⛓️

IBC

If your chain supports IBC and is built using the Cosmos SDK, you can consume price feeds over Stargate IBC Queries by importing the Ojo IBC module and relaying over the oracle channel via the hermes tool.
The Ojo IBC Module exists in this repo. To import the latest version:
go get github.com/ojo-network/ojo-chainibc-demo
And add it to various places in app.go
Imports:
oracleintegrationmodule "github.com/ojo-network/ojo-chainibc-demo/x/oracleintegration"
oracleintegrationmodulekeeper "github.com/ojo-network/ojo-chainibc-demo/x/oracleintegration/keeper"
oracleintegrationmoduletypes "github.com/ojo-network/ojo-chainibc-demo/x/oracleintegration/types"
ModuleBasics:
ModuleBasics = module.NewBasicManager(..., oracleintegrationmodule.AppModuleBasic{})
The App struct:
type App struct {...
ScopedChainintergrationKeeper capabilitykeeper.ScopedKeeper
ScopedOracleintegrationKeeper capabilitykeeper.ScopedKeeper
OracleintegrationKeeper oracleintegrationmodulekeeper.Keeper
}
The keys store - within App.New()
keys := sdk.NewKVStoreKeys(..., oracleintegrationmoduletypes.StoreKey)
In module definitions - within App.New()
scopedOracleintegrationKeeper := app.CapabilityKeeper.ScopeToModule(oracleintegrationmoduletypes.ModuleName)
app.ScopedOracleintegrationKeeper = scopedOracleintegrationKeeper
app.OracleintegrationKeeper = *oracleintegrationmodulekeeper.NewKeeper(
appCodec,
keys[oracleintegrationmoduletypes.StoreKey],
keys[oracleintegrationmoduletypes.MemStoreKey],
app.GetSubspace(oracleintegrationmoduletypes.ModuleName),
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
scopedOracleintegrationKeeper,
)
oracleintegrationModule := oracleintegrationmodule.NewAppModule(appCodec, app.OracleintegrationKeeper, app.AccountKeeper, app.BankKeeper)
oracleintegrationIBCModule := oracleintegrationmodule.NewIBCModule(app.OracleintegrationKeeper)
/**** BEFORE IBC Routing ****/
During IBC routing:
ibcRouter.AddRoute(oracleintegrationmoduletypes.ModuleName, oracleintegrationIBCModule)
/**** BEFORE app.IBCKeeper.SetRouter(ibcRouter) ****/
During Module Manager Declaration:
app.mm = module.NewManager(..., oracleintegrationModule)
During Begin Blockers, EndBlockers, InitGenesis, and ExportGenesis:
  • Note, please take careful consideration when determining the order of these operations. If you're running a lending protocol, you may want the oracle module endblocker to run before the lending module endblocker.
app.mm.SetOrderBeginBlockers(..., oracleintegrationmoduletypes.ModuleName)
app.mm.SetOrderEndBlockers(..., oracleintegrationmoduletypes.ModuleName)
genesisModuleOrder := []string{..., oracleintegrationmoduletypes.ModuleName}
// Assuming use of:
app.mm.SetOrderInitGenesis(genesisModuleOrder...)
app.mm.SetOrderExportGenesis(genesisModuleOrder...)
While initializing params:
paramsKeeper.Subspace(oracleintegrationmoduletypes.ModuleName)
Now you're able to import the ojo oracle into the module which needs this data in App.go:
app.LendingKeeper = lendingkeeper.NewKeeper(
app.cdc,
app.keys[assettypes.StoreKey],
app.GetSubspace(assettypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
&app.Rewardskeeper,
&app.VaultKeeper,
&app.OracleintegrationKeeper,
)
And within the LendingKeeper, you can use the oracleKeeper:
```
results, err := k.oracleKeeper.GetResults(ctx)
if err == nil {
return nil, err
}
prices = results[0].Result
```
Be sure to be running the hermes tool between your chain and the Agamotto chain.