Documentation

Devnet integration guides and Phase 1 payment and epoch-settlement specification.

Quickstart

The devnet contract path is Solana-native. SDK examples on this page are wrapper targets: the wrapper must build payment indexes, payment nonce hashes, payer token delegates, epoch PDAs, Merkle settlement artifacts, and masterpool v3 accounts before sending transactions.

This page separates current devnet v3 behavior from mainnet targets. Devnet v3 is live with 300-second epochs, a 60-second challenge window, a 3 percent payment-tax cap, zero upfront provider-stake transfer, and proof-based claims. The mainnet target keeps a 1-hour epoch, treasury split and buyback policy, bounded governance, and protocol-owned liquidity as whitepaper-level launch commitments.

Install

npm install @clawfarm/sdk

Configure devnet

import { ClawFarm } from '@clawfarm/sdk'

const cf = new ClawFarm({
  cluster: 'devnet',
})

SDK wrapper target

A contract-aligned wrapper records wallet-paid usage through masterpool v3, then settles ended epochs through aggregate roots and Merkle claims.

TypeScript

const payment = await cf.payments.record({
  providerWallet,
  payer: connectedWallet.publicKey,
  payerUsdcToken,
  paymentDelegate,
  paymentIndex: 42n,
  paymentNonceHash,
  baseChargeUsdc: '0.025000',
  taxRateBps: 300,
  taxSweepThresholdAmount: 0n,
})

const settlement = await cf.epochs.commitSettlement({
  epochId: payment.epochId,
  usageRoot,
  providerRoot,
  buyerRoot,
  artifactHash,
  artifactUriHash,
  totals: payment.epochTotals,
  providerPoolClaf,
  buyerPoolClaf,
})

await cf.epochs.finalizeSettlement({ epochId: settlement.epochId })

await cf.epochs.claimProviderEpoch({
  epochId: settlement.epochId,
  leafIndex,
  totalProviderUsdc,
  providerWeight,
  providerClafReward,
  proof,
})

await cf.epochs.claimBuyerReward({
  epochId: settlement.epochId,
  leafIndex,
  buyerWeight,
  buyerClafReward,
  proof,
})

Python

payment = cf.payments.record(
    provider_wallet=provider_wallet,
    payer=connected_wallet.public_key,
    payer_usdc_token=payer_usdc_token,
    payment_delegate=payment_delegate,
    payment_index=42,
    payment_nonce_hash=payment_nonce_hash,
    base_charge_usdc="0.025000",
    tax_rate_bps=300,
    tax_sweep_threshold_amount=0,
)

settlement = cf.epochs.commit_settlement(
    epoch_id=payment.epoch_id,
    usage_root=usage_root,
    provider_root=provider_root,
    buyer_root=buyer_root,
    artifact_hash=artifact_hash,
    artifact_uri_hash=artifact_uri_hash,
    totals=payment.epoch_totals,
    provider_pool_claf=provider_pool_claf,
    buyer_pool_claf=buyer_pool_claf,
)

cf.epochs.finalize_settlement(epoch_id=settlement.epoch_id)

cf.epochs.claim_provider_epoch(
    epoch_id=settlement.epoch_id,
    leaf_index=leaf_index,
    total_provider_usdc=total_provider_usdc,
    provider_weight=provider_weight,
    provider_claf_reward=provider_claf_reward,
    proof=proof,
)

cf.epochs.claim_buyer_reward(
    epoch_id=settlement.epoch_id,
    leaf_index=leaf_index,
    buyer_weight=buyer_weight,
    buyer_claf_reward=buyer_claf_reward,
    proof=proof,
)

Rust

let payment = cf.payments().record()
    .provider_wallet(provider_wallet)
    .payer(connected_wallet.pubkey())
    .payer_usdc_token(payer_usdc_token)
    .payment_delegate(payment_delegate)
    .payment_index(42)
    .payment_nonce_hash(payment_nonce_hash)
    .base_charge_usdc("0.025000")
    .tax_rate_bps(300)
    .tax_sweep_threshold_amount(0)
    .send()
    .await?;

let settlement = cf.epochs().commit_settlement()
    .epoch_id(payment.epoch_id)
    .usage_root(usage_root)
    .provider_root(provider_root)
    .buyer_root(buyer_root)
    .artifact_hash(artifact_hash)
    .artifact_uri_hash(artifact_uri_hash)
    .totals(payment.epoch_totals)
    .provider_pool_claf(provider_pool_claf)
    .buyer_pool_claf(buyer_pool_claf)
    .send()
    .await?;

cf.epochs().finalize_settlement(settlement.epoch_id).send().await?;

cf.epochs().claim_provider_epoch()
    .epoch_id(settlement.epoch_id)
    .leaf_index(leaf_index)
    .total_provider_usdc(total_provider_usdc)
    .provider_weight(provider_weight)
    .provider_claf_reward(provider_claf_reward)
    .proof(proof.clone())
    .send()
    .await?;

cf.epochs().claim_buyer_reward()
    .epoch_id(settlement.epoch_id)
    .leaf_index(leaf_index)
    .buyer_weight(buyer_weight)
    .buyer_claf_reward(buyer_claf_reward)
    .proof(proof)
    .send()
    .await?;

Current devnet contract shape

The SDK wrapper target maps to `clawfarm_masterpool_v3`. The current masterpool records payments directly, accumulates epoch totals, commits settlement roots, and verifies Merkle proofs for claims. Model IDs, endpoint metadata, and price metadata remain off-chain inputs to wrapper artifacts.

RecordPaymentV3Args
payment_index, payment_nonce_hash, base_charge_atomic, tax_rate_bps, and tax_sweep_threshold_amount.
Payment recording
The payer token delegate authorizes gross payment. Tax transfers to treasury, base charge transfers to provider pending, and the epoch accumulator records base, tax, gross, and payment count.
Payment bitmap
EpochPaymentBitmap marks payment indexes so the same payment index cannot be reused inside an epoch chunk.
Epoch settlement
After an epoch ends, the wrapper commits usage, provider, and buyer Merkle roots plus aggregate totals into an EpochSettlementBatch.
Claims
Finalized EpochSettlementRoot accounts release provider USDC and CLAF rewards through provider and buyer Merkle proofs.
Current versus target epoch
Current devnet v3 uses 300-second epochs for accelerated testing; the mainnet target is a 1-hour epoch.
Reserved payment field
record_payment_v3 accepts a payment nonce hash and tax_sweep_threshold_amount; current v3 deduplicates payment_index through the epoch bitmap and stores aggregate totals in the accumulator. Wrappers and indexers preserve per-payment identity and nonce metadata off-chain.
Payment tax range
Payment tax rate must be at least 50 bps and at or below GlobalConfigV3.tax_rate_bps.
CLAF pool calculation
commit_epoch_settlement_v3 stores provider_pool_claf and buyer_pool_claf supplied by the settlement artifact; current v3 does not compute emission on-chain.
Target treasury layer
Mainnet target treasury policy belongs to the whitepaper target layer, not the current devnet v3 masterpool settlement instruction set.

Gateway wrapper target

A gateway API may collect usage metadata, but it must create or return Solana transactions that follow the current masterpool v3 shape. It is not a contract-native REST endpoint.

POST /devnet/payment-transactions
{
  "providerWallet": "<provider-wallet>",
  "payer": "<payer-wallet>",
  "payerUsdcToken": "<payer-usdc-token>",
  "paymentIndex": "42",
  "paymentNonceHash": "<client-generated-nonce-hash>",
  "metadata": {
    "model": "model-l-001",
    "unit": "tokens"
  },
  "baseChargeUsdc": "0.025000",
  "taxRateBps": 300,
  "taxSweepThresholdAmount": "0"
}

The gateway wrapper response should contain a transaction or signing payload for `record_payment_v3`. Epoch settlement wrappers later commit aggregate roots and claim proofs.

Gateway selection

Applications or gateways choose the provider before payment recording. Masterpool v3 records payment identities, base charge, tax, epoch accumulator state, and payment bitmap state; finalized epoch roots later carry usage, provider, and buyer allocation data.

Directory
Endpoint, model, price, and limits are off-chain operator metadata.
Selection
Any app may choose a provider wallet before recording a masterpool v3 payment.
Settlement
Ended epochs settle through aggregate totals, usage roots, provider roots, buyer roots, and Merkle proof claims.

Provider

Providers register one wallet-controlled ProviderAccountV3. Current registration initializes staking state without requiring an upfront collateral transfer.

Register
Masterpool registration records the provider wallet, initializes staked_usdc_amount to zero, and sets active status. Endpoint, model, and pricing metadata live in the off-chain gateway or operator directory layer.
Stake
GlobalConfigV3 retains provider_stake_usdc, but current register_provider_v3 initializes staked_usdc_amount to zero and does not enforce or transfer upfront collateral.
Pricing
Input, output, request, image, second, or task units.
Payment artifacts
Wrappers derive payment nonce hashes, epoch PDAs, accumulator accounts, bitmap chunks, and settlement artifacts before sending masterpool v3 transactions.

The masterpool account does not store endpoint infrastructure; applications and gateways bind endpoint metadata outside the on-chain provider account.

Models

Model identifiers remain off-chain metadata used by applications and gateway directories. Masterpool v3 records payment and settlement artifacts, not model IDs.

model-l-001
Language model label supplied to wrapper artifacts outside ProviderAccountV3.
model-i-001
Image model label supplied to wrapper artifacts outside ProviderAccountV3.
model-v-001
Video model label supplied to wrapper artifacts outside ProviderAccountV3.

Protocol

ClawFarm Phase 1 is a payment-driven epoch settlement protocol for AI inference on Solana.

Architecture

WALLET / APP LAYER
  Users · Builders · Agents · Provider operators

OFF-CHAIN DIRECTORY
  Provider choices · Model labels · Endpoint metadata · Price metadata

MASTERPOOL V3 PAYMENT LAYER
  ProviderAccountV3 · EpochPaymentAccumulator · EpochPaymentBitmap · Treasury and provider pending vaults

EPOCH SETTLEMENT LAYER
  EpochSettlementBatch · EpochSettlementChallenge · EpochSettlementRoot · EpochClaimBitmap · Merkle proof claims

Smart contracts

clawfarm-masterpool-v3
Records payments, accumulates epoch totals, commits settlement roots, handles epoch settlement challenges, and verifies provider or buyer claim proofs.
ProviderAccountV3
Stores provider wallet, pending provider USDC, status, and timestamps.
EpochPaymentAccumulator
Stores epoch payment count plus total base, tax, and gross USDC recorded through masterpool v3.
EpochSettlementRoot
Stores finalized usage, provider, and buyer roots, aggregate totals, CLAF pools, claimed totals, and finalization timestamp.

Payment lifecycle

1. Wallet authorizes bounded Test USDC settlement through a payer token delegate.
2. App or gateway prepares payment_index, payment_nonce_hash, base_charge_atomic, and tax_rate_bps.
3. Masterpool v3 records payment, transfers tax to treasury, transfers base charge to provider pending, and marks the epoch payment bitmap.
4. Epoch payment accumulator stores payment count plus total base, tax, and gross USDC.
5. After the epoch ends, an authorized submitter commits usage, provider, and buyer Merkle roots into an EpochSettlementBatch.
6. Settlement challenges may invalidate a pending batch until accepted or rejected by authority.
7. After the challenge deadline, finalization writes an EpochSettlementRoot.
8. Providers and buyers claim USDC or CLAF with Merkle proofs against the finalized root.

Phase 1 economics

Payment tax
Masterpool v3 computes tax from the configured tax_rate_bps. The current payment tax rate must be at least 50 bps and at or below the configured cap; gross payment equals base charge plus tax.
Provider pending
Base charge moves to the provider pending vault during payment recording and is released through provider Merkle claims after epoch settlement finalizes.
Epoch roots
Ended epochs settle through usage, provider, and buyer roots plus aggregate base, tax, and gross totals.
Pool split
Finalized settlement roots carry provider and buyer CLAF pools for Merkle proof claims.
Emission artifact
Current v3 stores settlement-root CLAF pool caps supplied by the wrapper or indexer artifact; epoch length changes cadence and per-epoch pool size, not the total scheduled CLAF emission.
Claim protection
EpochClaimBitmap accounts prevent repeated provider or buyer claims for the same epoch leaf.

Challenges

Challenge scope
Challenges apply to pending EpochSettlementBatch accounts before finalization.
Open challenge
Opening a challenge invalidates the pending batch and stores evidence hashes in an EpochSettlementChallenge account.
Rejected challenge
The authority rejects the challenge and restores the batch to pending so it can finalize after the challenge deadline.
Accepted challenge
The authority accepts the challenge and closes the invalidated batch and challenge accounts.

Devnet parameters

Cluster
Solana devnet
Masterpool implementation
clawfarm_masterpool_v3
Program source
Latest implementation facts derive from the sibling clawfarm-masterpool repository.
Provider collateral
ProviderAccountV3 includes staked_usdc_amount, but current registration initializes it to zero and does not transfer upfront collateral.
Payment tax
Config-capped in GlobalConfigV3; record_payment_v3 accepts payment rates from 50 bps through the configured cap.
Current epoch duration
300 seconds on devnet v3 for accelerated testing; 1 hour is the mainnet target.
Current challenge window
60 seconds on devnet v3.
Epoch settlement
Uses accumulator totals, payment bitmaps, settlement batches, challenges, finalized roots, and claim bitmaps.
Treasury target
Buyback, burn, and protocol-owned-liquidity policy are whitepaper target commitments, not current devnet masterpool instructions.

Reproducibility

Contract builds should be verified against the current clawfarm-masterpool repository. The command below exposes the v3 bootstrap wrapper surface for testnet/devnet setup flows.

V3 wrapper command surface

yarn phase1:v3:bootstrap:testnet --help

Contract build

git clone <contract-source-url>
cd clawfarm-masterpool
anchor build
anchor test

Resources

Reference files and mirrors for developers, providers, and auditors.

Contract source
Protocol facts derive from the current clawfarm-masterpool repository.
Phase 1 economics
Payment recording, epoch settlement roots, challenges, and Merkle claim accounting.
Website source
Repository URL publishes after protocol organization migration.