API

To interact with Homa Liquid Staking from Javascript you can use

References

Install SDK

yarn add @polkadot/api @acala-network/api@^4.0.2-17 @acala-network/sdk@^4.0.2-17

Initialize SDK

const { ApiPromise, WsProvider } = require('@polkadot/api')
const { options } = require('@acala-network/api')
const { Wallet, Homa } = require('@acala-network/sdk')

async function main () {
        const ENDPOINT = 'wss://karura.api.onfinality.io/public-ws'

        const api = await ApiPromise.create(options({ provider: new WsProvider(ENDPOINT) }))
        const wallet = new Wallet(api)
        const homa = new Homa(api, wallet)

        // should wait homa sdk ready
        await homa.isReady

        const env = await homa.getEnv();

        // total staked token 
        console.log(env.totalStaking.toString())
        // total L-Token 
        console.log(env.totalLiquidity.toString())
        // estimated staking APY
        console.log(env.apy.toString())
        // exchange rate between L-Token and staked token e.g. rate of LDOT and DOT
        console.log(env.exchangeRate.toString())
        // minimum mint threshold
        console.log(env.mintThreshold.toString())
        // minimum redeem threshold
        console.log(env.redeemThreshold.toString())
        // staking soft cap
        console.log(env.stakingSoftCap.toString())
}

;main()

Queries

Get Total Staked Asset

Total number of assets staked via Homa Liquid Staking protocol

Get Total L-Token Asset

Total number of L-Token assets minted via Homa Liquid Staking protocol

Get Exchange Rate

Estimated staking APY

Get Staking APY

Exchange rate between L-Token and staked token e.g. rate of LDOT and DOT

Minimum Mint Threshold

Minimum Redeem Threshold

Staking Soft Cap

A soft cap for maximum token can be staked

Calculate the amount of Staking Asset for a given amount of L-Token and Vice Versa

Stake

Fast Redeem

When user stakes, the staking token will be stored in a mint pool before being sent to Relay Chain for staking via XCM. You can call fast redeem to exchange L-Token for staking token from this pool.

Some reference web application would employ the following flow to achieve instant redemption

  • check there's enough staking token in the pool using mint.canTryFastReddem

  • if there's, then swap L-Token to staking token from the mint pool

  • otherwise, swap L-Token to staking token via the Acalaswap DeX

Normal Redeem

Redeem and wait unbounding period + 1 Era to receive staked tokens. Unbounding period is defined by the staking asset protocol e.g. 28 days unbounding period for DOT and 7 days for KSM.

Last updated