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.
In this repository24 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llms.txtllms.txt
- clarity-apisSkill
- clarity-assetsSkill
- clarity-auditorSkill
- clarity-bitcoin-proofsSkill
- clarity-deploymentSkill
- clarity-ecosystemSkill
- clarity-environmentsSkill
- clarity-epochsSkill
- clarity-fuzzingSkill
- clarity-governanceSkill
- clarity-optimizerSkill
- clarity-oraclesSkill
- clarity-scholarSkill
- clarity-securitySkill
- clarity-sip-complianceSkill
- clarity-stakingSkill
- clarity-startSkill
- clarity-system-integrationSkill
- clarity-testingSkill
- clarity-upgradesSkill
- clarity-walletsSkill
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
- Distinctive: line 15
Never write a protocol call or interface from memory: take each principal from the registry or the protocol's call reference, and each call …
- Very specific: line 21
Read the selected protocol's address table before choosing a principal.
- Very specific: line 33
Before relying on an address, run python3 scripts/verify_registry.py --protocol <name> (or --contract <id>) from this skill's directory.
- Distinctive: line 37
If live evidence cannot be obtained, explain the unresolved dependency and keep proposed addresses marked unverified.
- Distinctive: line 41
Before deployment or signing, always verify, even with a fresh registry:
- Very specific: line 57
Run from this skill's directory.
- Very specific: line 64
Beneficiary: Read the intended recipient before entering the scope.
- Distinctive: line 67
Real contracts: Test against them at a pinned height at least once (mainnet-fork rules).
- Distinctive: line 71
Before writing, reviewing or testing a call to one of these protocols, read its reference: it holds the exact signatures, fragments, …
- Distinctive: line 85
Use Stacks Swap when the best route needs several hops, a split across pools or venues, or a Stacking DAO conversion.
- Distinctive: line 86
When both fit, compare them at the actual size: net output after fees and skim, liquidity, transaction cost, hop count and the contracts …
- Distinctive: line 106
Call references, one per protocol: Zest v2, Granite, Hermetica, Stacks Swap, Bitflow, USDCx.
≈ “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.
Files
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 recordedsource_sha256and the deployment receipt, read-only. Add--stateto 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 thesourcetext with SHA-256 and compare), the deployment transaction'sstatusfromGET /extended/v3/transactions/{txid}(success), andGET /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.pychecks the chain.
Rules for every protocol call
- Who pays: Zest, Granite and Hermetica take the payer from
contract-callerand move the asset under that caller'stx-sendercontext; Stacks Swap and Bitflow pull fromtx-sender. A contract spending its own funds therefore makes the call inside its ownas-contract?scope with an exactwith-ftallowance (with-stxfor 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", Granitestate-v1"lp-token", Hermeticatoken-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-senderis 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
BadTraitImplementationagainst 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-marketand sevenv0-vault-*vaults;v0-vault-usdcholds USDCx. Vaultdepositandredeemtake(amount min-out recipient)and the payer fromcontract-caller;redeemburns"zft"shares.flashloanpullsamount + feefrom itscontract-caller(afunds-receiverchanges only the destination) and needs a DAOcan-flashloangrant.liquidaterequirescontract-caller == tx-sender, takes the collateral's z-token vault and the underlying debt token, and aprice-feedslist must hold exactly one Lazer update. - Granite (references/granite.md): lends USDCx; use the exact logic,
state-v1and callback-trait principals in the reference. LPdeposit (assets recipient)has no minimum and returns no share count: measurestate-v1get-balancebefore and after. Exits burn"lp-token"(without the allowance:(err u128)).flash-loanchecks that the callback contract is allowed and pullsamount + feefrom the caller. Borrowing, removing collateral and liquidating need a fresh Pyth Lazerupdate; 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)): readcheck-is-deposit-enabledand decide how a refused hBTC leg is handled.deposithas no minimum argument; check the returned shares. Redemption is queued (request-redeemmoves"hBTC"into the vault); anyone may redeem a funded claim, which is then deleted, so nevertry!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-0r-dtakes 13 arguments in a fixed order and pullsamount-infromtx-sender.deadlineis an inclusive Stacks block height taken as an argument (Bitflow's DLMM router takes seconds);skim-amountandmax-skimare 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-2and stable swap corestableswap-core-v-1-4. Orientation and a stable pool's core come from the pool'sget-pool(x-token,y-token,core-address), not its name. Payer and recipient aretx-sender;deadline-timeis seconds againststacks-block-time. A router trait you define must use Bitflow's own traits (a local copy failsBadTraitImplementation); STX pools usetoken-stx-v-1-2, not Zest's wSTX. On a mainnet fork setuse_mainnet_wallets = true, or pool transfers fail witherr u3003. - USDCx (references/usdcx.md): token
SP120SBRBQJ00MCWS7TM5R8WJNTTKD5K0HFRC2CNE.usdcx, assetusdcx-token(a contract sending it allows(with-ft 'SP120SBRBQJ00MCWS7TM5R8WJNTTKD5K0HFRC2CNE.usdcx "usdcx-token" amount)), six decimals; not native USDC or aeUSDC.transferacceptssender == tx-senderorsender == contract-caller. The three balance getters return the same balance: do not add them. The.usdcx-v1bridgeburnburns from the currenttx-sender, v1 accepts only Ethereum domainu0, 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.
stacks-core: ccf31dc69c.zest-v2: f2fce52672.granite: 2d44a2df94.hermetica: 5e13e431f6.sbtc: eb507946c6.stackingdao: 125c73dc10.bitflow: 31c4e0be27.bitflow-dlmm: b4d3694c86.arkadiko: 854fda1d6d.pyth-lazer: a6034d2e39.alex-sdk: 4c7e1bd016.alexlab-doc: 7f4b05b461.
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
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.

