Example: a regime-aware LP strategy
No new contract: a small bot that decides how much of your liquidity sits in the pool, by regime. Built on the SDK, the HTTP API or Claude, around the hook's own addLiquidity and removeLiquidity.
The idea
The Poincaré pool is full-range by design, so there is no price range to set. What you can choose is how much liquidity sits in it, and when. During a trend the hook already charges with-trend swaps a spread that LPs keep, so staying in is usually right. The case worth acting on is a trend strong enough to pin the spread at its 5% cap for a while: the cap, not the detector, is then doing the work, and part of the position is better out until the trend ends.
- CalmFully deposited. Both sides trade at the plain price.
- Trend confirmedStay in: with-trend swaps pay the spread to you.
- Pinned at the capSpread at its 5% cap for N blocks: withdraw part.
- Trend endsAdd the withdrawn part back at the new price.
| Signal | Action |
|---|---|
| Calm, or a trend with the spread below its cap | Stay fully in |
kappa at kappaMax for PIN_BLOCKS blocks in a row | Withdraw TRIM of your LP shares (once per trend) |
trend-ended event | Add the withdrawn tokens back, at the pool's current ratio |
With the SDK
The SDK watches the regime block by block. Liquidity goes through the hook itself, so the example declares the two functions it needs. Every transaction carries an explicit gas limit, because testnet gas estimation mis-simulates calls through the hook.
import { createPoincareClient, UNICHAIN_SEPOLIA, erc20Abi } from "@poincaretrade/sdk";
import { createWalletClient, http, parseAbi, zeroHash } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { unichainSepolia } from "viem/chains";
const PIN_BLOCKS = 20n; // the spread sits at its cap this long before we act
const TRIM = 50n; // percent of our LP shares to take out
const account = privateKeyToAccount(process.env.KEY as `0x${string}`); // a testnet key
const wallet = createWalletClient({ account, chain: unichainSepolia, transport: http() });
const poincare = createPoincareClient({ walletClient: wallet });
const pub = poincare.publicClient;
const { hook, usdc, weth } = UNICHAIN_SEPOLIA;
const lpAbi = parseAbi([
"function balanceOf(address) view returns (uint256)",
"function addLiquidity((uint256 amount0Desired, uint256 amount1Desired, uint256 amount0Min, uint256 amount1Min, uint256 deadline, int24 tickLower, int24 tickUpper, bytes32 userInputSalt) params) payable",
"function removeLiquidity((uint256 liquidity, uint256 amount0Min, uint256 amount1Min, uint256 deadline, int24 tickLower, int24 tickUpper, bytes32 userInputSalt) params)",
]);
const deadline = () => BigInt(Math.floor(Date.now() / 1000) + 1200);
let pinnedSince: bigint | null = null;
let out = { usdc: 0n, weth: 0n }; // what we withdrew this trend, to add back
async function trim() {
const shares = await pub.readContract({ address: hook, abi: lpAbi, functionName: "balanceOf", args: [account.address] });
const before = await balances();
const hash = await wallet.writeContract({ address: hook, abi: lpAbi, functionName: "removeLiquidity", gas: 2_500_000n,
args: [{ liquidity: (shares * TRIM) / 100n, amount0Min: 0n, amount1Min: 0n, deadline: deadline(), tickLower: 0, tickUpper: 0, userInputSalt: zeroHash }] });
await pub.waitForTransactionReceipt({ hash });
const after = await balances();
out = { usdc: after.usdc - before.usdc, weth: after.weth - before.weth };
}
async function addBack(price: number) {
// deposits go in at the pool's ratio: size the WETH leg from the USDC leg at today's price
const usdcIn = out.usdc;
const wethIn = BigInt(Math.floor((Number(usdcIn) / price)));
for (const [token, amount] of [[usdc, usdcIn], [weth, wethIn]] as const) {
const h = await wallet.writeContract({ address: token, abi: erc20Abi, functionName: "approve", args: [hook, amount], gas: 150_000n });
await pub.waitForTransactionReceipt({ hash: h });
}
const hash = await wallet.writeContract({ address: hook, abi: lpAbi, functionName: "addLiquidity", gas: 3_000_000n,
args: [{ amount0Desired: usdcIn, amount1Desired: wethIn, amount0Min: 0n, amount1Min: 0n, deadline: deadline(), tickLower: 0, tickUpper: 0, userInputSalt: zeroHash }] });
await pub.waitForTransactionReceipt({ hash });
out = { usdc: 0n, weth: 0n };
}
async function balances() {
const read = (token: `0x${string}`) => pub.readContract({ address: token, abi: erc20Abi, functionName: "balanceOf", args: [account.address] });
return { usdc: await read(usdc), weth: await read(weth) };
}
poincare.watchRegime({
onRegime: async (r) => {
const pinned = r.kappaMax > 0 && r.kappa >= r.kappaMax * 0.999;
if (!pinned) { pinnedSince = null; return; }
pinnedSince ??= r.blockNumber;
if (out.usdc === 0n && r.blockNumber - pinnedSince >= PIN_BLOCKS) await trim();
},
onEvent: async (e, r) => {
if (e.type === "trend-ended" && out.usdc > 0n) await addBack(r.price);
},
onError: (err) => console.error(err),
});The minimum amounts are left at zero to keep the example short; a real bot should set them from a quote.
With the HTTP API
The API reads the regime but never holds keys, and it has no liquidity routes: a scheduled job reads /regime, keeps the same counters, and sends the two hook calls from its own signer, exactly as above.
curl -s https://gogjpdgluflntcgsarhn.supabase.co/functions/v1/poincare-api/regime | jq '{trend: .regime.trend, kappa: .regime.kappa, kappaMax: .regime.kappaMax, block: .regime.blockNumber}'With Claude
The MCP server has no liquidity tools, on purpose: Claude watches and tells you; you act in the app's Pool screen. That keeps a person in the loop for the one decision that moves your capital.
"Watch the Poincaré pool. If the spread sits at its cap
for about 20 blocks, tell me and suggest how much liquidity
to take out. When the trend ends, remind me to add it back."
→ wait_for_regime_change (spread-engaged, trend-ended)
→ get_regime, to check kappa against kappaMaxPIN_BLOCKS and TRIM.