Today, Hover Labs is debuting Kolibri.js, a JavaScript SDK for working with kUSD and the Kolibri protocol.
Kolibri.js is a wrapper for all aspects of the Kolibri protocol, including working with core contracts, ovens, and Harbinger Oracles. The SDK abstracts away details of working with the Kolibri contracts so that developers can simply build.
In fact, Kolibri.js is the same toolchain Hover Labs uses to build the Kolibri front end. One of the most powerful parts of DeFi is that the smart contracts which power the protocols are open by default. Over time, we hope Kolibri.js serves as inspiration for other developers to build additional front ends and other products which integrate with Kolibri.
The library is focused on being lightweight. It is built with Taquito and Thanos, and uses a few additional well understood libraries that seasoned DeFi developers will be familiar with (axios, bignumber.js, blakejs, and bs58check). Like any modern JavaScript library, it contains TypeScript definitions.
Of course, none of this would be possible without the tools created by the ecosystem. Hover Labs appreciates both the Taquito and Thanos teams, who built the excellent libraries that power Kolibri.js, and who patiently offered support and fielded feature requests throughout development.
Kolibri.js is available on NPM today. Hover Labs anticipates open sourcing the library after the mainnet launch of Kolibri. If you’d like help getting started, feel free to bug the developers of the library in the #kolibri-js channel in our Discord.
No good technical blog post would be complete without some tech demos, so we’ll dedicate the rest of the blog post to showing off a few code snippets to get other developers imaginations running.
Here are some things you can do with Kolibri.js:
Get a kUSD balance for an account:
import { CONTRACTS, TokenClient } from “@hover-labs/kolibri-js”const nodeUrl = “https://rpctest.tzbeta.net"
const tokenClient = new TokenClient(nodeUrl, CONTRACTS.DELPHI.TOKEN)const balance = await tokenClient.getBalance(
“tz1YfB2H1NoZVUq4heHqrVX4oVp99yz8gwNq”
)
console.log(`Balance: ${balance}`)
Retrieve data from a Harbinger Oracle:
import { CONTRACTS, HarbingerClient } from “@hover-labs/kolibri-js”const nodeUrl = “https://rpctest.tzbeta.net"
const harbingerClient = new HarbingerClient(
nodeUrl,
CONTRACTS.DELPHI.HARBINGER_NORMALIZER
)const priceData = await harbingerClient.getPriceData()
console.log(`Price: ${priceData.price}`)
console.log(`Price Timestamp: ${pricedata.time.getTime() / 1000}`)
Deploy an Oven:
const result = await stableCoinClient.deployOven(signer)
console.log(`Deployed in hash: ${result.opHash}`)
List Ovens owned by an address:
import {
CONTRACTS,
StableCoinClient,
Network
} from “@hover-labs/kolibri-js”const nodeUrl = “https://rpctest.tzbeta.net"const stableCoinClient = new StableCoinClient(
nodeUrl,
Network.Delphi,
CONTRACTS.DELPHI.OVEN_REGISTRY,
CONTRACTS.DELPHI.MINTER,
CONTRACTS.DELPHI.OVEN_FACTORY
)const ovens = await stableCoinClient.ovensOwnedByAddress(
TEST_ACCOUNT_ADDRESS
)console.log(`The first oven is ${ovens[0]}`)
Interact with an Oven:
import {
CONTRACTS,
HarbingerClient,
OvenClient,
StableCoinClient,
Network
} from “@hover-labs/kolibri-js”
import { InMemorySigner } from ‘@taquito/signer’
import BigNumber from ‘bignumber.js’const nodeUrl = “https://rpctest.tzbeta.net"const signer = await InMemorySigner.fromSecretKey(“edsk…”)
const harbingerClient = new HarbingerClient(
nodeUrl,
CONTRACTS.DELPHI.HARBINGER_NORMALIZER
)const stableCoinClient = new StableCoinClient(
nodeUrl,
Network.Delphi,
CONTRACTS.DELPHI.OVEN_REGISTRY,
CONTRACTS.DELPHI.MINTER,
CONTRACTS.DELPHI.OVEN_FACTORY
)const ovenAddress = “KT1…”
const ovenClient = new OvenClient(
nodeUrl,
signer,
ovenAddress,
stableCoinClient,
harbingerClient
)const collateralizationRatio =
await ovenClient.getCollateralizationRatio()
console.log(`Collateralization ratio: ${collateralizationRatio}`
If you’ve made it this far, hopefully you’re excited to take Kolibri.js for a spin. A overview of all the classes is available on our documentation page. We can’t wait to see what people build!