Skip to content
Docs

Agent builders

TypeScript SDK

@fillmark/sdk wraps the router for an ERC-8004 agent: it finds the accounts that installed the agent, sizes and quotes each fill inside that client's limits, and sends it from the agent wallet.

Install

Shell
npm install @fillmark/sdk viem

It needs Node 22.14 or later and viem 2.57.20 or later. The source is in the sdk folder of the repository.

Quick start

TypeScript: buy for every client
import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { robinhood } from "viem/chains";
import { fillmarkAgent } from "@fillmark/sdk";

const transport = http(process.env.RPC_URL);
const agent = fillmarkAgent({
  publicClient: createPublicClient({ chain: robinhood, transport }),
  walletClient: createWalletClient({ chain: robinhood, transport, account: privateKeyToAccount(AGENT_KEY) }),
  agentId: 123n, // the agent's ERC-8004 id; the key must be its agent wallet
});

await agent.check();

for (const client of await agent.clients()) {
  const quote = await agent.quoteBuy({ account: client.account, asset: "TSLA" });
  if (!quote.ok) {
    console.log(client.account, quote.reason, quote.message);
    continue;
  }
  const fill = await agent.fill(quote);
  console.log(fill.hash, fill.shortfallPpm);
}

A quote runs the router's checks in the router's order, quotes the router's pool on Uniswap and simulates the fill from the agent wallet. When something stands in the way it returns ok: false with the router's error name as the reason, so nothing is sent. Without an amount, quoteBuy takes the largest buy the client's limits and USDG allow, and quoteSell the largest sale.

TypeScript: take profit
// The largest sale the per-trade limit allows, never more than the agent's own lot
const quote = await agent.quoteSell({ account, asset: "cbBTC" });
if (quote.ok) await agent.fill(quote);

Calls

check()
Chain id, the RPC's clock, and that the wallet client is the agent wallet in the ERC-8004 registry.
clients()
Accounts with the agent installed: limits, allowed assets, USDG, buys in the last 24 hours, fee debt, whether buys are open.
market(assets?)
Session, Chainlink price and age, the router pool's price against it, and whether the asset trades now.
maxBuy / maxSell
The largest buy or sale the client's limits, balance and the agent's lot allow now.
quoteBuy / quoteSell
A checked, simulated fill, or the reason it is refused.
fill(quote)
Sends a quote from the agent wallet with a fixed 1,500,000 gas limit and returns the router's Filled event.
record()
The agent's totals from the router: fills, volume, total cost against Chainlink, worst fill.
book / settleFees / release / closeOut / claim
The agent's book with an account and its performance fees.
pay.setRate / pay.due / pay.track
Fillmark Pay: the agent's rate and what each client owes it.
accountStatus(client, account)
A client account as the router sees it.

Fill policy

The router enforces each client's limits. The SDK adds rules that keep an agent from wasting client money or its own ETH:

Sales
No sale under the lot's cost after the fill fee. Can be turned off with saleAboveCost.
Hold
No buy while a sale's gain waits out the router's 7-day hold, since the buy would cancel it. Can be turned off with noBuyDuringHold.
Pair cap
At most two fills per account and asset per UTC day by default (maxFillsPerPairPerDay, up to 50).
Nonces
Built from the router, agent, permission, account, asset, day and a counter, so a retry never fills twice.
Accounts
Only standard Kernel accounts without hooks are traded, checked again before each send.
Reverts
A fill that reverts on chain skips its account for the rest of the day. Every send counts toward maxFillsPerDay.
Sends
One at a time per wallet, and none for an account and asset while the previous one is pending.
The policy state lives in memory unless a store is passed. A store on disk keeps the caps and pending fills across restarts, as the MCP server does.

Errors

Every error is a FillmarkError with a short code and a plain sentence. Errors never carry the RPC URL, which often holds an API key. Use a private RPC: quotes come from it, and while a lying RPC can make a quote worse, it can never push a fill past the limits the client set on chain.

Loading the search index…