Skip to content
Docs

Agent builders

Following client strategies

Clients choose how an agent trades their account by signing a strategy setting. An agent that follows these settings reads them from the API, checks each one on chain, and marks every fill with the setting it ran under.

Reading the settings

Every setting for an agent
curl "https://api.fillmark.trade/v1/settings?agent=26144"

Each entry is a setting and its signature. The API checks them before it stores them, and an agent checks them again: recover the signer of the typed data below, then check that it is the account's owner in the ECDSA validator (ecdsaValidatorStorage(account) on 0x845A…cE57) and that the account's rootValidator() is that validator. Kernel accounts accept only signatures over their own wrapped hash in isValidSignature, which a wallet would show as an unreadable hash, so settings are checked this way instead.

The typed data
// EIP-712, as the client app and the reference agent sign and check it
const domain = { name: "Fillmark", version: "1", chainId: 4663, verifyingContract: "0x6F01e2bE7d1D31E88dF177bEC23392D1905FC8Aa" };
const types = {
  Setting: [
    { name: "account", type: "address" },
    { name: "agentId", type: "uint256" },
    { name: "strategy", type: "string" }, // "dca" or "rebalance"
    { name: "takeProfitBps", type: "uint32" },
    { name: "targets", type: "Target[]" },
    { name: "cashBps", type: "uint16" },
    { name: "driftBps", type: "uint16" },
    { name: "everyDays", type: "uint16" },
    { name: "validFrom", type: "uint64" },
    { name: "seq", type: "uint64" },
  ],
  Target: [
    { name: "asset", type: "address" },
    { name: "ticker", type: "string" },
    { name: "weightBps", type: "uint16" },
  ],
};
const signer = await recoverTypedDataAddress({ domain, types, primaryType: "Setting", message: setting, signature });

Which setting is in effect

A setting takes effect at the first 00:00 UTC after its validFrom, and not before the day after the agent first saw it, so a day already under way never changes strategy. The highest seq in effect wins; two settings with that seq, a signer that is not the owner, or a setting that does not fit the account (a target asset the account does not allow) stop the account rather than fall back to another strategy. Keep every setting you have seen: an answer from the API that leaves one out must never take an account back to an earlier strategy.

Marking each fill

The router logs fillId = keccak256(abi.encode(chainid, router, account, nonce)). Put the top 128 bits of the setting's EIP-712 hash in the top 128 bits of the nonce, and the low 128 bits of one of the derivations below in the low 128 bits. The API then proves which setting each fill ran under by rebuilding the candidate nonces of its day and matching their fill ids, without reading the transaction, and the agent page groups client results by strategy. These are the reference agent's derivations; the API can only rebuild these:

dca buy
keccak256(abi.encode("fillmark-dca-v2", account, token, day))
take-profit sale
keccak256(abi.encode("fillmark-tp-v1", account, token, day, n)), n from 0 each day
rebalance trade
keccak256(abi.encode("fillmark-rb-v1", account, token, day, sell, n)), n from 0 each day and side

Fills of an account with no setting keep the plain derivation, with no fingerprint. Fills with nonces the API cannot rebuild show as not attributed. The code is public: the reference agent and the proof in the record library.

Loading the search index…