@sailbound/sdk
v0.1.0
Published
JavaScript SDK for Sailbound: borrow USDG against stock tokens on Robinhood Chain, fund the pool, and pay or settle x402 requests in USDG.
Maintainers
Readme
@sailbound/sdk
JavaScript SDK for Sailbound: a USDG lending pool on Robinhood Chain backed by stock tokens. Borrow USDG against listed stock tokens, fund the pool, follow loans, and pay or settle x402 requests in USDG.
The Robinhood Chain mainnet deployment (chain id 4663) ships with the package, so you only need an RPC URL and, to send transactions, a signer.
Unaudited software. The pool contract has not been audited, a liquidation takes all of a loan's collateral, and the pool currently has no deposit cap. Use only amounts you can afford to lose. Stock tokens are not offered to U.S. persons.
Install
npm install @sailbound/sdkNode.js 20 or newer. The only dependency is ethers v6.
Read the pool
import { JsonRpcProvider } from "ethers";
import { LendingClient, loadDeployment, formatUsd } from "@sailbound/sdk";
const provider = new JsonRpcProvider("https://rpc.mainnet.chain.robinhood.com", 4663);
const pool = new LendingClient({ provider, deployment: loadDeployment(4663) });
console.log(await pool.poolStats()); // funds, idle USDG, utilization, safety fund, limits
console.log((await pool.assets()).map((a) => a.symbol)); // listed stock tokensQuote, borrow, repay
import { Wallet } from "ethers";
import { LendingClient, loadDeployment, parseUsd, parseToken } from "@sailbound/sdk";
const signer = new Wallet(process.env.PRIVATE_KEY, provider); // never hard-code a key
const pool = new LendingClient({ provider, signer, deployment: loadDeployment(4663) });
const q = await pool.quote({ asset: "NVDA", collateral: parseToken("2"), amount: parseUsd("50"), days: 7 });
if (q.canBorrow) {
const { loanId } = await pool.borrow({ asset: "NVDA", collateral: parseToken("2"), amount: parseUsd("50"), days: 7 });
const loan = await pool.loan(loanId); // health, liquidation price, due date
await pool.repay(loanId);
} else {
console.log(q.reasons); // why the pool would refuse: e.g. not enough idle USDG, or the address limit
}
// A new address starts with a small limit (3 USDG) that grows with loans held 7+ days and repaid in full.Terms are 1, 3, 7, 14 or 30 days. The fee (1% per 30 days, pro rata) is fixed when the loan opens and paid in full, even when repaid early. After the due date there is a one-day grace period; then, or when the collateral falls below its threshold, anyone can liquidate the loan and take all of its collateral.
Other methods: borrowLimit, loansOf, addCollateral, previewDeposit / deposit, positionsOf, previewWithdraw /
withdraw, previewLiquidate / liquidate, record (an address's repayment history), doctor (checks the connection and the
deployment).
Pay x402 endpoints
import { X402Payer, parseUsd } from "@sailbound/sdk";
const payer = new X402Payer({ client: pool, maxPrice: parseUsd("0.05"), maxBorrow: parseUsd("5"), collateral: "NVDA", days: 7 });
const preview = await payer.preview("https://sailbound.xyz/api/x402/pool"); // price, balance, any loan; nothing signed
const { response, paid, borrowed, loanId } = await payer.pay("https://sailbound.xyz/api/x402/pool");The payer pays any x402 endpoint in USDG on this chain (v2 PAYMENT-SIGNATURE, or v1 X-PAYMENT). If the USDG balance is short
and maxBorrow allows it, it first borrows the gap from the pool against collateral; that loan follows every normal rule.
maxPrice and maxBorrow are hard limits.
Sell your own data
createPaywall({ chainId, asset, payTo, relayer, provider })charges per request and settles the payment itself.- Or use the hosted facilitator at
https://sailbound.xyz/api/facilitatorwith any x402 server; register on sailbound.xyz/merchants.
Configuration
loadDeployment(chainId) reads the shipped deployment. Override any address with POOL_ADDRESS, USDG_ADDRESS or a
DEPLOYMENTS_DIR folder. resolveEnv() builds a provider and a signer from RPC_URLS and PRIVATE_KEY in the environment.
More: sailbound.xyz/developers. License: MIT.
