Documentation · Get started
Quickstart
Read a Stock Token's band and the price at which a position would be liquidated, against Robinhood Chain's testnet.
This reads two things from the testnet: the band of TSLA, and the liquidation price of a position that borrows 50 more USDG. Neither needs a wallet, a key or ether.
Before you start#
You need the chain's registry, deployments/46630.json in the repository, which lists every contract the SDKs use. No SDK compiles in an address. The testnet's public RPC is https://rpc.testnet.chain.robinhood.com.
pnpm add @tapehouse/sdk viemRead the band#
import { readFileSync } from 'node:fs'
import { createPublicClient, http } from 'viem'
import { band, parseDeployments } from '@tapehouse/sdk'
const deployments = parseDeployments(JSON.parse(readFileSync('deployments/46630.json', 'utf8')))
const client = createPublicClient({ transport: http('https://rpc.testnet.chain.robinhood.com') })
const { state, live, mid, halfBps, low, high } = await band.quote(client, deployments, 'TSLA')
console.log(state, live, mid, halfBps, low, high)The result carries the band's state as a number (0 halted, 1 degraded, 2 closed, 3 open), how many price legs are live, the centre, the half-width in basis points, and the low and high edges. Prices have 8 decimals. The band says what each state means. The HTTP call answers with the block it read at and the outputs by name.
Read a liquidation price#
The liquidation price is the price of a collateral asset at which a position falls short of its requirement, given what it already owes and a loan you are considering. It is a view, so you can ask before anyone signs. The position is CROSS, the cross position of the account, and the loan is 50 USDG, which has 6 decimals.
import { accounts, CROSS } from '@tapehouse/sdk'
const price = await accounts.liquidationPrice(
client,
deployments,
'0xB986a345655097302cac8b4af6C948FfaF7f55FC',
CROSS,
'TSLA',
50_000_000n,
)
console.log(price)The answer is a price in USD with 8 decimals: the price of TSLA at or above which the position meets its requirement once it owes 50 USDG more. It is the band's low edge where the position falls short already, and zero where no price leaves it short or the asset is halted. Over HTTP the price comes back as arg0, since the function names no output. While the band cannot tell the session, the requirement used is the closed one, so the price is the one at which borrowing stops.
Next#
- Open an account and borrow from the app or from code.
- The SDKs in full.
- The indexer API, if you would rather read events and views over HTTP.