clarity-staking
Skill2 starsChanged 31 days agoMITView on GitHub
Stack STX through PoX from Clarity: stake and unstake, signers, reward cycles, delegation, with-staking/with-pox allowances, liquid staking (stSTX). Use for contracts or tools that stake STX.
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-protocolsSkill
- clarity-scholarSkill
- clarity-securitySkill
- clarity-sip-complianceSkill
- clarity-startSkill
- clarity-system-integrationSkill
- clarity-testingSkill
- clarity-upgradesSkill
- clarity-walletsSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Keep protocol generation, burnchain clocks, signer rights and historical entitlements explicit.
- Very specific: line 18
Use the word staking for PoX participation, but keep exact names: PoX-4 stack-stx, PoX-5 stake and unstake (names by generation), and the …
- Very specific: line 24
Read the active PoX boot contract from /v2/pox (contract_id.
- Very specific: line 71
Before epoch 4.0, nodes reject a transaction that carries either type (Staking/Pox post-condition is not supported before Stacks 4.0), so …
- Distinctive: line 132
Test cycle and prepare-phase boundaries, joining and leaving near a boundary, lock expiry, caller checks, revoked signer-key grants, direct …
- Distinctive: line 133
Use Clarigen for typed tests, and a devnet or pinned simulation for boot transitions and timing.
≈ “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 Staking
Keep protocol generation, burnchain clocks, signer rights and historical entitlements explicit.
Writing or changing contract code: also load clarity-scholar and clarity-security, and finish with the build checklist.
Key distinctions
- Use the word staking for PoX participation, but keep exact names: PoX-4
stack-stx, PoX-5stakeandunstake(names by generation), and the protocol name Stacking DAO. Allowance names follow the Clarity version, not the PoX generation: a Clarity 4 or 5 contract stakes into PoX-5 withwith-stacking. - The newest PoX source file is not activation evidence. Mainnet uses PoX-5; resolve
/v2/poxfor the target. - STX, stSTX, stSTXbtc, stBTC, sBTC and hBTC represent different assets and rights: distinguish them by principal, native asset identifier, decimals and economic rights; names are not identities.
PoX generations
- Read the active PoX boot contract from
/v2/pox(contract_id; mainnet: PoX-5), then its delegation, signer authorization, reward-cycle and unlock rules. Resolve boot identities with system addresses. - Mainnet: active
SP000000000000000000002Q6VF78.pox-5. Epoch 4.0 deployed it at burn height 960,230, inside cycle 140, and cycle 141 is the first whose signer and reward set it controls. Cycles span 2,100 burn blocks with a 100-block prepare phase. Cycles and unlocks followburn-block-height, not Stacks blocks or wall time. - PoX-5's
SIGNER_SET_MIN_USTXis 50,000 STX delegated to a signer for signer-set eligibility. It is not a universal minimum for each participant.
| Generation | Integration model |
| Legacy PoX-4 | stack-stx/delegation APIs, signer authorization IDs and Bitcoin reward addresses; miner rewards paid on Bitcoin |
| PoX-5 | stake/stake-update/unstake, registered signer managers/key grants, sBTC reward accounting and claims; Bitcoin withdrawal is a separate step |
| Concept | PoX-4 (legacy) | PoX-5 |
| Lock / delegate STX | stack-stx, delegate-stx (+ delegate-stack-stx, stack-increase) | stake, stake-update |
| Exit | lock expires at the cycle boundary | lock also expires at the cycle boundary; unstake (STX) moves the unlock to the next boundary, and unstake-sbtc withdraws bonded sBTC |
- An STX-only
unstakeschedules unlocking at a cycle boundary, rather than immediately transferring STX. - PoX-5 also supports bonded STX with L1 BTC or custodied sBTC; use its specific bond/rollover/exit rules.
- PoX-5 has no PoX-4 authorization IDs, delegation expiry or Bitcoin reward addresses, and
pox-4call shapes do not map onto it. From epoch 4.0 everypox-4call that is not read-only, includingdelegate-stxandstack-stx, aborts with aDefunctPoxContractruntime error (locking dispatch). PoX-5 has nodelegate-stx: a staker joins a pool withstake, naming the pool's signer manager. - Sources: PoX-5 source, SIP-045. Verify actual deployed source and activation before use.
Allowances and postconditions
| Clarity version | Allowance for locking STX | Allowance for position changes |
| 4, 5 | with-stacking amount | none: an unstake-type call by the scope's owner makes as-contract? or restrict-assets? return (err u128), unless as-contract? uses with-all-assets-unsafe |
| 6+ | with-staking amount (same allowance, renamed) | with-pox (no amount) covers unstake, unstake-sbtc, update-bond-registration, announce-l1-early-exit |
- Allowance amounts are totals the active PoX contract may lock, not increases: a stake update or
stack-increaseneeds an allowance for the new total. A scope adds up the totals its calls record: astakeof 100 STX then an update to 110 STX in one scope needs an allowance of 210 STX. with-poxdoes not cover locking (that iswith-staking). A call to awith-poxfunction counts even when it returns(err ...), so omit the allowance to forbid touching the position inside a scope.with-stxand STX post-conditions see transfers and burns, never locks. Cover a lock or position change with the allowances above and the transaction post-conditions below (versions).- For reward-bearing token transfers, inspect whether hooks pay both endpoints or save entitlement for later claims. Apply aggregate postcondition and reward-checkpoint checks; do not assume one transfer means one asset movement.
Transaction post-conditions
Epoch 4.0 adds two transaction post-condition types for PoX-5 (SIP-045 section 3.4.3; the SDK and Ledger app label them SIP-044).
| Type | Builder (@stacks/transactions 7.6.0) | Covers |
Staking 0x03 | Pc.principal(p).willSendEq(total).ustxToLock() or another willSend* comparator | the micro-STX lock that stake, stake-update or register-for-bond records for p |
PoX 0x04 | Pc.principal(p).willPerformPox(), .willNotPerformPox() or .mayPerformPox() | p calling unstake, unstake-sbtc, update-bond-registration or announce-l1-early-exit |
Denyaborts the transaction when a principal stakes or makes one of those calls without a condition of that type on it.Originatordoes so for the origin only, andAllowpermits it. Listed conditions must pass in every mode.- Abort reasons:
Post-condition check failure: <n> STX was staked by <principal> but not checked(<n>in micro-STX) and... <principal> performed a PoX action but it was not checked. A failed condition reads... on STX staked by <principal>: <amount> SentLe <staked>(comparators print asSent*, as for transfers) or... on PoX action by <principal>: NotPerformed performed=true. - The staking amount is the total lock each call records, summed per principal over the transaction, not the increase. A
stake-updateadding 10 STX to 100 STX records 110 STX, an extension alone records the whole lock, and astakeof 100 STX then that update in one transaction records 210 STX. UsewillSendEqfor a known total andwillSendLtefor a cap. - STX conditions count transfers and burns, never locks. On a stake,
willSendEq(amount).ustx()fails (sent 0) andwillSendLte(amount).ustx()leaves the stake unchecked. A PoX condition does not cover a stake, and a staking condition does not cover an unstake. - The staking total and the PoX action both belong to the
tx-senderof the call into pox-5. A PoX attempt counts even when pox-5 returns(err ...), sowillPerformPox()proves an attempt, not success: check the call result.willNotPerformPox()aborts even a failed attempt. If a calling contract then returns an err, the attempt rolls back with it. - PoX-5 has no contract-caller allow list; SIP-045 relies on these conditions instead. Any contract the user calls can stake, update or unstake for the user, since the user stays
tx-sender. InDenymode, list only the intended action so that anything else aborts. InAllowmode,willSendEq(0).ustxToLock()andwillNotPerformPox()on the user forbid any stake or PoX action by the user. - Cover the other movements as usual. The staker sends sBTC into bond custody, and pox-5 itself sends sBTC refunds and
unstake-sbtcpayouts, soDenymode also needs an FT condition on the pox-5 contract (sBTC identity). The signer manager'svalidate-stake!runs with the staker astx-sender, so cover anything it moves. A contract acting on its own position needs the allowance above and, inDenymode, a condition on the contract principal. - Before epoch 4.0, nodes reject a transaction that carries either type (
Staking/Pox post-condition is not supported before Stacks 4.0), so readcurrent_epochfrom the target's/v2/pox.@stacks/transactions7.5.0 added the builders, andpostConditionToHexandPc.fromHexround-trip them. Connect 8.2.7 serializes them; 8.2.6 throws on these objects. Test the installed wallet and device (Ledger notes). - Clarinet SDK 3.26.0 simnet enforces both types at epoch 4.0 with the same reasons and rejects them at earlier epochs. Pass the mode and conditions explicitly (simulator traps).
// fragment: PoX-5 stake-update in Deny mode (imports from @stacks/connect, @stacks/transactions)
// poxId: contract_id from /v2/pox; staked: get-staker-info amount-ustx, in micro-STX
const newTotal = staked + increase; // the node records the new total lock, not the increase
const { txid } = await request('stx_callContract', {
contract: poxId, functionName: 'stake-update', // new and old manager, extra cycles, increase, calldata
functionArgs: [Cl.principal(manager), Cl.principal(manager), Cl.uint(0), Cl.uint(increase), Cl.none()],
network, address: staker, postConditionMode: 'deny',
postConditions: [Pc.principal(staker).willSendEq(newTotal).ustxToLock()],
});- An intended
unstakeinDenymode takesPc.principal(staker).willPerformPox(), ormayPerformPox()when the call may not run; neverwillNotPerformPox(). staketakes the signer manager,amount-ustx,num-cycles,start-burn-htand optional calldata. Pass a burn height in the current cycle, such as/v2/infoburn_block_height; a height in another cycle fails with(err u24). InDenymode it takesPc.principal(staker).willSendEq(amount).ustxToLock().- In the prepare phase,
stake,stake-update,register-for-bond,update-bond-registration,announce-l1-early-exitandunstake-sbtcfail with(err u47), andunstakewith(err u28). The transaction is still mined and pays its fee, so before the wallet signs, check that pox-5's read-onlyis-in-prepare-phaseis false forcurrent-pox-reward-cycle(stake, unstake, prepare phase). - Sources: SIP-045, epoch check, condition evaluator, lock and action records, per-principal sums, allowance check, SDK builders, Connect serializer.
PoX-5 signer managers
- A signer manager implements PoX-5's
signer-manager-trait, whose only function is thevalidate-stake!callback. It must assert there thatcontract-calleris the active PoX contract; otherwise anyone can call it directly and redirect another staker's reward destination. - Trace signer-key grants, manager registration, reward claims, fee snapshots and old-manager entitlements after switching signers.
- Account separately for pending withdrawals, rejected refunds, accepted fee refunds and unclaimed rewards. Fee sweeps must preserve staker liabilities.
- Reference implementations: STX Labs signer-managers collects implementations of PoX-5's
signer-manager-trait. Its basic manager supports sBTC reward claims, optional Bitcoin withdrawals and admin-set fees. Treat it as reference code; verify deployment and configuration separately. - Reuse its Clarigen tests and PoX helpers as test designs. Its extraction script supplies SDK boot source to Clarigen; tests call simnet's boot instance. Check SDK/epoch support and target-network bindings before adapting the harness.
Liquid staking: Stacking DAO
- Stacking DAO's STX core is
SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.stacking-dao-core-stx-v2; stSTX is...ststx-token, the withdrawal NFT...ststx-withdraw-nft-v4. Addresses: Stacking DAO registry.
;; fragment: interface excerpt; resolve the exact deployment before calling
;; Deposit STX, receive stSTX at the current ratio (ok ststx-amount)
(contract-call? 'SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.stacking-dao-core-stx-v2 deposit stx-amount min-shares-out)
;; Queue a withdrawal: stSTX moves to the core, a withdrawal NFT is minted (ok nft-id)
(contract-call? 'SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.stacking-dao-core-stx-v2 init-withdraw ststx-amount)
;; After the unlock burn height: burn the NFT and receive STX (ok {stx-user, stx-fee})
(contract-call? 'SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.stacking-dao-core-stx-v2 withdraw nft-id)
;; Instant exit from idle liquidity only, with a fee (ok {stx-user, stx-fee})
(contract-call? 'SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.stacking-dao-core-stx-v2 withdraw-idle ststx-amount)- The ratio is
data-stx-v2get-stx-per-ststx(STX per stSTX, 6 decimals); to price stSTX, see liquid staking ratios. - These functions act on
tx-sender, notcontract-caller: STX is taken fromtx-sender, stSTX is minted totx-sender, and the NFT owner must equaltx-sender. A contract that holds the STX, stSTX or withdrawal NFT must make the call in its ownas-contract?scope.depositneedswith-stx, andinit-withdrawandwithdraw-idleneedwith-ftonststx-token(token nameststx).withdrawburns the NFT, so it needswith-nftonststx-withdraw-nft-v4(token namewithdraw-nft) listing the NFT id. withdrawrequiresburn-block-height >= unlock-burn-heightof the NFT, whichinit-withdrawsets to the burn height plus a governed cooldown, at least 2,100 blocks on mainnet (cooldown);withdraw-idlefails with an insufficient-idle error when the reserve lacks liquid STX, and chargeswithdraw-idle-feeunless fee-exempt. Queued withdrawals cannot finance atomic repayment.- The stSTXbtc and stBTC cores have separate contracts and ABIs (
stacking-dao-core-ststxbtc-v2,stacking-dao-core-stbtc-v1); read each before use. - Each liquid staking protocol adds its own custody, share accounting and withdrawal schedule, and these change between versions. Before generating calls, read its current core, staker and strategy contracts and their mutable configuration.
Historical reward entitlements
- Settle historical rewards against historical entitlement before changing balance, delegation, signer manager or exclusions.
- Handle queued withdrawals and pending rewards in share price; do not apply current weights to prior-cycle rewards.
- Reconcile available funds, locked principal, withdrawal reserves, pending rewards and queued liabilities.
Integrate and test
- Resolve the active PoX contract and read its source. Record the cycle and prepare-phase lengths, the burn height, signer-key grants, reward destinations and who may call each function.
- Separate native STX transfers from locks, and use the allowance and post-condition type each operation needs.
- In your own wrapper, check callers per operation rather than with one global list.
- Test cycle and prepare-phase boundaries, joining and leaving near a boundary, lock expiry, caller checks, revoked signer-key grants, direct calls to manager callbacks, reward-claim and withdrawal destinations, late funding, signer changes and strategy migration.
- Use Clarigen for typed tests, and a devnet or pinned simulation for boot transitions and timing. Record the synthetic time and state each test assumes.
References
- Versions: allowance evolution and epoch behavior.
- Model corrections: context and PoX gaps.
- Load
clarity-system-integrationfor boot identities andclarity-apisfor node reads.
Reference baseline
Examples use Clarity 4+ syntax unless marked, checked on epoch 4.0. Source links in this skill use these pins.
stacks-core: ccf31dc69c.stackingdao: 125c73dc10.signer-managers: c9e0235421.stacks-core-release: 10474cdec9.sips: 642af6804d.stacks-js-wallets: e6084a5214.stacks-connect: 096c3fa5a1.
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.

