TypeScript SDK
@poincaretrade/sdk is a typed, viem-based ESM package. One client covers the regime, quotes and DCA orders; reads need no wallet.
Install
npm i @poincaretrade/sdk viemviem 2 is a peer dependency. The package is ESM-only and ships its own types.
Create a client
import { createPoincareClient } from "@poincaretrade/sdk";
const poincare = createPoincareClient(); // the live Unichain Sepolia deployment, public RPC
// createPoincareClient({ rpcUrl, publicClient, walletClient, deployment })Regime and quotes
const r = await poincare.regime();
const q = await poincare.quote("sell", "0.5");
const stop = poincare.watchRegime({
onEvent: (e) => {
if (e.type === "spread-engaged") console.log(`${e.side}s now pay ${(e.spread * 100).toFixed(2)}%`);
},
});
const samples = await poincare.history(fromBlock); // the hook's DetectorSample traceOpen a DCA order
create approves exactly the budget (never an unlimited allowance) and resolves to the order id.
import { createPoincareClient, recurringOrder, twapOrder } from "@poincaretrade/sdk";
const poincare = createPoincareClient({ walletClient });
// 100 USDC of WETH every hour, 10 times, never paying the trend spread
const id = await poincare.dca.create(
recurringOrder({ side: "buy", amountPerBuy: "100", frequency: "1h", count: 10, protection: "spread-guard" }),
);
// 2 WETH sold evenly over 4 hours, with a floor
await poincare.dca.create(twapOrder({ side: "sell", total: "2", durationSec: 14_400, limitPrice: "2200" }));
// every field by hand
await poincare.dca.create({ side: "buy", amount: "1000", slices: 6, interval: 3600, maxSpreadBps: 25, pauseOnTrend: true });Follow and manage it
const o = await poincare.dca.order(id); // filled, remaining, refunded, amountOut, paused, ...
const next = await poincare.dca.preview(id); // { status, amountIn, quoteOut, minOut, spreadBps, nextSlotAt }
await poincare.dca.pause(id);
await poincare.dca.edit(id, { slices: 12, interval: 1800, limitPrice: null }); // re-plan what is left
await poincare.dca.resume(id);
await poincare.dca.cancel(id);Sign elsewhere
Every write also exists unsigned under dca.build, as { to, data, value, gas, description }, ready for a browser wallet, a multisig or an agent.
const txs = await poincare.dca.build.create(owner, input); // [approve (if needed), createOrder]
const tx = poincare.dca.build.pause(id); // also execute, cancel, closeExpired, resume
const edit = await poincare.dca.build.edit(id, { slices: 8 });Gas and RPC lag. Every built transaction carries an explicit gas limit: testnet estimation mis-simulates calls through the hook. After a transaction, the client pins its next allowance read to that block, so a lagging public RPC replica cannot make it skip an approval.
Reference
| Export | What it is |
|---|---|
createPoincareClient | regime, watchRegime, history, quote, and dca.{order, ordersOf, openOrderIds, preview, create, execute, pause, resume, edit, cancel, closeExpired, build.*} |
recurringOrder · twapOrder | Plan builders; FREQUENCIES 5m 15m 1h 4h 1d 1w; PROTECTIONS spread-guard · trend-pause · always |
buildOrderParams · buildEditParams | Validate like createOrder / editOrder; throw DcaParamError with the contract's reason |
planSlice · sliceAmount · slotInfo | Offline mirror of the contract's slice rules |
spentOf · progressOf · statusOf | Order helpers; DCA_STATUS_TEXT explains every status |
readRegime · diffRegime · trendOnsets | Lower-level regime reads and event diffing |
build*Tx · sendTx · DCA_GAS | Unsigned transactions with explicit gas, and a sender that fails loudly on a revert |
hookAbi · lensAbi · dcaAbi · erc20Abi | Typed ABIs generated from the contracts |
UNICHAIN_SEPOLIA · withDca | The live deployment, and a helper to point at another PoincareDCA |