agentleFS
cybasecuritycybasecurity/clarity-skills/skills/clarity-protocols/SKILL.md

clarity-protocols

Skill2 starsChanged 31 days agoMITView on GitHub

Verified Stacks DeFi addresses and exact function signatures: Zest, Granite, Bitflow, Stacks Swap, Hermetica, Stacking DAO, ALEX, Velar, USDCx, sBTC, Pyth. Use to call a protocol: loans, swaps, liquidations, deposits.

The file

We split this skill into the rules it gives an agent

12 rules. About 0 are common, 8 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never write a protocol call or interface from memory: take each principal from the registry or the protocol's call reference, and each call …

    line 15
  2. Very specific:

    Read the selected protocol's address table before choosing a principal.

    line 21
  3. Very specific:

    Before relying on an address, run python3 scripts/verify_registry.py --protocol <name> (or --contract <id>) from this skill's directory.

    line 33
  4. Distinctive:

    If live evidence cannot be obtained, explain the unresolved dependency and keep proposed addresses marked unverified.

    line 37
  5. Distinctive:

    Before deployment or signing, always verify, even with a fresh registry:

    line 41
  6. Very specific:

    Run from this skill's directory.

    line 57
  7. Very specific:

    Beneficiary: Read the intended recipient before entering the scope.

    line 64
  8. Distinctive:

    Real contracts: Test against them at a pinned height at least once (mainnet-fork rules).

    line 67
  9. Distinctive:

    Before writing, reviewing or testing a call to one of these protocols, read its reference: it holds the exact signatures, fragments, …

    line 71
  10. Distinctive:

    Use Stacks Swap when the best route needs several hops, a split across pools or venues, or a Stacking DAO conversion.

    line 85
  11. Distinctive:

    When both fit, compare them at the actual size: net output after fees and skim, liquidity, transaction cost, hop count and the contracts …

    line 86
  12. Distinctive:

    Call references, one per protocol: Zest v2, Granite, Hermetica, Stacks Swap, Bitflow, USDCx.

    line 106

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Clarity Protocols

Never write a protocol call or interface from memory: take each principal from the registry or the protocol's call reference, and each call shape from that reference or the deployed ABI. Position contracts, vault valuation, flash-loan order and fork tests: clarity-ecosystem.

Writing or changing contract code: also load clarity-scholar and clarity-security, and finish with the build checklist.

Addresses and freshness

  • Read the selected protocol's address table before choosing a principal; reuse verified results within the task. Registry age uses registry_verified_at, never the review, release or installation date.
  • Deployed code is immutable; what ages is whether the protocol still selects that contract and its mutable state (roles, pauses, fees, oracle configuration). A newer deployment with a different interface needs an adapter review, not a string replacement.
  • Inspect each accepted asset's transfer authorization, including sender-only tokens and privileged branches; a shared trait does not prove repayment or withdrawal compatibility.
  • Unknown, unavailable or conflicting evidence stays unverified. Never guess an address, change its network prefix, or substitute a mock. Testnet deployments are independent records.
  • To find or refresh a deployment, check the official docs and deployment tables, what the app or API selects, and the contracts a router binds. Official lists can still name retired contracts; note candidates the registry lacks.
  • Code in a protocol's repository does not prove a current, accessible deployment. A registry entry is a discovery seed, not authorization or a safety claim.

When the registry is due

Evidence is due for re-verification when it is 30 days or more old, the timestamp is missing or in the future, the network changes, or a newer deployment is suspected.

  • Tell the user the installed package may be outdated and suggest updating the plugin; releases carry refreshed registries. Never fetch registry files from a repository or overwrite the installed skill.
  • Before relying on an address, run python3 scripts/verify_registry.py --protocol <name> (or --contract <id>) from this skill's directory. It checks each record's live source against the recorded source_sha256 and the deployment receipt, read-only. Add --state to rerun the recorded read-only state checks and list what changed.
  • Confirm current selection from on-chain registries/pointers and the official deployment list; read mutable state.
  • Without the script, make the same checks by hand: GET /v2/contracts/source/{address}/{name} (hash the source text with SHA-256 and compare), the deployment transaction's status from GET /extended/v3/transactions/{txid} (success), and GET /v2/contracts/interface/{address}/{name}.
  • Record what you verified and when, in the project's dependency record if it keeps one, and tell the user. Verification does not reset the registry's date.
  • If live evidence cannot be obtained, explain the unresolved dependency and keep proposed addresses marked unverified. Do not use them for a production transaction.

Before constructing production calls

Before deployment or signing, always verify, even with a fresh registry:

  • Network, active epoch and Clarity version; full principal and exact trait/asset identifiers.
  • Deployed source/hash and ABI matching the intended recipe/revision.
  • For ordinary contracts, successful canonical deployment. For boot contracts, consensus initialization and activation.
  • Current registry selection, authorized roles, pause state, fee scales, oracle configuration (signers/feeds), asset availability and liquidity, read at a recorded tip.
  • Recheck mutable parameters close to execution; freshness is not a guarantee against subsequent changes. Use on-chain limits/deadlines/minimum outputs where available.

Offline age check

python3 scripts/check_registry.py
python3 scripts/check_registry.py --registry references/addresses/zest.md
python3 scripts/check_registry.py --registry ../clarity-system-integration/references/addresses.md
  • Run from this skill's directory. Exit 0: within the window; 1: verification due; 2: malformed/unsupported metadata.
  • This checks age only, offline; verify_registry.py checks the chain.

Rules for every protocol call

  • Who pays: Zest, Granite and Hermetica take the payer from contract-caller and move the asset under that caller's tx-sender context; Stacks Swap and Bitflow pull from tx-sender. A contract spending its own funds therefore makes the call inside its own as-contract? scope with an exact with-ft allowance (with-stx for native STX) for the gross outflow, fees included.
  • Burns and escrows are outflows: Exiting needs an allowance for the share token the protocol burns or escrows: Zest v0-vault-* "zft", Granite state-v1 "lp-token", Hermetica token-hbtc "hBTC". Without it the scope returns (err u128) and the position cannot exit. A mock that books shares in a map hides this.
  • Beneficiary: Read the intended recipient before entering the scope; inside it tx-sender is your contract.
  • Minimums and deadlines: Take them from outside the trade and keep them non-zero. Use a function argument chosen by the transaction signer or, for operator-triggered swaps, a floor computed from a verified oracle price. A value derived inside the call from the pool being traded or from the current block, such as (+ stacks-block-height u10), protects nothing. Where a protocol has no minimum argument (Granite deposit/redeem, Hermetica deposit), measure what you received in the same transaction and compare it with the caller's minimum.
  • Static calls: Call fixed protocol contracts by literal principal (read-only code cannot call through a constant, even through a private helper). A trait-typed parameter in a trait you define, or in a callback you pass to the protocol, must use the protocol's own trait: a local copy there fails BadTraitImplementation against the real contract while passing against your mocks (trait-typed parameters).
  • Real contracts: Test against them at a pinned height at least once (mainnet-fork rules). Mocks that share your own trait copies hide interface and trait-identity errors.

Protocol call references

Before writing, reviewing or testing a call to one of these protocols, read its reference: it holds the exact signatures, fragments, deployed-body checks and test fixtures. Each line lists rules agents often get wrong; it does not replace the reference.

  • Zest v2 (references/zest.md): market v0-8-market and seven v0-vault-* vaults; v0-vault-usdc holds USDCx. Vault deposit and redeem take (amount min-out recipient) and the payer from contract-caller; redeem burns "zft" shares. flashloan pulls amount + fee from its contract-caller (a funds-receiver changes only the destination) and needs a DAO can-flashloan grant. liquidate requires contract-caller == tx-sender, takes the collateral's z-token vault and the underlying debt token, and a price-feeds list must hold exactly one Lazer update.
  • Granite (references/granite.md): lends USDCx; use the exact logic, state-v1 and callback-trait principals in the reference. LP deposit (assets recipient) has no minimum and returns no share count: measure state-v1 get-balance before and after. Exits burn "lp-token" (without the allowance: (err u128)). flash-loan checks that the callback contract is allowed and pulls amount + fee from the caller. Borrowing, removing collateral and liquidating need a fresh Pyth Lazer update; never route them through the legacy Pyth Core adapters. LP exits, borrows and collateral removals draw on market-wide withdrawal caps and fail with (err u120002) to (err u120004) above the current bucket: exit large positions in parts.
  • Hermetica (references/hermetica.md): vault vault-hbtc-v1-2, sBTC only. Deposits are currently disabled ((err u102005)): read check-is-deposit-enabled and decide how a refused hBTC leg is handled. deposit has no minimum argument; check the returned shares. Redemption is queued (request-redeem moves "hBTC" into the vault); anyone may redeem a funded claim, which is then deleted, so never try! across a list of claims.
  • Stacks Swap (references/stacks-swap.md): Zest's aggregator across Bitflow, Velar, ALEX and other venues; choose it or a direct Bitflow call as choosing a swap venue says. zr-d-0 r-d takes 13 arguments in a fixed order and pulls amount-in from tx-sender. deadline is an inclusive Stacks block height taken as an argument (Bitflow's DLMM router takes seconds); skim-amount and max-skim are absolute output units, zero unless a fee is intended. Also covers multi-hop and split routes, Stacking DAO conversion adapters and test obligations.
  • Bitflow (references/bitflow.md): DLMM router dlmm-swap-router-v-1-2 and stable swap core stableswap-core-v-1-4. Orientation and a stable pool's core come from the pool's get-pool (x-token, y-token, core-address), not its name. Payer and recipient are tx-sender; deadline-time is seconds against stacks-block-time. A router trait you define must use Bitflow's own traits (a local copy fails BadTraitImplementation); STX pools use token-stx-v-1-2, not Zest's wSTX. On a mainnet fork set use_mainnet_wallets = true, or pool transfers fail with err u3003.
  • USDCx (references/usdcx.md): token SP120SBRBQJ00MCWS7TM5R8WJNTTKD5K0HFRC2CNE.usdcx, asset usdcx-token (a contract sending it allows (with-ft 'SP120SBRBQJ00MCWS7TM5R8WJNTTKD5K0HFRC2CNE.usdcx "usdcx-token" amount)), six decimals; not native USDC or aeUSDC. transfer accepts sender == tx-sender or sender == contract-caller. The three balance getters return the same balance: do not add them. The .usdcx-v1 bridge burn burns from the current tx-sender, v1 accepts only Ethereum domain u0, and the USDC release happens later, so a flash loan cannot rely on it.

Choosing a swap venue

Neither Stacks Swap nor a direct Bitflow call is the default. Follow a venue or route the task names. Otherwise choose by route, and tell the developer which you chose and why:

  • Call Bitflow directly when one Bitflow pool (DLMM or stable swap) covers the pair with enough liquidity for the trade size. It puts fewer contracts in the trust path and usually costs less to execute. The sBTC/USDCx pair has a Bitflow DLMM pool, dlmm-pool-sbtc-usdcx-v-1-bps-10, which Stacks Swap's DLMM route also goes through.
  • Use Stacks Swap when the best route needs several hops, a split across pools or venues, or a Stacking DAO conversion. A single Velar, ALEX or Arkadiko pool can also be called directly once its deployed router ABI is resolved (protocol discovery).
  • When both fit, compare them at the actual size: net output after fees and skim, liquidity, transaction cost, hop count and the contracts each adds. More routing options do not guarantee a better fill or a lower cost.

Oracles and other protocols

  • Pyth: Core no longer supports Stacks; use Lazer for new integrations (Core/Wormhole is legacy audit/migration material). The documented Lazer model is one governed instance per consumer, not a public shared oracle: Zest v2 (SP1A27...) and Granite (SPMV5HDZ...) each run their own (addresses). Consumer rules, price checks and deploying your own instance: clarity-oracles.
  • DIA: its oracle is the only on-chain source of a USDh/USD price, so any contract that values USDh reads it there: a push oracle with one updater key, eight decimals, millisecond timestamps (addresses).
  • Velar (addresses), ALEX (AMM v2; flash loans are currently disabled on the deployed vault; addresses), Arkadiko and Stacking DAO (staking): start from protocol discovery.
  • Boot/standard principals: system integration; sBTC balances: assets.

Protocol discovery

Read the repository discovery table when selecting an unfamiliar protocol, finding its source or refreshing a deployment record. It maps use cases to repositories, contract paths and checks. Repository HEAD can include mocks, retired or unreleased code: resolve the deployed implementation, roles, asset, fees, pauses and limits before generating an adapter.

  • Current source pins are in the reference baseline.
  • Zest wSTX, Bitflow/Velar/ALEX wrappers and native STX are not interchangeable: a call into another protocol passes the wrapper that protocol requires, and your own contracts use Zest's wSTX where nothing requires another (wSTX).
  • A Stacks Lazer source repository or cross-chain SDK does not establish a production deployment. Verify the consumer's signer, decoder and service access (oracles).

References

  • Address index and its per-protocol tables: open for every principal you use.
  • Call references, one per protocol: Zest v2, Granite, Hermetica, Stacks Swap, Bitflow, USDCx. Open the one you call before writing it (index).

Reference baseline

Examples use Clarity 4+ syntax unless marked, checked on epoch 4.0. Source links in this skill and its references use these pins.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.