STLNCHR

@lnchr/sdk

Typed helpers over viem

Reads come from the API or straight off chain through the lens, whichever you prefer. Writes come back as plain call objects, so they drop into walletClient.writeContract or wagmi's useWriteContract unchanged.

Install

bash
npm i @lnchr/sdk viem
typescript
import { lnchr } from "@lnchr/sdk";

const sdk = lnchr();

const stocks = await sdk.getStocks();
const packs = await sdk.getPacks();
const nav = await sdk.getNav(packs[0].pack);

Addresses come from the published manifest on first use. Pin them yourself if you would rather not depend on a fetch:

typescript
const sdk = lnchr({
  apiUrl: "https://lnchr.io",
  rpcUrl: process.env.RPC_URL,
  addresses: { packRegistry, packHook, packLens, packRouter },
});

Reading

getStocks()Stocks a pack can hold, with live price, depth rating and route.
getPacks({ offset, limit })Registered packs with composition, holdings and NAV.
getPack(address)One pack, or null.
getNav(pack)USD value of one pack unit, with the composition it was computed from.
predictPack(stocks){ registered, pack, ticker } for an ordered stock list, before it exists.
isPack(address)Whether an address is a registered pack.
readPack / readPacks / readStocksThe same reads straight off chain through PackLens, no server in the path.
navUsdg(pack)NAV of one unit in USDG, on chain.
poolKey(pack, quote)The Uniswap v4 pool key for a pack pool.

Writing

buildRegisterPack(stocks)Fetches the signed price set and returns the register call.
buildBuyWithEth({ pack, value, minOut })Buy a pack with ETH.
buildBuyWithUsdg({ pack, amountIn, minOut })Buy a pack with USDG.
buildSellForEth({ pack, amountIn, minOut })Sell a pack for ETH.
buildSellForUsdg({ pack, amountIn, minOut })Sell a pack for USDG.
buildRedeem({ pack, units, to })Take the underlying stocks out of the vault, pro rata.
quoteBuyWithEth({ pack, value, account })Simulate a buy and read what it would pay out.
typescript
const { registered, pack } = await sdk.predictPack([aapl, meta, nvda]);

if (!registered) {
  await walletClient.writeContract(await sdk.buildRegisterPack([aapl, meta, nvda]));
}

await walletClient.writeContract(
  await sdk.buildBuyWithEth({ pack, value: parseEther("0.1"), minOut: 0n })
);

Approve the pack to the router before selling. There is no separate quoter contract: simulating the call you are about to send is the quote, which is what quoteBuyWithEth does.

ABIs

Exported from the package, and served as JSON if you would rather fetch them.

typescript
import { packLensAbi, packRouterAbi, packRegistryAbi } from "@lnchr/sdk";