> ## Documentation Index
> Fetch the complete documentation index at: https://heyaven09.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Reputation Contract: On-Chain Score Computation

> Reads all attestations for a Stellar address and computes a weighted, category-broken-down reputation score that is fully on-chain and publicly verifiable.

The reputation contract reads all attestations for a Stellar address and computes a weighted score broken down by work category. Scores are computed on-chain and are publicly verifiable by anyone with access to a Stellar RPC endpoint. Because the contract holds no state of its own — it reads directly from the attestation contract on every invocation — your score is always current and automatically reflects every attestation ever minted for your address.

## Contract Address

**Testnet:** `CANK4E7GOFZT4D3U57RNT7QLQTNFGY7QNL6TQTWWKYBNHX7J6U54HO7E`

## Key Functions

<ResponseField name="compute_score" type="function → i128">
  Returns the total aggregated reputation score for a recipient address, capped at `10,000`. This is a convenience wrapper around `get_score_breakdown` that returns only the `total` field.

  **Parameters:**

  * `attestation_contract` — Address of the attestation contract to read from
  * `recipient` — Worker's Stellar address to score
</ResponseField>

<ResponseField name="get_score_breakdown" type="function → ScoreBreakdown">
  Returns the full `ScoreBreakdown` struct with the total score and a per-category breakdown. Use this when you want to display or compare scores across different types of work.

  **Parameters:**

  * `attestation_contract` — Address of the attestation contract to read from
  * `recipient` — Worker's Stellar address to score
</ResponseField>

<ResponseField name="verify_claim" type="function → bool">
  Returns `true` if the recipient's total reputation score is greater than or equal to `minimum_score`. Useful for on-chain access control or eligibility checks.

  **Parameters:**

  * `attestation_contract` — Address of the attestation contract to read from
  * `recipient` — Worker's Stellar address to check
  * `minimum_score` — Minimum score threshold (negative values always return `false`)
</ResponseField>

## ScoreBreakdown Fields

<ResponseField name="total" type="i128">
  Aggregate score across all attestation categories, capped at `10,000`. This is the primary reputation score you would display to end users.
</ResponseField>

<ResponseField name="freelance" type="i128">
  Score contribution from all `Freelance`-category attestations.
</ResponseField>

<ResponseField name="salary" type="i128">
  Score contribution from all `Salary`-category attestations.
</ResponseField>

<ResponseField name="bounty" type="i128">
  Score contribution from all `Bounty`-category attestations.
</ResponseField>

<ResponseField name="grant" type="i128">
  Score contribution from all `Grant`-category attestations.
</ResponseField>

<ResponseField name="agent_task" type="i128">
  Score contribution from all `AgentTask`-category attestations.
</ResponseField>

<ResponseField name="subscription" type="i128">
  Score contribution from all `Subscription`-category attestations.
</ResponseField>

## Scoring Formula

Each attestation contributes a base score of **10 points**, plus a payment bonus of up to **100 points** proportional to the amount paid. That raw score is then multiplied by three independent weighting factors before being added to the breakdown.

**Per-attestation score:**

```
base = 10
payment_bonus = clamp(amount_paid_in_xlm / 10, 0, 100)
raw = base + payment_bonus

points = raw × recency_pct × category_pct × confirmed_pct / 1_000_000
```

### Recency Weighting

Attestations from recent ledgers are worth more than older ones, incentivising sustained activity.

| Window | Approximate Duration          | Score Multiplier |
| ------ | ----------------------------- | ---------------- |
| Hot    | \~7 days (\~120,960 ledgers)  | 150%             |
| Warm   | \~50 days (\~864,000 ledgers) | 120%             |
| Cold   | Older than the warm window    | 100%             |

### Category Weighting

| Category                              | Score Multiplier |
| ------------------------------------- | ---------------- |
| `Grant`                               | 130%             |
| `Bounty`                              | 120%             |
| `Freelance`                           | 110%             |
| `Salary`, `AgentTask`, `Subscription` | 100%             |

### Client Confirmation Weighting

| Confirmation                                             | Score Multiplier |
| -------------------------------------------------------- | ---------------- |
| Client explicitly approved (`client_confirmed = true`)   | 100%             |
| Auto-released after timeout (`client_confirmed = false`) | 50%              |

### Score Cap

The `total` field in `ScoreBreakdown` is capped at **10,000** regardless of how many attestations a worker accumulates. Individual category sub-scores are **not** capped and can exceed 10,000. The reputation contract processes up to the 100 most recent attestation IDs per call.

## How to Query Reputation

### Using the Stellar CLI

```bash theme={null}
stellar contract invoke \
  --id CANK4E7GOFZT4D3U57RNT7QLQTNFGY7QNL6TQTWWKYBNHX7J6U54HO7E \
  --network testnet \
  -- \
  get_score_breakdown \
  --attestation_contract CD22NZLAI53Y2LZB2GNLVITQXZWGZ3AQ6QKVKNUDKWABIIQIDEFSPQCG \
  --recipient <WORKER_STELLAR_ADDRESS>
```

### Using the TypeScript Bindings

```typescript theme={null}
import { Client } from '../contracts/bindings/reputation';

const client = new Client({
  contractId: 'CANK4E7GOFZT4D3U57RNT7QLQTNFGY7QNL6TQTWWKYBNHX7J6U54HO7E',
  networkPassphrase: 'Test SDF Network ; September 2015',
  rpcUrl: 'https://soroban-testnet.stellar.org',
});

const result = await client.get_score_breakdown({
  attestation_contract: 'CD22NZLAI53Y2LZB2GNLVITQXZWGZ3AQ6QKVKNUDKWABIIQIDEFSPQCG',
  recipient: workerAddress,
});

const breakdown = result.result;
console.log('Total score:    ', breakdown.total);
console.log('Freelance:      ', breakdown.freelance);
console.log('Bounty:         ', breakdown.bounty);
console.log('Grant:          ', breakdown.grant);
```

### Checking a Minimum Score Threshold

```typescript theme={null}
const eligible = await client.verify_claim({
  attestation_contract: 'CD22NZLAI53Y2LZB2GNLVITQXZWGZ3AQ6QKVKNUDKWABIIQIDEFSPQCG',
  recipient: workerAddress,
  minimum_score: 500n,
});

if (eligible.result) {
  console.log('Worker meets the minimum reputation requirement.');
}
```

<Tip>
  The reputation contract is stateless — it reads from the attestation contract on every call. There is no separate storage to update or synchronise. Your score automatically reflects all attestations whenever it is queried, and it decays naturally over time as older attestations move from the Hot window to the Warm and Cold windows.
</Tip>
