@invia-app/sdk
v0.1.0
Published
TypeScript SDK for the Invia OTC escrow program on Solana
Maintainers
Readme
@invia-app/sdk
TypeScript SDK for the Invia OTC escrow program on Solana. Wraps the on-chain
program (Rust/Anchor) and the public REST API at api.invia.markets.
Install
pnpm add @invia-app/sdk @solana/web3.js@solana/web3.js is a peer dependency. Anchor is not required at runtime.
Quickstart
import { Connection, PublicKey } from "@solana/web3.js";
import {
InviaClient,
PAYMENT_MINTS,
parseTokenAmount,
pickPriceAndScale,
} from "@invia-app/sdk";
const connection = new Connection("https://api.devnet.solana.com", "confirmed");
const invia = new InviaClient({ connection, apiBaseUrl: "https://api.invia.markets" });
const open = await invia.api.getOffers({ status: "open", limit: 50 });
console.log(`open offers: ${open.offers.length}`);
const sizeRaw = parseTokenAmount("100", 6);
const totalRaw = parseTokenAmount("0.5", 9);
const priced = pickPriceAndScale(sizeRaw, totalRaw)!;
const { ix, pda, nonce } = invia.program.buildCreateOfferIx({
maker: new PublicKey("..."),
side: "sell",
tokenMint: new PublicKey("..."),
paymentMint: PAYMENT_MINTS.WSOL,
size: sizeRaw,
pricePerToken: priced.pricePerToken,
priceScale: priced.priceScale,
minFill: sizeRaw,
expiresAt: BigInt(Math.floor(Date.now() / 1000) + 24 * 3600),
});What is in the box
- Program client: instruction builders for
create_offer,take_offer,cancel_offer,expire_offer,close_offer, plus PDA + ATA derivation and raw-bytes account decoding. No Anchor runtime needed. - API client: typed wrappers for the public REST endpoints: offers, fills, tokens, simulate, blockhash, stats, makers, trending.
- Helpers:
parseTokenAmount,fmtTokenAmount,pickPriceAndScale,totalFromPrice, fee math,signSendConfirmfor Privy-shaped wallets.
Tests
The SDK ships with a vitest suite that exercises the pure helpers offline and the API + devnet program live. By default tests hit production:
pnpm testOverride the targets with env vars:
| Var | Default | Purpose |
|---------------------------|--------------------------------------|----------------------------------------|
| INVIA_API_BASE_URL | https://api.invia.markets | REST API base used by InviaApiClient |
| INVIA_RPC_URL | https://api.devnet.solana.com | RPC endpoint for on-chain reads |
| INVIA_OFFLINE | unset | When set, skip live (api + rpc) tests |
Pure helpers run regardless of network access:
pnpm test:offlineStatus
The contract is currently deployed on devnet at
C9YABXJdHpiz4gjDuVrmCV7Qhq7uGGLNcdDnKu5UBiUV. The mainnet program ID and
account layouts will be locked at the D0 deploy and exposed here as a constant.
Docs
Full reference and walkthroughs live at https://docs.invia.markets/sdk/quickstart.
