Skip to content

SDK Getting Started

@interestswap/sdk provides production address constants, quote/RFQ models, EIP-712 signing, HTTP helpers, an authenticated RFQ WebSocket client, rate conversions, and a local daemon socket client.

Install

bash
pnpm add @interestswap/sdk viem

Node.js 20 or later is required. The WebSocket signer APIs can use a private key, but browser applications should use BackerSigner.setAccount with the connected wallet rather than expose a private key to client code.

Read Production Data

The SDK defaults to the generated Base contract addresses, but its orderbook URL defaults to localhost. Set the service URL explicitly for production:

ts
import { InterestSwapClient, PRODUCTION_DEPLOYMENT } from '@interestswap/sdk'

const client = new InterestSwapClient({
  orderbookUrl: 'https://api.interest.exchange',
})

const [health, poolData] = await Promise.all([
  client.getHealth(),
  client.getPoolRates(),
])

console.log(PRODUCTION_DEPLOYMENT.chainId, health.status, poolData.pools)

orderbookUrl is the origin without /api/v1; the client appends API and WebSocket paths.

Request Borrower Quotes

ts
const result = await client.requestQuotes({
  poolId: '0x...',
  expiry: 1_787_000_000,
  notional: '1407554', // raw loan-token units
})

for (const quote of result.quotes) {
  console.log(
    quote.marketQuote.maker,
    quote.notional,
    quote.vrtAmount,
    quote.expiresAt,
  )
}

This endpoint discovers quotes; it does not execute them. A borrower must revalidate the selected quote and call the deployed QuoteMarket through Bundler3 with the required approvals.

Listen and Quote as a Backer

ts
import { InterestSwapClient } from '@interestswap/sdk'

const client = new InterestSwapClient({
  orderbookUrl: 'https://api.interest.exchange',
})

// Server-side only. Prefer setAccount with a wallet client in wallet software.
client.setPrivateKey(process.env.BACKER_PRIVATE_KEY as `0x${string}`)

const ws = client.connectWebSocket({
  onAuthenticated: (address) => console.log('authenticated', address),
  onRFQ: async (rfq) => {
    // Apply policy, choose an eligible series, read QuoteMarket.nonces(maker),
    // calculate vrtAmount, construct the exact QuoteMarketQuote, then:
    // await ws.submitQuote(rfq.rfqId, quote)
    console.log('RFQ', rfq)
  },
  onQuoteAck: (ack) => console.log('quote result', ack),
})

Before submitting, the maker must have enough pool loan token and must approve QuoteMarket for at least vrtAmount. The quote nonce must equal the current on-chain QuoteMarket.nonces(maker) value.

Interest Exchange Protocol